优化:初步优化全局代码样式
This commit is contained in:
@@ -68,49 +68,49 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, toRefs, onMounted } from 'vue'
|
||||
import { useData } from 'vitepress'
|
||||
import md5 from 'blueimp-md5'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/zh-cn'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { goToLink } from '../utils.ts'
|
||||
import { reactive, toRefs, onMounted } from 'vue';
|
||||
import { useData } from 'vitepress';
|
||||
import md5 from 'blueimp-md5';
|
||||
import dayjs from 'dayjs';
|
||||
import 'dayjs/locale/zh-cn';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
import { goToLink } from '../utils.ts';
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
dayjs.locale('zh-cn')
|
||||
dayjs.extend(relativeTime);
|
||||
dayjs.locale('zh-cn');
|
||||
|
||||
// 定义文章属性
|
||||
const props = defineProps({
|
||||
article: Object,
|
||||
showCategory: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
// 定义文章属性
|
||||
const props = defineProps({
|
||||
article: Object,
|
||||
showCategory: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
// 初始化文章元数据信息
|
||||
const { theme, page } = useData();
|
||||
const data = reactive({
|
||||
isOriginal: props.article?.isOriginal ?? true,
|
||||
author: props.article?.author ?? theme.value.articleMetadataConfig.author,
|
||||
authorLink: props.article?.authorLink ?? theme.value.articleMetadataConfig.authorLink,
|
||||
showViewCount: theme.value.articleMetadataConfig?.showViewCount ?? false,
|
||||
viewCount: 0,
|
||||
date: new Date(props.article.date),
|
||||
categories: props.article?.categories ?? [],
|
||||
tags: props.article?.tags ?? [],
|
||||
showCategory: props.showCategory
|
||||
});
|
||||
const { isOriginal, author, authorLink, showViewCount, viewCount, date, toDate, categories, tags, showCategory } = toRefs(data);
|
||||
|
||||
if (data.showViewCount) {
|
||||
// 记录并获取文章阅读数(使用文章标题 + 发布时间生成 MD5 值,作为文章的唯一标识)
|
||||
onMounted(() => {
|
||||
$api.getArticleViewCount(md5(props.article.title + props.article.date), location.href, function(viewCountData) {
|
||||
data.viewCount = viewCountData;
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化文章元数据信息
|
||||
const { theme, page } = useData()
|
||||
const data = reactive({
|
||||
isOriginal: props.article?.isOriginal ?? true,
|
||||
author: props.article?.author ?? theme.value.articleMetadataConfig.author,
|
||||
authorLink: props.article?.authorLink ?? theme.value.articleMetadataConfig.authorLink,
|
||||
showViewCount: theme.value.articleMetadataConfig?.showViewCount ?? false,
|
||||
viewCount: 0,
|
||||
date: new Date(props.article.date),
|
||||
categories: props.article?.categories ?? [],
|
||||
tags: props.article?.tags ?? [],
|
||||
showCategory: props.showCategory
|
||||
})
|
||||
const { isOriginal, author, authorLink, showViewCount, viewCount, date, toDate, categories, tags, showCategory } = toRefs(data)
|
||||
|
||||
if (data.showViewCount) {
|
||||
// 记录并获取文章阅读数(使用文章标题 + 发布时间生成 MD5 值,作为文章的唯一标识)
|
||||
onMounted(() => {
|
||||
$api.getArticleViewCount(md5(props.article.title + props.article.date), location.href, function(viewCountData) {
|
||||
data.viewCount = viewCountData
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
Reference in New Issue
Block a user