-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
556953a
commit a9abe71
Showing
6 changed files
with
216 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"text": "2023-11-08<br>Oxlint General Availability", | ||
"link": "/blog/2023-11-08-announcing-oxlint" | ||
}, | ||
{ | ||
"text": "2023-11-07<br>Announcing Oxc", | ||
"link": "/blog/2023-11-07-announcing-oxc" | ||
}, | ||
{ | ||
"text": "2022-08-08<br>A research on JavaScript linters", | ||
"link": "/blog/2022-08-08-linter-research" | ||
}, | ||
{ | ||
"text": "2022-02-10<br>High Performance JavaScript Toolchain", | ||
"link": "/blog/2022-02-10-js-tooling-research" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import * as fs from "node:fs/promises"; | ||
import { defineCommand } from "citty"; | ||
import consola from "consola"; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: "create-blog-post", | ||
description: "create blog post", | ||
}, | ||
args: { | ||
date: { | ||
type: "positional", | ||
description: "publish date of the post", | ||
required: true, | ||
}, | ||
title: { | ||
type: "positional", | ||
description: "title of the post", | ||
required: true, | ||
}, | ||
slug: { | ||
type: "string", | ||
description: "slug of the post", | ||
required: false, | ||
}, | ||
author: { | ||
type: "string", | ||
description: "author ID of the post", | ||
required: false, | ||
}, | ||
}, | ||
async run({ args }) { | ||
const { date, title, slug, author } = args; | ||
const isValidDate = | ||
/^(?:20\d{2})\-(?:0?[1-9]|1[012])\-(?:0?[1-9]|1\d|2\d|3[0-1])$/.test( | ||
date, | ||
); | ||
|
||
if (!isValidDate) { | ||
consola.error(`date is invalid: ${date}`); | ||
} | ||
|
||
await writeMarkdownFile({ date, title, slug, author }); | ||
await writeSidebarFile({ date, title, slug }); | ||
|
||
consola.success(`blog post created`); | ||
}, | ||
}); | ||
|
||
async function writeMarkdownFile({ | ||
date, | ||
title, | ||
slug, | ||
author, | ||
}: { | ||
date: string; | ||
title: string; | ||
slug: string; | ||
author: string; | ||
}) { | ||
const filePath = `${process.cwd()}/src${getBlogPostUrl({ | ||
date, | ||
title, | ||
slug, | ||
})}.md`; | ||
const content = ` | ||
--- | ||
title: ${title} | ||
outline: deep | ||
authors: | ||
- ${author || "# TODO: add author ID"} | ||
--- | ||
<AppBlogPostHeader /> | ||
`.trimStart(); | ||
|
||
await fs.writeFile(filePath, content); | ||
} | ||
|
||
async function writeSidebarFile({ | ||
date, | ||
title, | ||
slug, | ||
}: { | ||
date: string; | ||
title: string; | ||
slug: string; | ||
}) { | ||
const filePath = `${process.cwd()}/.vitepress/sidebar.blog.json`; | ||
const currentSidebar = await fs.readFile(filePath, "utf8"); | ||
const sidebar = JSON.parse(currentSidebar) as Record< | ||
"text" | "link", | ||
string | ||
>[]; | ||
|
||
sidebar.unshift({ | ||
text: `${date}<br>${title}`, | ||
link: getBlogPostUrl({ date, title, slug }), | ||
}); | ||
|
||
await fs.writeFile(filePath, JSON.stringify(sidebar, null, 2)); | ||
} | ||
|
||
function getBlogPostUrl({ | ||
date, | ||
title, | ||
slug, | ||
}: { | ||
date: string; | ||
title: string; | ||
slug: string; | ||
}) { | ||
return `/blog/${date}-${(slug || title) | ||
.toLocaleLowerCase() | ||
.replace(/\s+/g, "-")}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { defineCommand, runMain } from "citty"; | ||
import type { CommandDef } from "citty"; | ||
|
||
const _rDefault = (r: any) => (r.default || r) as Promise<CommandDef>; | ||
|
||
const main = defineCommand({ | ||
meta: { | ||
name: "pnpm run cli", | ||
description: "CLI for OXC Documentation", | ||
}, | ||
subCommands: { | ||
"create-blog-post": () => | ||
import("./commands/create-blog-post.mjs").then(_rDefault), | ||
}, | ||
}); | ||
|
||
runMain(main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.