Skip to content

Commit bb80df3

Browse files
committed
feat: display reading status in footer
1 parent 654ed54 commit bb80df3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/stores/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { ReadTimeResults } from 'reading-time'
12
import DEFAULT_CONTENT from '@/assets/example/markdown.md?raw'
23
import DEFAULT_CSS_CONTENT from '@/assets/example/theme-css.txt?raw'
34
import { altKey, codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, legendOptions, shiftKey, themeMap, themeOptions } from '@/config'
45
import { addPrefix, css2json, customCssWithTemplate, customizeTheme, downloadMD, exportHTML, formatDoc } from '@/utils'
5-
import { initRenderer } from '@/utils/renderer'
66

7+
import { initRenderer } from '@/utils/renderer'
78
import CodeMirror from 'codemirror'
89
import { marked } from 'marked'
910

@@ -178,16 +179,22 @@ export const useStore = defineStore(`store`, () => {
178179
isUseIndent: isUseIndent.value,
179180
})
180181

182+
const readingTime = ref<ReadTimeResults | null>(null)
183+
181184
// 更新编辑器
182185
const editorRefresh = () => {
183186
codeThemeChange()
184187
renderer.reset({ citeStatus: isCiteStatus.value, legend: legend.value, isUseIndent: isUseIndent.value, countStatus: isCountStatus.value })
185188

186-
const { markdownContent, readingTime } = renderer.parseFrontMatterAndContent(editor.value!.getValue())
189+
const { markdownContent, readingTime: readingTimeResult } = renderer.parseFrontMatterAndContent(editor.value!.getValue())
190+
console.log(`Reading time result:`, readingTimeResult)
191+
readingTime.value = readingTimeResult
187192
let outputTemp = marked.parse(markdownContent) as string
188193

194+
console.log(readingTime.value)
195+
189196
// 阅读时间及字数统计
190-
outputTemp = renderer.buildReadingTime(readingTime) + outputTemp
197+
outputTemp = renderer.buildReadingTime(readingTimeResult) + outputTemp
191198

192199
// 去除第一行的 margin-top
193200
outputTemp = outputTemp.replace(/(style=".*?)"/, `$1;margin-top: 0"`)
@@ -451,6 +458,7 @@ export const useStore = defineStore(`store`, () => {
451458
primaryColor,
452459
codeBlockTheme,
453460
legend,
461+
readingTime,
454462

455463
editorRefresh,
456464

src/views/CodemirrorEditor.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CodeMirror from 'codemirror'
1212
1313
const store = useStore()
1414
const displayStore = useDisplayStore()
15-
const { isDark, output, editor } = storeToRefs(store)
15+
const { isDark, output, editor, readingTime } = storeToRefs(store)
1616
const { isShowCssEditor } = storeToRefs(displayStore)
1717
1818
const {
@@ -434,6 +434,9 @@ onMounted(() => {
434434
</div>
435435
<CssEditor class="flex-1" />
436436
</div>
437+
<footer class="flex flex-1 justify-end pr-5 text-[14px]">
438+
约 {{ readingTime?.words }} 字, {{ readingTime?.text }}
439+
</footer>
437440
</main>
438441

439442
<UploadImgDialog

0 commit comments

Comments
 (0)