---
title: "一种内容管理的新想法"
tags: ["astro", "blog"]
categories: ["thought"]
pubDate: "2024-09-25T17:24:00.000Z"
isDraft: false
---

> 一个季度没更新一篇博文，又在折腾这些有的没的，有些惭愧。


想法的来源是希望提笔写些内容的时候，不用疲于在各个仓库之间来回切换，博客、数字花园、还有一些更零碎的笔记。

**如何在一个地方管理好这些内容，并且有一个舒服的书写环境？**

在更换 obsidian 同步的时候，看到 obsidian 的 git 插件，随即产生一个想法：

如果我把 astro/content 中所有的内容用一个 vault 保存起来，并用该 git 插件提交内容，继而触发 vercel 的自动构建，自己不就有了一个桌面端的**无与伦比**的内容管理工具了吗？

在一路思考着并实践中，整个技术路线也越来越清晰了

- 基于之前博客的项目，增加数字花园的内容，并集成之前解析 wikilink 的插件
- 博客项目中的 content 目录，作为一个独立的 repo，使用 submodule 的方式集成到主项目中
- 使用 github action，当 content 项目更新时，自动更新博客项目，并触发主项目构建

## 迁移数字花园

如何把数字花园从之前的 [Starlight](https://starlight.astro.build/getting-started/) 绑定到博客的项目中来？

首先，我尝试使用最小的工作量把 starlight 集成进来。技术上确实没问题，只需要把路由配好，项目就跑起来了，倒是提升了一些跳转速度，但两个页面风格差异的问题直让我挠头，即使配上 [GitHub - HiDeoo/starlight-theme-rapide: Starlight theme inspired by the Visual Studio Code Vitesse theme](https://github.com/HiDeoo/starlight-theme-rapide) 这个主题切换的时候也很违和。尝试重写一部分组件，后来发现自己水平不够，有几个部分确实达不到自己想要的结果，只得另寻他法。

进一步，直接放弃了 starlight，用 astro 自己重写这部分内容，做的过程中自己发现如果只是把内容展示出来，给内容加一个大致的目录树的话，工作量其实不大，wikilink 的解析之前也做过，碰到的唯一一点障碍是 [Routing too many redirects when using the config.json file generated by the Vercel adapter · Issue #418 · withastro/adapters · GitHub](https://github.com/withastro/adapters/issues/418)，不过自己不是强迫症的话这倒也不是问题。

## content 更新触发构建

1. 博客项目中 [yuhang.ch/.github/workflows/update-content.yml at main · yuhangch/yuhang.ch · GitHub](https://github.com/yuhangch/yuhang.ch/blob/main/.github/workflows/update-content.yml)
2. content 项目中 [content/.github/workflows/deploy.yml at main · yuhangch/content · GitHub](https://github.com/yuhangch/content/blob/main/.github/workflows/deploy.yml)

这两个脚本都是 GPT 写的，踩到的坑都集中在 Github Token 的权限分配上。[[github-submodule-auto-update|自动更新submodule]] 这篇记了一部分。


## 最后

更新这部分内容的时候，顺便把 astro的一些新 feature应用了起来，比如 `astro:env`，`getCollection` ，因此项目从创建到完善，一直没什么敏感信息，所以两个仓库都设成公开可见了。

1. [GitHub - yuhangch/content](https://github.com/yuhangch/content)

2. [GitHub - yuhangch/yuhang.ch: Yuhang's Site](https://github.com/yuhangch/yuhang.ch)

至于这部分更新何时同步到[GitHub - yuhangch/astro-theme-panda: A tiny blog theme for astro.](https://github.com/yuhangch/astro-theme-panda)，可能要等下一次空闲了。