feat: add new post creation script and theme update script, remove git-protect.list and sync-upstream.sh

- Deleted `README-zh.md` and `README.md` as they are no longer needed.
- Removed `git-protect.list` to streamline the synchronization process.
- Introduced `new-post.ts` script for easier blog post creation with default metadata.
- Added `update-theme.ts` script to simplify theme updates from the upstream repository.
- Updated content configuration to handle optional updated dates correctly.
- Adjusted pin values in theme guide documents to allow a range from 0-99 instead of 1-99.
This commit is contained in:
radishzzz 2025-05-28 20:41:08 +01:00
parent 886c959183
commit 2f80ab9523
17 changed files with 494 additions and 573 deletions

View file

@ -78,10 +78,6 @@ Retypeset is a static blog theme based on the [Astro](https://astro.build/) fram
Retypeset releases [new features](https://github.com/radishzzz/astro-theme-retypeset/issues/18) from time to time. You can refer to the [GitHub Docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) and run `Sync fork` in your repository to sync with the latest branch. Do not click `Discard Changes`, or you will lose your modifications.
For details on how to safely pull upstream changes **while preserving your custom content**, see:
👉 [`scripts/README.md`](./scripts/README.md)
## Credits
- [Typography](https://github.com/moeyua/astro-theme-typography)

View file

@ -74,15 +74,10 @@ Retypeset 是一款基于 [Astro](https://astro.build/) 框架的静态博客主
 [![Deploy to Netlify](images/deploy-netlify.svg)](https://app.netlify.com/start) [![Deploy to Vercel](images/deploy-vercel.svg)](https://vercel.com/new)
## 更新
Retypeset 会不定期发布 [新功能](https://github.com/radishzzz/astro-theme-retypeset/issues/18)。你可以参考 [GitHub 文档](https://docs.github.com/zh/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork),在仓库中执行 `Sync fork` 以同步最新分支。不要点击 `Discard Changes`,否则会丢失你的更改。
如需了解如何在**保留自定义内容的同时安全地拉取上游更新**,请参阅:
👉 [`scripts/README.md`](./scripts/README-zh.md) 文件
## 鸣谢
- [Typography](https://github.com/moeyua/astro-theme-typography)

View file

@ -11,7 +11,9 @@
"astro": "astro",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"comments": "curl -L https://unpkg.com/@waline/client@latest/dist/waline.css -o public/assets/waline/waline.css && curl -L https://unpkg.com/@waline/client@latest/dist/waline.js -o public/assets/waline/waline.js"
"comments": "curl -L https://unpkg.com/@waline/client@latest/dist/waline.css -o public/assets/waline/waline.css && curl -L https://unpkg.com/@waline/client@latest/dist/waline.js -o public/assets/waline/waline.js",
"update-theme": "esno scripts/update-theme.ts",
"new-post": "esno scripts/new-post.ts"
},
"dependencies": {
"@astrojs/mdx": "^4.3.0",
@ -22,7 +24,7 @@
"astro-og-canvas": "^0.7.0",
"astro-robots-txt": "^1.0.0",
"canvaskit-wasm": "^0.40.0",
"feed": "^5.0.1",
"feed": "^5.1.0",
"gsap": "^3.13.0",
"katex": "^0.16.22",
"markdown-it": "^14.1.0",
@ -45,7 +47,7 @@
"@astrojs/check": "^0.9.4",
"@types/hast": "^3.0.4",
"@types/markdown-it": "^14.1.2",
"@types/node": "^22.15.21",
"@types/node": "^22.15.24",
"@types/sanitize-html": "^2.16.0",
"@unocss/eslint-plugin": "66.1.2",
"@unocss/preset-attributify": "66.1.2",
@ -53,7 +55,8 @@
"astro-eslint-parser": "^1.2.2",
"eslint": "^9.27.0",
"eslint-plugin-astro": "^1.3.1",
"lint-staged": "^16.0.0",
"esno": "^4.8.0",
"lint-staged": "^16.1.0",
"typescript": "~5.8.3",
"unocss": "66.1.2",
"unocss-preset-theme": "^0.14.1"

721
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -1,65 +0,0 @@
## 🚀 基于本仓库创建并维护你自己的博客项目
本仓库为 [Astro](https://astro.build/) + [Retype](https://retype.com/) 构建的高颜值博客模板,支持一键部署和持续更新。以下是创建你自己的博客并与本模板保持同步的标准流程。
### ✅ 第一步:创建你自己的仓库
请**不要 Fork** 本仓库。
相反,请点击 👉 [Use this template](https://github.com/radishzzz/astro-theme-retypeset) 创建一个新的仓库副本。
> 📌 原因说明Fork 仓库将强制公开并可能暴露你的私人配置例如部署密钥、邮箱、API Token 等),不利于信息保护。
---
### ✏️ 第二步:保护你的自定义内容
你将在 `scripts/git-protect.list` 文件中声明需要保护的内容(如你撰写的文章、配置文件、页面自定义设置等)。
这些文件在后续执行上游同步时会被自动备份和恢复,确保不会被覆盖。
---
### 🌐 第三步:开发并部署你的博客
* 根据项目目录结构撰写你的内容;
* 使用平台如 [Vercel](https://vercel.com/)、[Netlify](https://www.netlify.com/) 等部署站点;
---
### 🔄 第四步:同步上游更新并保留本地定制
> 在你首次同步前,需添加上游远程地址(只需执行一次):
```bash
git remote add upstream https://github.com/radishzzz/astro-theme-retypeset.git
```
之后每次同步只需在项目根目录执行以下命令:
#### macOS / Linux / WSL / Git Bash推荐
```bash
chmod u+x scripts/sync-upstream.sh
bash scripts/sync-upstream.sh upstream/master /tmp/blog-sync
```
#### Windows 用户注意:
* **请使用 Git Bash** 执行上述命令;
* ❌ **不建议使用 cmd.exe 或 PowerShell**,以避免路径兼容与权限问题;
* 如需使用 Windows 运行脚本,推荐 Git Bash。路径参数使用 `/c/...` 格式,避免 Windows 风格路径。
---
### 📎 常见问题
* **为什么不通过Github Actions 自动化处理?**
由于游仓库的活跃,无法保证合并不需要人工介入。
* **为何要保护文件?**
上游可能会变更主题逻辑、样式或结构。通过 `git-protect.list` 声明关键文件,可在合并更新时避免被覆盖。
* **我修改了主题结构,是否还能同步?**
可以。但需在同步前手动解决冲突,并确保 `git-protect.list` 保护的路径无误。

View file

@ -1,66 +0,0 @@
## 🚀 Create and Maintain Your Own Blog Based on This Repository
This repository provides a visually polished blog template built with [Astro](https://astro.build/) and [Retype](https://retype.com/), designed for seamless deployment and long-term maintenance. Follow the steps below to initialize your own blog and keep it in sync with future upstream updates.
---
### ✅ Step 1: Create Your Own Repository
**Do not fork this repository.**
Instead, click 👉 [Use this template](https://github.com/radishzzz/astro-theme-retypeset) to create a new repository based on this template.
> 📌 **Why not fork?**
> Forked repositories are publicly visible by default, which may expose sensitive configuration data (e.g., deployment tokens, email addresses, API keys), posing a security risk.
---
### ✏️ Step 2: Safeguard Your Custom Content
Declare the files and directories you want to preserve in the `scripts/git-protect.list` file.
This includes your posts, configuration files, and site-specific settings. These items will be automatically backed up and restored during synchronization with the upstream repository, ensuring they are never overwritten.
---
### 🌐 Step 3: Develop and Deploy Your Blog
* Structure and write your content according to the projects directory layout.
* Deploy the site using platforms such as [Vercel](https://vercel.com/) or [Netlify](https://www.netlify.com/).
* Continuous deployment via GitHub Actions is supported but optional.
---
### 🔄 Step 4: Sync with Upstream While Preserving Local Customizations
> Before the first synchronization, add the upstream remote (only required once):
```bash
git remote add upstream https://github.com/radishzzz/astro-theme-retypeset.git
```
Then, run the sync script from the root directory of your repository:
#### macOS / Linux / WSL / Git Bash (Recommended):
```bash
chmod u+x scripts/sync-upstream.sh
bash scripts/sync-upstream.sh upstream/master /tmp/blog-sync
```
#### For Windows Users:
* ✅ **Use Git Bash** to run the above commands;
* ❌ **Avoid using cmd.exe or PowerShell**, as they may cause compatibility issues with file paths;
* For best results, stick with Git Bash even on Windows.Use the `/c/...` format for path arguments and avoid Windows-style paths.
---
### 📎 Frequently Asked Questions
* **Why not automate synchronization with GitHub Actions?**
Due to the active nature of this upstream repository, automatic merges are not guaranteed to be conflict-free. Manual review is often required.
* **Why are certain files protected?**
Upstream updates may introduce structural or styling changes. Defining protected files in `git-protect.list` ensures your custom content is preserved during synchronization.
* **Can I still sync if Ive modified the theme structure?**
Yes, but you'll need to manually resolve conflicts before syncing. Make sure all critical paths are properly listed in `git-protect.list`.

View file

@ -1,4 +0,0 @@
.cursor/
src/config.ts
src/content/
src/i18n/ui.ts

60
scripts/new-post.ts Normal file
View file

@ -0,0 +1,60 @@
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
import { basename, dirname, extname, join } from 'node:path'
import process from 'node:process'
import { themeConfig } from '../src/config'
// pnpm new-post
// pnpm new-post first-post
// pnpm new-post first-post.md
// pnpm new-post first-post.mdx
// pnpm new-post 2025/03/post
// pnpm new-post 2025/03/post.md
// pnpm new-post 2025/03/post.mdx
// Process file path
const rawPath = process.argv[2] || 'new-post'
const baseName = basename(rawPath).replace(/\.(md|mdx)$/, '')
const targetFile = ['.md', '.mdx'].includes(extname(rawPath))
? rawPath
: `${rawPath}.md`
const fullPath = join('src/content/posts', targetFile)
// Check if file already exists
if (existsSync(fullPath)) {
console.error(`❌ File already exists: ${fullPath}`)
process.exit(1)
}
// Create directory structure
mkdirSync(dirname(fullPath), { recursive: true })
// Prepare file content
const today = new Date().toISOString().split('T')[0]
const content = `---
title: ${baseName}
published: ${today}
# Optional
description: ''
updated: ''
tags:
- Note
# Advanced
draft: false
pin: 0
toc: ${themeConfig.global.toc}
lang: ''
abbrlink: ''
---
`
// Write to file
try {
writeFileSync(fullPath, content)
console.log(`✅ Post created: ${fullPath}`)
}
catch (error) {
console.error('❌ Failed to create post:', error)
process.exit(1)
}

View file

@ -1,82 +0,0 @@
#!/bin/bash
# filepath: sync-upstream.sh
# Usage: ./sync-upstream.sh <upstream/branch> <tmp_dir>
# Example: ./sync-upstream.sh upstream/master /tmp/astro-protect
set -e
###########################
# Configuration
DEBUG=true # Set to true to enable debug output
PROTECT_LIST="scripts/git-protect.list" # Path to the protected files list
###########################
UPSTREAM_BRANCH="$1"
TMP_DIR="$2"
# Debug output function
log_debug() {
if [[ "$DEBUG" == true ]]; then
echo -e "[DEBUG] $*"
fi
}
# Validate arguments
if [[ -z "$UPSTREAM_BRANCH" || -z "$TMP_DIR" ]]; then
echo "Usage: $0 <upstream/branch> <tmp_dir>"
exit 1
fi
if [[ ! -f "$PROTECT_LIST" ]]; then
echo "File not found: $PROTECT_LIST"
exit 1
fi
log_debug "Upstream branch: $UPSTREAM_BRANCH"
log_debug "Temporary directory: $TMP_DIR"
log_debug "Protection list file: $PROTECT_LIST"
# Include hidden files (e.g., .env)
shopt -s dotglob
# Step 1: Back up protected files and directories
mkdir -p "$TMP_DIR"
while IFS= read -r path || [[ -n "$path" ]]; do
[[ -z "$path" ]] && continue
[[ "${path:0:1}" == "#" ]] && continue
if [[ -e "$path" ]]; then
log_debug "Backing up: $path"
mkdir -p "$TMP_DIR/$(dirname "$path")"
cp -r "$path" "$TMP_DIR/$(dirname "$path")/"
else
log_debug "Skipping non-existent path: $path"
fi
done < "$PROTECT_LIST"
# Step 2: Fetch and apply upstream content
log_debug "Fetching from remote: ${UPSTREAM_BRANCH%%/*}"
git fetch "${UPSTREAM_BRANCH%%/*}"
log_debug "Checking out from $UPSTREAM_BRANCH"
git checkout "$UPSTREAM_BRANCH" -- .
# Step 3: Restore protected files
while IFS= read -r path || [[ -n "$path" ]]; do
[[ -z "$path" ]] && continue
[[ "${path:0:1}" == "#" ]] && continue
if [[ -e "$TMP_DIR/$path" ]]; then
log_debug "Restoring: $path"
rm -rf "$path"
mkdir -p "$(dirname "$path")"
cp -r "$TMP_DIR/$path" "$path"
else
log_debug "No backup found, skipping: $path"
fi
done < "$PROTECT_LIST"
# Step 4: Clean up
log_debug "Removing temporary directory: $TMP_DIR"
rm -rf "$TMP_DIR"
echo "✅ Sync complete. Protected files have been restored. Please review and git add/commit/push."

32
scripts/update-theme.ts Executable file
View file

@ -0,0 +1,32 @@
import { execSync } from 'node:child_process'
import process from 'node:process'
// pnpm update-theme
// Check and set up the remote repository
try {
execSync('git remote get-url upstream', { stdio: 'ignore' })
}
catch {
execSync('git remote add upstream https://github.com/radishzzz/astro-theme-retypeset.git', { stdio: 'inherit' })
}
// Update theme from upstream repository
try {
execSync('git fetch upstream', { stdio: 'inherit' })
const beforeHash = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim()
execSync('git merge upstream/main', { stdio: 'inherit' })
const afterHash = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim()
if (beforeHash === afterHash) {
console.log('✅ Already up to date')
}
else {
console.log('✨ Updated successfully')
}
}
catch (error) {
console.error('❌ Update failed:', error)
process.exit(1)
}

View file

@ -10,7 +10,10 @@ const posts = defineCollection({
published: z.date(),
// optional
description: z.string().optional().default(''),
updated: z.date().optional(),
updated: z.preprocess(
val => val === '' ? undefined : val,
z.date().optional(),
),
tags: z.array(z.string()).optional().default([]),
// Advanced
draft: z.boolean().optional().default(false),

View file

@ -301,7 +301,7 @@ tags:
# Advanced, Optional
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide

View file

@ -301,7 +301,7 @@ tags:
# Avanzado, Opcional
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide

View file

@ -301,7 +301,7 @@ tags:
# 高度な設定(任意)
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide

View file

@ -301,7 +301,7 @@ tags:
# Расширенные, опциональные
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide

View file

@ -301,7 +301,7 @@ tags:
# 進階,可選
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide

View file

@ -301,7 +301,7 @@ tags:
# 进阶,可选
draft: true/false
pin: 1-99
pin: 0-99
toc: true/false
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
abbrlink: theme-guide