feat: add format-posts srcipt

This commit is contained in:
radishzzz 2025-05-31 16:53:20 +01:00
parent 4d1e5b3054
commit 5ec894cd36
20 changed files with 232 additions and 89 deletions

View file

@ -1,16 +1,20 @@
/**
* Create a new post with frontmatter
* Usage: pnpm new-post <title>
*
* Example: pnpm new-post
* Example: pnpm new-post first-post
* Example: pnpm new-post first-post.md
* Example: pnpm new-post first-post.mdx
* Example: pnpm new-post 2025/03/first-post
* Example: pnpm new-post 2025/03/first-post.md
* Example: pnpm new-post 2025/03/first-post.mdx
*/
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/first-post
// pnpm new-post 2025/03/first-post.md
// pnpm new-post 2025/03/first-post.mdx
// Process file path
const rawPath = process.argv[2] || 'new-post'
const baseName = basename(rawPath).replace(/\.(md|mdx)$/, '')