mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 03:32:51 +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
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue