采用了 @HanochMa 的项目
仓库:**https://github.com/HanochMa/vitepress-markdown-timeline**
Demo:**https://hanochma.github.io/daily/2023-04**
pnpm add -D vitepress-markdown-timeline
yarn add -D vitepress-markdown-timeline
npm install vitepress-markdown-timeline
在 config.mts
中注册 markdown 解析插件
import timeline from "vitepress-markdown-timeline";
export default {
markdown: {
//行号显示
lineNumbers: true,
//时间线
config: (md) => {
md.use(timeline);
},
},
}
在 .vitepress/theme/index.ts
中引入时间线样式。如果你没有这个文件,就自己新建
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme'
// 只需添加以下一行代码,引入时间线样式
import "vitepress-markdown-timeline/dist/theme/index.css";
export default {
extends: DefaultTheme,
}
最后我们在markdown文件中,按格式使用即可
::: timeline 2023-04-24
- 一个非常棒的开源项目 H5-Dooring 目前 star 3.1k
- 开源地址 <https://github.com/MrXujiang/h5-Dooring>
- 基本介绍 <http://h5.dooring.cn/doc/zh/guide/>
- 《深入浅出webpack》 <http://webpack.wuhaolin.cn/>
:::
::: timeline 2023-04-23
:::
利用插件 google-analytics ,来查看网站访问量,这里我们用 @ZhongxuYang 的插件
仓库:**https://github.com/ZhongxuYang/vitepress-plugin-google-analytics**
pnpm add -D vitepress-plugin-google-analytics
yarn add -D vitepress-plugin-google-analytics
npm install vitepress-plugin-google-analytics
在 .vitepress/theme/index.ts
中引入
// .vitepress/theme/index.ts
import DefaultTheme from "vitepress/theme"
import googleAnalytics from 'vitepress-plugin-google-analytics'
export default {
extends: DefaultTheme,
enhanceApp({app}) {
googleAnalytics({
id: 'G-******', //跟踪ID,在analytics.google.com注册即可
}),
},
}
pnpm add -D medium-zoom
yarn add -D medium-zoom
npm install medium-zoom
在 .vitepress/theme/index.ts
添加如下代码,并保存
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme'
import mediumZoom from 'medium-zoom';
import { onMounted, watch, nextTick } from 'vue';
import { useRoute } from 'vitepress';
export default {
extends: DefaultTheme,
setup() {
const route = useRoute();
const initZoom = () => {
// mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' }); // 默认
mediumZoom('.main img', { background: 'var(--vp-c-bg)' }); // 不显式添加{data-zoomable}的情况下为所有图像启用此功能
};
onMounted(() => {
initZoom();
});
watch(
() => route.path,
() => nextTick(() => initZoom())
);
},
}
点击图片后,还是能看到导航栏,加一个遮挡样式。在 .vitepress/theme/style/var.css
中加入如下代码,并保存
/* .vitepress/theme/style/var.css */
.medium-zoom-overlay {
z-index: 20;
}
.medium-zoom-image {
z-index: 9999 !important;/* 给的值是21,但是实测盖不住,直接999 */
}
pnpm add -D busuanzi.pure.js
yarn add -D busuanzi.pure.js
npm install busuanzi.pure.js
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme'
import { inBrowser } from 'vitepress'
import busuanzi from 'busuanzi.pure.js'
export default {
extends: DefaultTheme,
enhanceApp({ app , router }) {
if (inBrowser) {
router.onAfterRouteChanged = () => {
busuanzi.fetch()
}
}
},
}
使用就很简单了,也可以自己写个好看点的组件
本站总访问量 <span id="busuanzi_value_site_pv" /> 次
本站访客数 <span id="busuanzi_value_site_uv" /> 人次
Giscus 是一个基于 GitHub Discussion 的评论系统,启用简便
进 Giscus App官网:**https://github.com/apps/giscus**
点击 Install
安装;选择 Only select repositories
,再指定一个你想开启讨论的仓库;完成后可以在个人头像-设置-应用 Applications
中看到
因为giscus会把评论数据都放到讨论 discussions
中
我们进入要开启讨论的仓库,点设置 - 勾选讨论 Settings - discussions
进入官网:**https://giscus.app/zh-CN**
输入自己的仓库链接,满足条件会提示可用
下拉到 Discussion 分类我们按推荐的选 Announcements
,懒加载评论也可以勾选下
下方就自动生成了你的关键数据
其中 data-repo
、 data-repo-id
、 data-category
和 data-category-id
这4个是我们的关键数据
<script src="<https://giscus.app/client.js>"
data-repo="Yiov/vitepress-doc"
data-repo-id="R_******"
data-category="Announcements"
data-category-id="DIC_******"
data-mapping="pathname"
data-strict="0"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="bottom"
data-theme="preferred_color_scheme"
data-lang="zh-CN"
data-loading="lazy"
crossorigin="anonymous"
async>
</script>
有能力的可以用官方给的js数据封装,我这里用 @T-miracle 的插件
仓库:**https://github.com/T-miracle/vitepress-plugin-comment-with-giscus**
pnpm add -D vitepress-plugin-comment-with-giscus
yarn add -D vitepress-plugin-comment-with-giscus
npm install vitepress-plugin-comment-with-giscus
在 .vitepress/theme/index.ts
中填入下面代码
并将我们之前获取的4个关键数据填入,其他保持默认保存
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme';
import giscusTalk from 'vitepress-plugin-comment-with-giscus';
import { useData, useRoute } from 'vitepress';
export default {
extends: DefaultTheme,
setup() {
// Get frontmatter and route
const { frontmatter } = useData();
const route = useRoute();
// giscus配置
giscusTalk({
repo: 'your github repository', //仓库
repoId: 'your repository id', //仓库ID
category: 'Announcements', // 讨论分类
categoryId: 'your category id', //讨论分类ID
mapping: 'pathname',
inputPosition: 'bottom',
lang: 'zh-CN',
},
{
frontmatter, route
},
//默认值为true,表示已启用,此参数可以忽略;
//如果为false,则表示未启用
//您可以使用“comment:true”序言在页面上单独启用它
true
);
}