修复 frontmatter 数据没有在页面切换时正确更新的 bug (#431)
部署到 Cloudflare Pages / deploy (push) Has been cancelled Details

pull/432/head
Lee 2024-09-21 13:52:43 +08:00 committed by GitHub
parent 4ec030e988
commit f673412ea2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -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,

View File

@ -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>