Skip to content

Commit

Permalink
修复字数bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Leetfs committed Sep 21, 2024
1 parent 4ec030e commit 86767ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: 部署到 Cloudflare Pages
on:
push:
branches:
- 'main' # 当推送到 main 分支时触发
- 'devread' # 当推送到 main 分支时触发

jobs:
deploy:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useData } from 'vitepress'
// 获取页面数据
const { frontmatter } = useData()
// 定义响应式变量
const wordCount = ref(0)
const readingTime = ref(0)
// 计算阅读时间的函数
function calculateReadingTime(wordCount: number) {
const calculateReadingTime = (wordCount: number) => {
const wordsPerMinute = 500 // 假设中文阅读速度为每分钟500字
return Math.ceil(wordCount / wordsPerMinute) // 计算预计阅读时间
}
// 从 frontmatter 获取字数和计算阅读时间
const wordCount = frontmatter.value.wordCount || 0
const readingTime = calculateReadingTime(wordCount)
// 在组件挂载后获取字数并计算阅读时间
onMounted(() => {
wordCount.value = frontmatter.value.wordCount || 0
readingTime.value = calculateReadingTime(wordCount.value)
})
</script>

<template>
Expand Down

0 comments on commit 86767ae

Please sign in to comment.