mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-15 11:12:54 +02:00
✨ 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:
parent
886c959183
commit
2f80ab9523
17 changed files with 494 additions and 573 deletions
|
@ -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` 保护的路径无误。
|
|
@ -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 project’s 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 I’ve 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`.
|
|
@ -1,4 +0,0 @@
|
|||
.cursor/
|
||||
src/config.ts
|
||||
src/content/
|
||||
src/i18n/ui.ts
|
60
scripts/new-post.ts
Normal file
60
scripts/new-post.ts
Normal 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)
|
||||
}
|
|
@ -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
32
scripts/update-theme.ts
Executable 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue