Skip to content

About

personBlog

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

我的个人博客

轻量版个人博客:零构建,读 Markdown 即时渲染,改文章保存后浏览器自动实时刷新;同时支持一条命令静态导出,发布到 GitHub Pages。

仿 Fuwari 主题观感,功能包括:首页分页、归档页(按年时间线 + 右侧年份导航)、分类/标签筛选、文章页(上一篇/下一篇)、关于/作品页(GitHub 仓库卡片)、站内搜索、亮/暗色模式、RSS。

整套依赖只有 2 个包(markdown-it、highlight.js,共 8 个文件 + package-lock),无构建步骤、无打包器。

快速开始

npm install        # 安装依赖(仅 markdown-it、highlight.js)
npm run dev        # 启动本地服务 → http://localhost:4321/personBlog/

实时更新:直接编辑 src/content/posts/ 下的 Markdown,保存后浏览器会在 1 秒内自动刷新并显示新内容(服务会监听内容、配置与资源文件,通过 SSE 推送)。新增/删除文章、修改 blog.config.json、替换 public/ 资源都会即时生效,无需重启。

写文章

在 src/content/posts/ 下新建 .md 文件(或 文件夹/index.md),文件头带上 frontmatter:

---
title: "文章标题"
published: 2026-09-07
description: 一句话简介。
tags: [标签1, 标签2]
category: 分类名
draft: false
---
  • draft: true 的文章只在本地开发时可见,npm run build 静态导出时会自动过滤。
  • 作品页支持 ::github{repo="用户名/仓库名"} 指令,自动渲染 GitHub 仓库卡片。

站点配置

所有身份信息集中在一个 blog.config.json:

字段 说明
base GitHub Pages 路径前缀(项目仓库保持 personBlog;<用户名>.github.io 根仓库改为 "")
title / subtitle / author / bio 站点标题、副标题、作者名、简介
avatar 头像文件(放在 public/,如 avatar.png)
siteUrl 可选,站点的绝对地址(如 https://用户名.github.io/personBlog),设置后 RSS 等输出绝对链接
hue 主题主色(0–360)
perPage 首页每页文章数
nav / social 顶部导航与社交链接

静态导出与 GitHub Pages

npm run build      # 输出到 dist/(与动态服务渲染结果一致,draft 被过滤)
npm run preview    # 本地预览 dist 的渲染效果

推送后 .github/workflows/deploy.yml 会自动执行 npm install + npm run build 并发布 GitHub Pages:

git remote set-url origin https://github.com/<你的用户名>/<仓库名>.git
git push -u origin master

访问地址取决于仓库名:

  • 项目仓库(如 <用户名>/personBlog)→ https://<用户名>.github.io/personBlog/,blog.config.json 保持 base: "personBlog"。
  • 根仓库(<用户名>/<用户名>.github.io)→ https://<用户名>.github.io/,把 base 改为 "",并把仓库 Settings → Pages 的 Source 设为 GitHub Actions。

目录结构

server.mjs          # 动态服务(路由 / 缓存 / 文件监听 / SSE 实时刷新)
build.mjs           # 静态导出到 dist/
lib/blog.js         # 数据与渲染核心(frontmatter、markdown、聚合、页面)
lib/router.js       # 路由表(server 与 build 共用)
public/             # 静态资源:style.css、app.js、avatar.png 等
src/content/posts/  # 文章(Markdown)
src/content/spec/   # about.md、products.md
blog.config.json    # 站点配置

与旧版 Astro 的差异

  • 不移植:数学公式(KaTeX)、mermaid 图表、Pagefind 词根搜索、主题色滑块(保留了亮/暗/跟随系统)。
  • 文章正文支持标准 Markdown、代码高亮(highlight.js)、HTML、GitHub 仓库卡片指令。
  • 原本的 Astro 源码可从 git 历史恢复;内容(src/content/)与本文档是唯一事实来源。

致谢

About

personBlog

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages