Skip to content

Commit

Permalink
修复 frontmatter 数据没有在页面切换时正确更新的 bug (project-trans#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leetfs authored Sep 21, 2024
1 parent 4ec030e commit f673412
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/preview-pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `${{ steps.deploy.outputs.url }}`;
const comment = `🚀 预览部署完成! 访问链接: ${previewUrl}`;
const comment = `🚀 预览部署完成 访问链接: ${previewUrl}`;
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { useData } from 'vitepress'
import { ref, watch } from 'vue'
// 获取页面数据
const { frontmatter } = useData()
Expand All @@ -10,9 +11,15 @@ function calculateReadingTime(wordCount: number) {
return Math.ceil(wordCount / wordsPerMinute) // 计算预计阅读时间
}
// 从 frontmatter 获取字数和计算阅读时间
const wordCount = frontmatter.value.wordCount || 0
const readingTime = calculateReadingTime(wordCount)
// 使用 ref 创建响应式变量
const wordCount = ref(frontmatter.value.wordCount || 0)
const readingTime = ref(calculateReadingTime(wordCount.value))
// 监听 frontmatter 的变化
watch(() => frontmatter.value, (newFrontmatter) => {
wordCount.value = newFrontmatter.wordCount || 0
readingTime.value = calculateReadingTime(wordCount.value)
})
</script>

<template>
Expand Down

0 comments on commit f673412

Please sign in to comment.