diff --git a/package.json b/package.json index b3e1aa2..e60e2c6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2ff757..d415dcf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -120,6 +120,9 @@ importers: eslint-plugin-astro: specifier: ^1.3.1 version: 1.3.1(eslint@9.27.0(jiti@2.4.2)) + esno: + specifier: ^4.8.0 + version: 4.8.0 lint-staged: specifier: ^16.1.0 version: 16.1.0 @@ -1436,8 +1439,8 @@ packages: resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} engines: {node: '>=12'} - ansis@4.0.0: - resolution: {integrity: sha512-P8nrHI1EyW9OfBt1X7hMSwGN2vwRuqHSKJAT1gbLWZRzDa24oHjYwGHvEgHeBepupzk878yS/HBZ0NMPYtbolw==} + ansis@4.1.0: + resolution: {integrity: sha512-BGcItUBWSMRgOCe+SVZJ+S7yTRG0eGt9cXAHev72yuGcY23hnLA7Bky5L/xLyPINoSN95geovfBkqoTlNZYa7w==} engines: {node: '>=14'} anymatch@3.1.3: @@ -2098,6 +2101,10 @@ packages: jiti: optional: true + esno@4.8.0: + resolution: {integrity: sha512-acMtooReAQGzLU0zcuEDHa8S62meh5aIyi8jboYxyvAePdmuWx2Mpwmt0xjwO0bs9/SXf+dvXJ0QJoDWw814Iw==} + hasBin: true + espree@10.3.0: resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -3549,6 +3556,11 @@ packages: tslib@2.8.1: 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: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} @@ -5467,7 +5479,7 @@ snapshots: ansi-styles@6.2.1: {} - ansis@4.0.0: {} + ansis@4.1.0: {} anymatch@3.1.3: dependencies: @@ -6357,6 +6369,10 @@ snapshots: transitivePeerDependencies: - supports-color + esno@4.8.0: + dependencies: + tsx: 4.19.4 + espree@10.3.0: dependencies: acorn: 8.14.1 @@ -8325,6 +8341,13 @@ snapshots: 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: dependencies: prelude-ls: 1.2.1 @@ -8567,6 +8590,7 @@ snapshots: jiti: 2.4.2 lightningcss: 1.29.3 terser: 5.39.0 + tsx: 4.19.4 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)): diff --git a/scripts/new-post.ts b/scripts/new-post.ts new file mode 100644 index 0000000..74edd4e --- /dev/null +++ b/scripts/new-post.ts @@ -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) +} diff --git a/scripts/update-theme.ts b/scripts/update-theme.ts new file mode 100755 index 0000000..98ea811 --- /dev/null +++ b/scripts/update-theme.ts @@ -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) +} diff --git a/src/content.config.ts b/src/content.config.ts index 7f5df19..83615cd 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -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), diff --git a/src/content/posts/guides/Theme Guide-en.md b/src/content/posts/guides/Theme Guide-en.md index 3704ae6..0acd8ca 100644 --- a/src/content/posts/guides/Theme Guide-en.md +++ b/src/content/posts/guides/Theme Guide-en.md @@ -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 diff --git a/src/content/posts/guides/Theme Guide-es.md b/src/content/posts/guides/Theme Guide-es.md index bc952e8..1b84051 100644 --- a/src/content/posts/guides/Theme Guide-es.md +++ b/src/content/posts/guides/Theme Guide-es.md @@ -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 diff --git a/src/content/posts/guides/Theme Guide-ja.md b/src/content/posts/guides/Theme Guide-ja.md index bf141c7..33698a9 100644 --- a/src/content/posts/guides/Theme Guide-ja.md +++ b/src/content/posts/guides/Theme Guide-ja.md @@ -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 diff --git a/src/content/posts/guides/Theme Guide-ru.md b/src/content/posts/guides/Theme Guide-ru.md index 0bdacf5..de0af99 100644 --- a/src/content/posts/guides/Theme Guide-ru.md +++ b/src/content/posts/guides/Theme Guide-ru.md @@ -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 diff --git a/src/content/posts/guides/Theme Guide-zh-tw.md b/src/content/posts/guides/Theme Guide-zh-tw.md index e338366..00053cb 100644 --- a/src/content/posts/guides/Theme Guide-zh-tw.md +++ b/src/content/posts/guides/Theme Guide-zh-tw.md @@ -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 diff --git a/src/content/posts/guides/Theme Guide-zh.md b/src/content/posts/guides/Theme Guide-zh.md index 25b97bb..62c0591 100644 --- a/src/content/posts/guides/Theme Guide-zh.md +++ b/src/content/posts/guides/Theme Guide-zh.md @@ -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