|
| 1 | +import type { ReadTimeResults } from 'reading-time' |
1 | 2 | import DEFAULT_CONTENT from '@/assets/example/markdown.md?raw'
|
2 | 3 | import DEFAULT_CSS_CONTENT from '@/assets/example/theme-css.txt?raw'
|
3 | 4 | import { altKey, codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, legendOptions, shiftKey, themeMap, themeOptions } from '@/config'
|
4 | 5 | import { addPrefix, css2json, customCssWithTemplate, customizeTheme, downloadMD, exportHTML, formatDoc } from '@/utils'
|
5 |
| -import { initRenderer } from '@/utils/renderer' |
6 | 6 |
|
| 7 | +import { initRenderer } from '@/utils/renderer' |
7 | 8 | import CodeMirror from 'codemirror'
|
8 | 9 | import { marked } from 'marked'
|
9 | 10 |
|
@@ -178,16 +179,22 @@ export const useStore = defineStore(`store`, () => {
|
178 | 179 | isUseIndent: isUseIndent.value,
|
179 | 180 | })
|
180 | 181 |
|
| 182 | + const readingTime = ref<ReadTimeResults | null>(null) |
| 183 | + |
181 | 184 | // 更新编辑器
|
182 | 185 | const editorRefresh = () => {
|
183 | 186 | codeThemeChange()
|
184 | 187 | renderer.reset({ citeStatus: isCiteStatus.value, legend: legend.value, isUseIndent: isUseIndent.value, countStatus: isCountStatus.value })
|
185 | 188 |
|
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 |
187 | 192 | let outputTemp = marked.parse(markdownContent) as string
|
188 | 193 |
|
| 194 | + console.log(readingTime.value) |
| 195 | + |
189 | 196 | // 阅读时间及字数统计
|
190 |
| - outputTemp = renderer.buildReadingTime(readingTime) + outputTemp |
| 197 | + outputTemp = renderer.buildReadingTime(readingTimeResult) + outputTemp |
191 | 198 |
|
192 | 199 | // 去除第一行的 margin-top
|
193 | 200 | outputTemp = outputTemp.replace(/(style=".*?)"/, `$1;margin-top: 0"`)
|
@@ -451,6 +458,7 @@ export const useStore = defineStore(`store`, () => {
|
451 | 458 | primaryColor,
|
452 | 459 | codeBlockTheme,
|
453 | 460 | legend,
|
| 461 | + readingTime, |
454 | 462 |
|
455 | 463 | editorRefresh,
|
456 | 464 |
|
|
0 commit comments