基于 VitePress + Element Plus 的卡片风博客主题。
目标是简单易用:写 Markdown、推送代码、自动上线。
将本仓库 Fork 到你自己的 GitHub 仓库后,按下面流程即可开始使用。
- 把文章放到仓库根目录
posts/下即可。 - 根目录
site_config.yml用于定制网站效果(站点名称、首页文案、菜单、页脚等)。
- 安装 Node.js / npm 环境。
- 安装依赖:
npm i- 本地预览:
npm run dev- 本地打包:
npm run docs:build- 其他常用命令:
npm run preview
npm run build仓库已内置工作流。你只需要在 GitHub 仓库 Settings -> Actions -> General 中允许 Actions 运行。
之后每次推送到 main 都会触发自动构建和部署。
在 GitHub 仓库 Settings -> Pages 中,将 Source 设置为 GitHub Actions。
- 在 Vercel 导入并绑定该仓库。
- 在 GitHub 仓库
Settings -> Secrets and variables -> Actions配置:VERCEL_ORG_IDVERCEL_PROJECT_IDVERCEL_TOKEN
你可以把 Markdown 知识库仓库作为外部内容源,快速同步至本项目。
注意:
- 每次同步外部知识库内容,
posts/本地文章会被覆盖。 - 该功能适配第 3 节的工作流托管。托管方案会在每次构建时自动同步知识库内容。
在 GitHub 仓库 Settings -> Secrets and variables -> Actions 配置Repository secrets:
WIKI_URL:知识库仓库 Git URL(例如https://github.com/yourname/your-wiki.git)WIKI_BRANCH:可选,默认mainPAT:可选,私有仓库需要 使用托管方案不需要手动同步知识库
Windows PowerShell:
$env:WIKI_URL="https://github.com/yourname/your-wiki.git"
$env:WIKI_BRANCH="main"
$env:PAT="ghp_xxx" # 私有仓库时需要
npm run fetch-postsmacOS / Linux:
export WIKI_URL="https://github.com/yourname/your-wiki.git"
export WIKI_BRANCH="main"
export PAT="ghp_xxx" # 私有仓库时需要
npm run fetch-posts4.2.1 公开文章
外联知识库并不会全部公开。
仅当 Markdown 能正确解析 frontmatter,且包含 layout: doc 时,该文章会被保留并展示到网站。
4.2.2 配置文件优先级
如果知识库根目录中存在 site_config.yml,将被优先使用(忽略本仓库的site_config.yml配置)。
因此,推荐将site_config.yml复制进知识库根目录中,则可以使用update_theme.sh快速更新样式。
本仓库工作流监听 repository_dispatch 的 contents-updated 事件。
你可以在知识库仓库配置一个触发工作流,在更新后通知博客仓库重建。
需要在触发方仓库(文章/知识库仓库)添加
BLOG_REPOsecret,值为目标博客仓库全名(owner/repo)PATsecret。
示例:
# Place this workflow in your content/wiki repository (not the blog repo).
name: Trigger Blog Rebuild
on:
push:
branches: [main]
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Dispatch event to blog repo
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT }} # PAT stored in the content/wiki repo
repository: ${{ secrets.BLOG_REPO }} # e.g. 57Darling02/57Darling02.github.io
event-type: contents-updated根目录 site_config.yml为配置文件,推荐将其复制到posts/或关联知识库的根目录中修改:
进入fontawesome选取自己喜欢的图标。
site_name: "My Awesome Blog"
author: "Your Name"
socialLinks:
- name: "GitHub"
icon: "fa-brands fa-github"
url: "https://github.com/..."在posts/public 或 知识库根目录/public下放置图片,即可直接使用。
例如:背景图放置在 posts\public\wallpaper\1.webp 或者知识库根目录\public\wallpaper\1.webp
则site_config.yml中配置
background: "/wallpaper/2.webp"即可调用。
或者使用网络图床资源:
例如:site_config.yml中配置
avatar: "https://resource-un4.pages.dev/article/yjtp.webp" 即成功配置头像
---
title: My Post Title
date: 2024-03-20
author: Me
layout: doc
cover: /path/to/image.png
---1.1 外联知识库时,layout: doc才会被发布
1.2 cover封面不能直接使用文章内部的插图!可以使用public或者网络图片
文章内部插图相对简单,只需要使用相对位置即可。obsidian配置如图:
好玩又有用的文字展示效果、甚至嵌入自己写的网页或vue组件, 参考 👉文档
VitePress-Butterfly/
├── .vitepress/ # Theme core
├── posts/ # Markdown content
├── public/ # Static assets
├── scripts/ # Build scripts
├── site_config.yml # Site config
└── package.json
MIT © 2024-present 57Darling02