mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-15 11:12:54 +02:00
Merge pull request #28 from radishzzz/pr-27
✨ feat: add new post creation script and theme update script, remove git-protect.list and sync-upstream.sh
This commit is contained in:
commit
e1f326a4da
11 changed files with 132 additions and 11 deletions
|
@ -11,7 +11,9 @@
|
||||||
"astro": "astro",
|
"astro": "astro",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint:fix": "eslint . --fix",
|
"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": {
|
"dependencies": {
|
||||||
"@astrojs/mdx": "^4.3.0",
|
"@astrojs/mdx": "^4.3.0",
|
||||||
|
|
30
pnpm-lock.yaml
generated
30
pnpm-lock.yaml
generated
|
@ -120,6 +120,9 @@ importers:
|
||||||
eslint-plugin-astro:
|
eslint-plugin-astro:
|
||||||
specifier: ^1.3.1
|
specifier: ^1.3.1
|
||||||
version: 1.3.1(eslint@9.27.0(jiti@2.4.2))
|
version: 1.3.1(eslint@9.27.0(jiti@2.4.2))
|
||||||
|
esno:
|
||||||
|
specifier: ^4.8.0
|
||||||
|
version: 4.8.0
|
||||||
lint-staged:
|
lint-staged:
|
||||||
specifier: ^16.1.0
|
specifier: ^16.1.0
|
||||||
version: 16.1.0
|
version: 16.1.0
|
||||||
|
@ -1436,8 +1439,8 @@ packages:
|
||||||
resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==}
|
resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
ansis@4.0.0:
|
ansis@4.1.0:
|
||||||
resolution: {integrity: sha512-P8nrHI1EyW9OfBt1X7hMSwGN2vwRuqHSKJAT1gbLWZRzDa24oHjYwGHvEgHeBepupzk878yS/HBZ0NMPYtbolw==}
|
resolution: {integrity: sha512-BGcItUBWSMRgOCe+SVZJ+S7yTRG0eGt9cXAHev72yuGcY23hnLA7Bky5L/xLyPINoSN95geovfBkqoTlNZYa7w==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
|
|
||||||
anymatch@3.1.3:
|
anymatch@3.1.3:
|
||||||
|
@ -2098,6 +2101,10 @@ packages:
|
||||||
jiti:
|
jiti:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
esno@4.8.0:
|
||||||
|
resolution: {integrity: sha512-acMtooReAQGzLU0zcuEDHa8S62meh5aIyi8jboYxyvAePdmuWx2Mpwmt0xjwO0bs9/SXf+dvXJ0QJoDWw814Iw==}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
espree@10.3.0:
|
espree@10.3.0:
|
||||||
resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==}
|
resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==}
|
||||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||||
|
@ -3549,6 +3556,11 @@ packages:
|
||||||
tslib@2.8.1:
|
tslib@2.8.1:
|
||||||
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
|
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
|
||||||
|
|
||||||
|
tsx@4.19.4:
|
||||||
|
resolution: {integrity: sha512-gK5GVzDkJK1SI1zwHf32Mqxf2tSJkNx+eYcNly5+nHvWqXUJYUkWBQtKauoESz3ymezAI++ZwT855x5p5eop+Q==}
|
||||||
|
engines: {node: '>=18.0.0'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
type-check@0.4.0:
|
type-check@0.4.0:
|
||||||
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
|
@ -5467,7 +5479,7 @@ snapshots:
|
||||||
|
|
||||||
ansi-styles@6.2.1: {}
|
ansi-styles@6.2.1: {}
|
||||||
|
|
||||||
ansis@4.0.0: {}
|
ansis@4.1.0: {}
|
||||||
|
|
||||||
anymatch@3.1.3:
|
anymatch@3.1.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -6357,6 +6369,10 @@ snapshots:
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
esno@4.8.0:
|
||||||
|
dependencies:
|
||||||
|
tsx: 4.19.4
|
||||||
|
|
||||||
espree@10.3.0:
|
espree@10.3.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
acorn: 8.14.1
|
acorn: 8.14.1
|
||||||
|
@ -8325,6 +8341,13 @@ snapshots:
|
||||||
|
|
||||||
tslib@2.8.1: {}
|
tslib@2.8.1: {}
|
||||||
|
|
||||||
|
tsx@4.19.4:
|
||||||
|
dependencies:
|
||||||
|
esbuild: 0.25.5
|
||||||
|
get-tsconfig: 4.10.1
|
||||||
|
optionalDependencies:
|
||||||
|
fsevents: 2.3.3
|
||||||
|
|
||||||
type-check@0.4.0:
|
type-check@0.4.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
prelude-ls: 1.2.1
|
prelude-ls: 1.2.1
|
||||||
|
@ -8567,6 +8590,7 @@ snapshots:
|
||||||
jiti: 2.4.2
|
jiti: 2.4.2
|
||||||
lightningcss: 1.29.3
|
lightningcss: 1.29.3
|
||||||
terser: 5.39.0
|
terser: 5.39.0
|
||||||
|
tsx: 4.19.4
|
||||||
yaml: 2.8.0
|
yaml: 2.8.0
|
||||||
|
|
||||||
vitefu@1.0.6(vite@6.3.5(@types/node@22.15.23)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(yaml@2.8.0)):
|
vitefu@1.0.6(vite@6.3.5(@types/node@22.15.23)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(yaml@2.8.0)):
|
||||||
|
|
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)
|
||||||
|
}
|
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)
|
||||||
|
}
|
|
@ -10,7 +10,10 @@ const posts = defineCollection({
|
||||||
published: z.date(),
|
published: z.date(),
|
||||||
// optional
|
// optional
|
||||||
description: z.string().optional().default(''),
|
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([]),
|
tags: z.array(z.string()).optional().default([]),
|
||||||
// Advanced
|
// Advanced
|
||||||
draft: z.boolean().optional().default(false),
|
draft: z.boolean().optional().default(false),
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# Advanced, Optional
|
# Advanced, Optional
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# Avanzado, Opcional
|
# Avanzado, Opcional
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# 高度な設定(任意)
|
# 高度な設定(任意)
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# Расширенные, опциональные
|
# Расширенные, опциональные
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# 進階,可選
|
# 進階,可選
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
|
@ -301,7 +301,7 @@ tags:
|
||||||
|
|
||||||
# 进阶,可选
|
# 进阶,可选
|
||||||
draft: true/false
|
draft: true/false
|
||||||
pin: 1-99
|
pin: 0-99
|
||||||
toc: true/false
|
toc: true/false
|
||||||
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
lang: de/en/es/fr/ja/ko/pl/pt/ru/zh/zh-tw
|
||||||
abbrlink: theme-guide
|
abbrlink: theme-guide
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue