333 字
2 分钟
Astro分离文章仓库最佳实践

Astro分离文章仓库最佳实践#

TIP

Astro 站点主框架与文章分离,且文章按公开/私有分别存放于不同仓库

1. 整体架构#

[ 主框架仓库 (core) ] ← 私有,包含 Astro 项目、页面模板、样式、组件
├── src/content/public/ ← Git 子模块 → [ 公开文章仓库 (public-posts) ] 公开
└── src/content/private/ ← Git 子模块 → [ 私有文章仓库 (private-posts) ] 私有
  • 核心仓库:负责网站框架、布局、路由。建议设为私有(避免暴露私有子模块地址)。
  • 公开文章仓库:所有人可读,贡献者通过 PR 提交内容。
  • 私有文章仓库:仅授权成员可访问,存放内部文档、草稿、会员内容等。

通过 Git 子模块 将两个内容仓库挂载到核心项目的 src/content 下,让 Astro 像使用本地文件一样处理它们。

2. 仓库初始化#

2.1 创建核心仓库并添加子模块#

bash

# 在 core 项目中
git submodule add git@github.com:your-org/public-posts.git src/content/public
git submodule add git@github.com:your-org/private-posts.git src/content/private
git commit -m "Add content submodules"

2.2 开发者克隆核心仓库#

bash

git clone --recurse-submodules git@github.com:your-org/core.git
# 若未自动拉取子模块,可手动执行:
git submodule update --init --recursive

如果开发者没有私有仓库权限,private 子模块会拉取失败。此时需要借助环境变量跳过(见下节)。

Astro分离文章仓库最佳实践
https://blog.minggh.cn/posts/public-content/tutorial/astro最佳实践01/
作者
六爻
发布于
2026-06-15
许可协议
CC BY-NC-SA 4.0