mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-15 03:02:53 +02:00
✨ feat: add format-posts srcipt
This commit is contained in:
parent
4d1e5b3054
commit
5ec894cd36
20 changed files with 232 additions and 89 deletions
|
@ -12,6 +12,7 @@
|
|||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"new-post": "esno scripts/new-post.ts",
|
||||
"format-posts": "esno scripts/format-posts.ts",
|
||||
"update-theme": "esno scripts/update-theme.ts",
|
||||
"update-vendors": "curl -L https://unpkg.com/@waline/client@latest/dist/waline.css -o public/vendors/waline/waline.css && curl -L https://unpkg.com/@waline/client@latest/dist/waline.js -o public/vendors/waline/waline.js"
|
||||
},
|
||||
|
@ -53,9 +54,11 @@
|
|||
"@unocss/preset-attributify": "66.1.3",
|
||||
"@unocss/reset": "66.1.3",
|
||||
"astro-eslint-parser": "^1.2.2",
|
||||
"autocorrect-node": "^2.14.0",
|
||||
"eslint": "^9.28.0",
|
||||
"eslint-plugin-astro": "^1.3.1",
|
||||
"esno": "^4.8.0",
|
||||
"fast-glob": "^3.3.2",
|
||||
"lint-staged": "^16.1.0",
|
||||
"typescript": "~5.8.3",
|
||||
"unocss": "66.1.3",
|
||||
|
|
64
pnpm-lock.yaml
generated
64
pnpm-lock.yaml
generated
|
@ -114,6 +114,9 @@ importers:
|
|||
astro-eslint-parser:
|
||||
specifier: ^1.2.2
|
||||
version: 1.2.2
|
||||
autocorrect-node:
|
||||
specifier: ^2.14.0
|
||||
version: 2.14.0
|
||||
eslint:
|
||||
specifier: ^9.28.0
|
||||
version: 9.28.0(jiti@2.4.2)
|
||||
|
@ -123,6 +126,9 @@ importers:
|
|||
esno:
|
||||
specifier: ^4.8.0
|
||||
version: 4.8.0
|
||||
fast-glob:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.3
|
||||
lint-staged:
|
||||
specifier: ^16.1.0
|
||||
version: 16.1.0
|
||||
|
@ -1499,6 +1505,41 @@ packages:
|
|||
peerDependencies:
|
||||
'@astrojs/compiler': '>=0.27.0'
|
||||
|
||||
autocorrect-node-darwin-arm64@2.14.0:
|
||||
resolution: {integrity: sha512-l5IRTQz6zYAlkfEc5emIDXBkayD0MIwPPAVXCFMceFwyTNhAJ5veoKqRrsPuBVthIbfYKtAUs9oy9oFoHQn7bw==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
autocorrect-node-darwin-x64@2.14.0:
|
||||
resolution: {integrity: sha512-vRO0lwfXff2Fs41NzdDqN5t4VQ03M0Xsn6Tk4OjMrbjoWJqaEq05KZOTSaSF/wEs/7E1VoaI9Kz+c0fqylVX4Q==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
autocorrect-node-linux-x64-gnu@2.14.0:
|
||||
resolution: {integrity: sha512-v1y1wh340cbhrHSZZP0oPkvWUprDtUIwnBP69Bls27VhQ2ZyVV4eijDNOP//yGUyUunMB0rtWoZaBsq8ugt1Kg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
autocorrect-node-linux-x64-musl@2.14.0:
|
||||
resolution: {integrity: sha512-3LifiLG61VIXBrOITpD/REcg/ZEUuLz/P2XUWMCfGqhzoUb8oFgM3o0A6extvIH2NefiHMndB9kNbfQjXCl3zA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
autocorrect-node-win32-x64-msvc@2.14.0:
|
||||
resolution: {integrity: sha512-OM6TeGUW0+4R9KtUYTYNEwlInd+b2kumw/B1HCbCzb1F7HpfaNxnZiMk1li0bdPPBDzD5YuzwM30VJZMCWIi5A==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
autocorrect-node@2.14.0:
|
||||
resolution: {integrity: sha512-Pkdw3Hr1Wbtpm8f7KYOaPnHFa7TNVo9dyuOffVaNGN3iWWRBs011XBuCJUEmHV097kJkab94cs4P6KJ4pvI41g==}
|
||||
engines: {node: '>= 10'}
|
||||
hasBin: true
|
||||
|
||||
axobject-query@4.1.0:
|
||||
resolution: {integrity: sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
@ -5689,6 +5730,29 @@ snapshots:
|
|||
'@astrojs/compiler': 2.12.0
|
||||
synckit: 0.11.8
|
||||
|
||||
autocorrect-node-darwin-arm64@2.14.0:
|
||||
optional: true
|
||||
|
||||
autocorrect-node-darwin-x64@2.14.0:
|
||||
optional: true
|
||||
|
||||
autocorrect-node-linux-x64-gnu@2.14.0:
|
||||
optional: true
|
||||
|
||||
autocorrect-node-linux-x64-musl@2.14.0:
|
||||
optional: true
|
||||
|
||||
autocorrect-node-win32-x64-msvc@2.14.0:
|
||||
optional: true
|
||||
|
||||
autocorrect-node@2.14.0:
|
||||
optionalDependencies:
|
||||
autocorrect-node-darwin-arm64: 2.14.0
|
||||
autocorrect-node-darwin-x64: 2.14.0
|
||||
autocorrect-node-linux-x64-gnu: 2.14.0
|
||||
autocorrect-node-linux-x64-musl: 2.14.0
|
||||
autocorrect-node-win32-x64-msvc: 2.14.0
|
||||
|
||||
axobject-query@4.1.0: {}
|
||||
|
||||
bail@2.0.2: {}
|
||||
|
|
68
scripts/format-posts.ts
Normal file
68
scripts/format-posts.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Project: https://github.com/huacnlee/autocorrect
|
||||
* Format posts by fixing spaces and punctuations in CJK text
|
||||
* Usage: pnpm format-posts
|
||||
*/
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import process from 'node:process'
|
||||
import { format } from 'autocorrect-node'
|
||||
import fg from 'fast-glob'
|
||||
|
||||
function splitContent(content: string) {
|
||||
const match = content.match(/^---\r?\n([\s\S]+?)\r?\n---\r?\n([\s\S]*)$/m)
|
||||
if (match) {
|
||||
return {
|
||||
frontmatter: match[1],
|
||||
body: match[2],
|
||||
hasFrontmatter: true,
|
||||
}
|
||||
}
|
||||
return {
|
||||
frontmatter: '',
|
||||
body: content,
|
||||
hasFrontmatter: false,
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const files = await fg(['src/content/**/*.{md,mdx}'])
|
||||
console.log(`🔍 ${files.length} Markdown files found`)
|
||||
|
||||
let changedCount = 0
|
||||
let errorCount = 0
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
const content = await readFile(file, 'utf8')
|
||||
const { frontmatter, body, hasFrontmatter } = splitContent(content)
|
||||
|
||||
const formattedBody = format(body)
|
||||
const newContent = hasFrontmatter
|
||||
? `---\n${frontmatter}\n---\n${formattedBody}`
|
||||
: formattedBody
|
||||
|
||||
if (content !== newContent) {
|
||||
await writeFile(file, newContent, 'utf8')
|
||||
console.log(`✅ ${file}`)
|
||||
changedCount++
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`❌ ${file}: ${error instanceof Error ? error.message : error}`)
|
||||
errorCount++
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n${changedCount > 0
|
||||
? `✨ Formatted ${changedCount} files successfully`
|
||||
: `✅ Check complete, no files needed formatting changes`}`)
|
||||
|
||||
if (errorCount > 0) {
|
||||
console.log(`⚠️ ${errorCount} files failed to format`)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error('❌ Execution failed:', error)
|
||||
process.exit(1)
|
||||
})
|
|
@ -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)$/, '')
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* Update theme from upstream repository
|
||||
* Usage: pnpm update-theme
|
||||
*/
|
||||
import { execSync } from 'node:child_process'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
|
|
@ -98,7 +98,7 @@ i18n 对我来说是必需的。因为我之前发过一篇英文的 [三星优
|
|||
|
||||
三是因为 Webkit。我有 Macbook Pro、三星 S23U、iPad Mini 6 和 iPhone15 Pro 这几台设备。每次网站部署之后,我都会在这几台设备上进行测试。
|
||||
|
||||
iPhone 上总是会出现一些奇怪的 BUG,例如切换页面时背景会闪烁? View Transition 期间字体会被裁切?图标的水平位置跟标题对不齐?换了几个浏览器都是这样,后来才知道是 iOS 上的 Webkit 浏览器引擎的锅。
|
||||
iPhone 上总是会出现一些奇怪的 BUG,例如切换页面时背景会闪烁?View Transition 期间字体会被裁切?图标的水平位置跟标题对不齐?换了几个浏览器都是这样,后来才知道是 iOS 上的 Webkit 浏览器引擎的锅。
|
||||
|
||||
以下图片均为慢动作拍摄。
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ site: {
|
|||
// サイト URL
|
||||
url: 'https://retypeset.radishzz.cc'
|
||||
// ファビコン URL
|
||||
// 推奨フォーマット: svg, png, ico
|
||||
// 推奨フォーマット:svg, png, ico
|
||||
favicon: '/icons/favicon.svg' // または https://example.com/favicon.svg
|
||||
}
|
||||
```
|
||||
|
@ -119,7 +119,7 @@ comment: {
|
|||
emoji: [
|
||||
'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji'
|
||||
// 'https://unpkg.com/@waline/emojis@1.2.0/bmoji'
|
||||
// その他の絵文字: https://waline.js.org/en/guide/features/emoji.html
|
||||
// その他の絵文字:https://waline.js.org/en/guide/features/emoji.html
|
||||
]
|
||||
// gif 検索
|
||||
search: false // true, false
|
||||
|
@ -159,7 +159,7 @@ seo: {
|
|||
}
|
||||
// APIFlash アクセスキー
|
||||
// OpenGraph 用のウェブサイトスクリーンショットを自動生成
|
||||
// アクセスキーの取得: https://apiflash.com/
|
||||
// アクセスキーの取得:https://apiflash.com/
|
||||
apiflashKey: ''
|
||||
}
|
||||
```
|
||||
|
@ -222,7 +222,7 @@ preload: {
|
|||
// astro.config.ts
|
||||
|
||||
shikiConfig: {
|
||||
// 利用可能なテーマ: https://shiki.style/themes
|
||||
// 利用可能なテーマ:https://shiki.style/themes
|
||||
// 背景色はデフォルトでシンタックスハイライトテーマではなく、ブログテーマに従います
|
||||
themes: {
|
||||
light: 'github-light' // ライトテーマ
|
||||
|
@ -274,7 +274,7 @@ getImageOptions: (_path, page) => ({
|
|||
'https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@main/Sans/SubsetOTF/SC/NotoSansSC-Regular.otf',
|
||||
],
|
||||
bgGradient: [[242, 241, 245]], // 背景色
|
||||
// その他の設定: https://github.com/delucis/astro-og-canvas/tree/latest/packages/astro-og-canvas
|
||||
// その他の設定:https://github.com/delucis/astro-og-canvas/tree/latest/packages/astro-og-canvas
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ site: {
|
|||
// 站點地址
|
||||
url: 'https://retypeset.radishzz.cc'
|
||||
// 站點圖標
|
||||
// 推薦格式: svg, png, ico
|
||||
// 推薦格式:svg, png, ico
|
||||
favicon: '/icons/favicon.svg' // 或 https://example.com/favicon.svg
|
||||
}
|
||||
```
|
||||
|
@ -119,7 +119,7 @@ comment: {
|
|||
emoji: [
|
||||
'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji'
|
||||
// 'https://unpkg.com/@waline/emojis@1.2.0/bmoji'
|
||||
// 更多表情: https://waline.js.org/en/guide/features/emoji.html
|
||||
// 更多表情:https://waline.js.org/en/guide/features/emoji.html
|
||||
]
|
||||
// gif 搜索
|
||||
search: false // true, false
|
||||
|
@ -159,7 +159,7 @@ seo: {
|
|||
}
|
||||
// apiflash access key 訪問密鑰
|
||||
// 自動生成網站截圖用於 open graph
|
||||
// 獲取訪問密鑰: https://apiflash.com/
|
||||
// 獲取訪問密鑰:https://apiflash.com/
|
||||
apiflashKey: ''
|
||||
}
|
||||
```
|
||||
|
|
|
@ -33,7 +33,7 @@ site: {
|
|||
// 站点地址
|
||||
url: 'https://retypeset.radishzz.cc'
|
||||
// 站点图标
|
||||
// 推荐格式: svg, png, ico
|
||||
// 推荐格式:svg, png, ico
|
||||
favicon: '/icons/favicon.svg' // 或 https://example.com/favicon.svg
|
||||
}
|
||||
```
|
||||
|
@ -119,7 +119,7 @@ comment: {
|
|||
emoji: [
|
||||
'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji'
|
||||
// 'https://unpkg.com/@waline/emojis@1.2.0/bmoji'
|
||||
// 更多表情: https://waline.js.org/en/guide/features/emoji.html
|
||||
// 更多表情:https://waline.js.org/en/guide/features/emoji.html
|
||||
]
|
||||
// gif 搜索
|
||||
search: false // true, false
|
||||
|
@ -159,7 +159,7 @@ seo: {
|
|||
}
|
||||
// apiflash access key 访问密钥
|
||||
// 自动生成网站截图用于 open graph
|
||||
// 获取访问密钥: https://apiflash.com/
|
||||
// 获取访问密钥:https://apiflash.com/
|
||||
apiflashKey: ''
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue