@guzhongren/sha 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -20
- package/create.mjs +127 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -2,16 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Config-driven Astro blog theme for technical writing. The theme is consumed as an Astro integration and injects default pages, layouts, and styling.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Scaffold a new blog in one command:
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
|
-
pnpm
|
|
10
|
+
pnpm dlx @guzhongren/sha my-blog
|
|
11
|
+
cd my-blog && pnpm dev
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
This creates a complete project with `astro.config.mjs`, content collections bridge, and a sample post.
|
|
15
|
+
|
|
16
|
+
## Manual Setup
|
|
17
|
+
|
|
18
|
+
If you prefer to set up manually or add the theme to an existing Astro project:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add @guzhongren/sha astro @astrojs/mdx @astrojs/markdown-remark tailwindcss @tailwindcss/vite
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### astro.config.mjs
|
|
12
25
|
|
|
13
26
|
```js
|
|
14
|
-
// astro.config.mjs
|
|
15
27
|
import { defineConfig } from "astro/config";
|
|
16
28
|
import mdx from "@astrojs/mdx";
|
|
17
29
|
import tailwindcss from "@tailwindcss/vite";
|
|
@@ -22,21 +34,13 @@ export default defineConfig({
|
|
|
22
34
|
integrations: [
|
|
23
35
|
blogTheme({
|
|
24
36
|
site: {
|
|
25
|
-
name: "
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
name: "My Blog",
|
|
38
|
+
title: "My Blog",
|
|
39
|
+
description: "A blog powered by @guzhongren/sha",
|
|
40
|
+
lang: "en",
|
|
28
41
|
},
|
|
29
42
|
author: {
|
|
30
|
-
name: "
|
|
31
|
-
headline: "全栈开发者 / 技术顾问",
|
|
32
|
-
bio: "写工程实践、架构思考、开源与日常观察。",
|
|
33
|
-
avatar: "/avatar.svg",
|
|
34
|
-
},
|
|
35
|
-
diagrams: {
|
|
36
|
-
mermaid: true,
|
|
37
|
-
plantuml: {
|
|
38
|
-
serverUrl: "https://www.plantuml.com/plantuml/svg",
|
|
39
|
-
},
|
|
43
|
+
name: "Author",
|
|
40
44
|
},
|
|
41
45
|
}),
|
|
42
46
|
mdx(),
|
|
@@ -49,9 +53,7 @@ export default defineConfig({
|
|
|
49
53
|
|
|
50
54
|
Register `blogTheme(...)` before `mdx()` when using theme shortcodes such as ECharts. The theme pre-processes content before MDX parses it.
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Astro requires the app to export content collections:
|
|
56
|
+
### Content collections bridge
|
|
55
57
|
|
|
56
58
|
```ts
|
|
57
59
|
// src/content.config.ts
|
package/create.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const name = process.argv[2];
|
|
7
|
+
if (!name) {
|
|
8
|
+
console.error("Usage: pnpm dlx @guzhongren/sha <project-dir>");
|
|
9
|
+
console.error(" node create.mjs <project-dir>");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const root = join(process.cwd(), name);
|
|
14
|
+
|
|
15
|
+
// Dir tree
|
|
16
|
+
mkdirSync(join(root, "src", "content", "posts"), { recursive: true });
|
|
17
|
+
|
|
18
|
+
// package.json
|
|
19
|
+
writeFileSync(
|
|
20
|
+
join(root, "package.json"),
|
|
21
|
+
JSON.stringify(
|
|
22
|
+
{
|
|
23
|
+
name: name,
|
|
24
|
+
version: "0.0.1",
|
|
25
|
+
type: "module",
|
|
26
|
+
private: true,
|
|
27
|
+
scripts: {
|
|
28
|
+
dev: "astro dev",
|
|
29
|
+
sync: "astro sync",
|
|
30
|
+
build: "astro build",
|
|
31
|
+
preview: "astro preview",
|
|
32
|
+
},
|
|
33
|
+
dependencies: {
|
|
34
|
+
"@astrojs/markdown-remark": "^7.0.0",
|
|
35
|
+
"@astrojs/mdx": "^7.0.5",
|
|
36
|
+
"@guzhongren/sha": "^0.1.1",
|
|
37
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
38
|
+
astro: "^7.1.6",
|
|
39
|
+
tailwindcss: "^4.3.3",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
null,
|
|
43
|
+
2,
|
|
44
|
+
) + "\n",
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// astro.config.mjs
|
|
48
|
+
writeFileSync(
|
|
49
|
+
join(root, "astro.config.mjs"),
|
|
50
|
+
`import { defineConfig } from "astro/config";
|
|
51
|
+
import mdx from "@astrojs/mdx";
|
|
52
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
53
|
+
import blogTheme from "@guzhongren/sha";
|
|
54
|
+
|
|
55
|
+
export default defineConfig({
|
|
56
|
+
site: "https://example.com",
|
|
57
|
+
integrations: [
|
|
58
|
+
blogTheme({
|
|
59
|
+
site: {
|
|
60
|
+
name: "My Blog",
|
|
61
|
+
title: "My Blog",
|
|
62
|
+
description: "A blog powered by @guzhongren/sha",
|
|
63
|
+
lang: "en",
|
|
64
|
+
},
|
|
65
|
+
author: {
|
|
66
|
+
name: "Author",
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
mdx(),
|
|
70
|
+
],
|
|
71
|
+
vite: {
|
|
72
|
+
plugins: [tailwindcss()],
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
`,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// src/content.config.ts
|
|
79
|
+
writeFileSync(
|
|
80
|
+
join(root, "src", "content.config.ts"),
|
|
81
|
+
`export { collections } from "@guzhongren/sha/content";\n`,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// hello-world post
|
|
85
|
+
writeFileSync(
|
|
86
|
+
join(root, "src", "content", "posts", "hello-world.md"),
|
|
87
|
+
`---
|
|
88
|
+
title: "Hello World"
|
|
89
|
+
description: "My first blog post"
|
|
90
|
+
publishDate: ${new Date().toISOString().slice(0, 10)}
|
|
91
|
+
category: "Uncategorized"
|
|
92
|
+
tags: ["hello"]
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
Welcome to my blog! 🎉
|
|
96
|
+
`,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// tsconfig.json
|
|
100
|
+
writeFileSync(
|
|
101
|
+
join(root, "tsconfig.json"),
|
|
102
|
+
`{
|
|
103
|
+
"extends": "astro/tsconfigs/strict"
|
|
104
|
+
}
|
|
105
|
+
`,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// .gitignore
|
|
109
|
+
writeFileSync(join(root, ".gitignore"), "node_modules/\n.astro/\ndist/\n");
|
|
110
|
+
|
|
111
|
+
// pnpm-workspace.yaml (minimumReleaseAgeExclude for fresh packages)
|
|
112
|
+
writeFileSync(
|
|
113
|
+
join(root, "pnpm-workspace.yaml"),
|
|
114
|
+
`allowBuilds:
|
|
115
|
+
esbuild: true
|
|
116
|
+
minimumReleaseAgeExclude:
|
|
117
|
+
- "@guzhongren/sha"
|
|
118
|
+
`,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Install deps
|
|
122
|
+
console.log(`\n✓ Scaffolded "${name}"`);
|
|
123
|
+
console.log("Installing dependencies...\n");
|
|
124
|
+
execSync("pnpm install", { cwd: root, stdio: "inherit" });
|
|
125
|
+
|
|
126
|
+
console.log(`\n✓ Done! Start the dev server:\n`);
|
|
127
|
+
console.log(` cd ${name} && pnpm dev\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guzhongren/sha",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "个人 Astro 博客主题 — 开箱即用的内容驱动博客",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,9 +15,13 @@
|
|
|
15
15
|
],
|
|
16
16
|
"files": [
|
|
17
17
|
"src/",
|
|
18
|
+
"create.mjs",
|
|
18
19
|
"README.md",
|
|
19
20
|
"LICENSE"
|
|
20
21
|
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"create-sha-blog": "./create.mjs"
|
|
24
|
+
},
|
|
21
25
|
"exports": {
|
|
22
26
|
".": "./src/index.ts",
|
|
23
27
|
"./content": "./src/content.ts",
|