修复 frontmatter 数据没有在页面切换时正确更新的 bug (#431)
部署到 Cloudflare Pages / deploy (push) Has been cancelled
Details
部署到 Cloudflare Pages / deploy (push) Has been cancelled
Details
parent
4ec030e988
commit
f673412ea2
|
@ -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,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { useData } from 'vitepress'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
// 获取页面数据
|
||||
const { frontmatter } = useData()
|
||||
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue