fossbook 0.0.4 → 0.0.6
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 +246 -246
- package/bin/fossbook.js +120 -119
- package/lib/all_posts.js +33 -32
- package/lib/assets/placeholder.svg +3 -3
- package/lib/deploy.js +257 -237
- package/lib/home.js +60 -59
- package/lib/index.js +79 -79
- package/lib/init.js +311 -253
- package/lib/mod/config.js +136 -136
- package/lib/mod/marked.js +95 -95
- package/lib/mod/page.js +119 -115
- package/lib/mod/page_base.js +97 -97
- package/lib/new.js +48 -48
- package/lib/posts.js +47 -42
- package/lib/server.js +20 -14
- package/lib/tag/index.js +70 -69
- package/lib/tag/tag.js +30 -29
- package/package.json +45 -45
- package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.svg +330 -330
- package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.svg +365 -365
- package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.svg +405 -405
- package/themes/archie/assets/styles/fonts.css +51 -51
- package/themes/archie/assets/styles/highlights.css +75 -75
- package/themes/archie/assets/styles/main.css +402 -402
- package/themes/archie/layouts/all_posts.html +41 -41
- package/themes/archie/layouts/home.html +61 -61
- package/themes/archie/layouts/page.html +50 -50
- package/themes/archie/layouts/partials/footer.html +9 -9
- package/themes/archie/layouts/post.html +81 -81
- package/themes/archie/layouts/tag.html +42 -42
- package/themes/archie/layouts/tag_list.html +43 -43
package/lib/deploy.js
CHANGED
|
@@ -1,237 +1,257 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { execSync, exec } = require("child_process");
|
|
4
|
-
const { build } = require("./index");
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Deploy the blog: build → commit → push → poll CI → show URL.
|
|
8
|
-
*/
|
|
9
|
-
async function deploy(config, options = {}) {
|
|
10
|
-
const cwd = process.cwd();
|
|
11
|
-
const deployConfig = config.deploy || {};
|
|
12
|
-
const branch = deployConfig.branch || "main";
|
|
13
|
-
const remote = deployConfig.remote || "origin";
|
|
14
|
-
|
|
15
|
-
// 1. Build the site
|
|
16
|
-
console.log("Building site...");
|
|
17
|
-
build(config);
|
|
18
|
-
console.log("Build complete.\n");
|
|
19
|
-
|
|
20
|
-
// 2. Check git is initialized
|
|
21
|
-
if (!fs.existsSync(path.join(cwd, ".git"))) {
|
|
22
|
-
console.error("Error: Not a git repository. Run 'fossbook init --github' first.");
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 3. Stage all changes
|
|
27
|
-
execSync("git add -A", { cwd, stdio: "inherit" });
|
|
28
|
-
|
|
29
|
-
// 4. Check if there are changes to commit
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
console.log(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
execSync("gh
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { execSync, exec } = require("child_process");
|
|
4
|
+
const { build } = require("./index");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Deploy the blog: build → commit → push → poll CI → show URL.
|
|
8
|
+
*/
|
|
9
|
+
async function deploy(config, options = {}) {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const deployConfig = config.deploy || {};
|
|
12
|
+
const branch = deployConfig.branch || "main";
|
|
13
|
+
const remote = deployConfig.remote || "origin";
|
|
14
|
+
|
|
15
|
+
// 1. Build the site
|
|
16
|
+
console.log("Building site...");
|
|
17
|
+
build(config);
|
|
18
|
+
console.log("Build complete.\n");
|
|
19
|
+
|
|
20
|
+
// 2. Check git is initialized
|
|
21
|
+
if (!fs.existsSync(path.join(cwd, ".git"))) {
|
|
22
|
+
console.error("Error: Not a git repository. Run 'fossbook init --github' first.");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 3. Stage all changes
|
|
27
|
+
execSync("git add -A", { cwd, stdio: "inherit" });
|
|
28
|
+
|
|
29
|
+
// 4. Check if there are changes to commit
|
|
30
|
+
let hasChanges = false;
|
|
31
|
+
try {
|
|
32
|
+
execSync("git diff --cached --quiet", { cwd });
|
|
33
|
+
} catch {
|
|
34
|
+
hasChanges = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!hasChanges) {
|
|
38
|
+
// Check if there are unpushed commits
|
|
39
|
+
const remote = deployConfig.remote || "origin";
|
|
40
|
+
try {
|
|
41
|
+
const unpushed = execSync(`git log ${remote}/${branch}..HEAD --oneline`, {
|
|
42
|
+
cwd,
|
|
43
|
+
encoding: "utf-8",
|
|
44
|
+
}).trim();
|
|
45
|
+
if (!unpushed) {
|
|
46
|
+
console.log("No changes to commit and no unpushed commits.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
console.log("No new changes to commit, but found unpushed commits. Pushing...");
|
|
50
|
+
} catch {
|
|
51
|
+
// Remote branch may not exist yet — continue to push
|
|
52
|
+
console.log("No changes to commit. Pushing to create remote branch...");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 5. Determine commit message
|
|
57
|
+
let commitMessage = options.message;
|
|
58
|
+
if (!commitMessage) {
|
|
59
|
+
commitMessage = detectNewPost(config) || "Update blog";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 6. Commit (only if there are staged changes)
|
|
63
|
+
if (hasChanges) {
|
|
64
|
+
console.log(`Committing: "${commitMessage}"`);
|
|
65
|
+
execSync(`git commit -m "${commitMessage.replace(/"/g, '\\"')}"`, {
|
|
66
|
+
cwd,
|
|
67
|
+
stdio: "inherit",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 7. If --draft, stop here
|
|
72
|
+
if (options.draft) {
|
|
73
|
+
console.log("\nDraft committed locally. Run 'fossbook deploy' again to push.");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 8. Ensure GitHub Pages is enabled (source: GitHub Actions)
|
|
78
|
+
ensureGitHubPages(cwd);
|
|
79
|
+
|
|
80
|
+
// 9. Push
|
|
81
|
+
console.log(`\nPushing to ${remote}/${branch}...`);
|
|
82
|
+
try {
|
|
83
|
+
execSync(`git push ${remote} ${branch}`, { cwd, stdio: "inherit" });
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error(`Error: Failed to push to ${remote}/${branch}.`);
|
|
86
|
+
console.error("Make sure the remote exists and you have push access.");
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 10. Wait for CI/CD and show URL
|
|
91
|
+
if (options.noWait) {
|
|
92
|
+
console.log("\nPushed! Skipping CI/CD status check (--no-wait).");
|
|
93
|
+
printSiteUrl(config);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
await waitForDeployment(cwd, config);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Detect if a new post was added and return a commit message.
|
|
102
|
+
*/
|
|
103
|
+
function detectNewPost(config) {
|
|
104
|
+
try {
|
|
105
|
+
const diffOutput = execSync("git diff --cached --name-only", {
|
|
106
|
+
encoding: "utf-8",
|
|
107
|
+
});
|
|
108
|
+
const postsDir = config.postsDir || "./content/posts";
|
|
109
|
+
const newPosts = diffOutput
|
|
110
|
+
.split("\n")
|
|
111
|
+
.filter((f) => f.startsWith(postsDir.replace("./", "")) && f.endsWith("index.md"))
|
|
112
|
+
.map((f) => {
|
|
113
|
+
// Extract post title from path like "content/posts/My Post/index.md"
|
|
114
|
+
const parts = f.split(/[\/\\]/);
|
|
115
|
+
return parts[parts.length - 2];
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (newPosts.length === 1) {
|
|
119
|
+
return `Publish: ${newPosts[0]}`;
|
|
120
|
+
} else if (newPosts.length > 1) {
|
|
121
|
+
return `Publish ${newPosts.length} new posts`;
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// Fall through
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Wait for GitHub Actions deployment to complete, then show the URL.
|
|
131
|
+
*/
|
|
132
|
+
async function waitForDeployment(cwd, config) {
|
|
133
|
+
// Check if gh is available
|
|
134
|
+
const hasGh = isGhAvailable();
|
|
135
|
+
|
|
136
|
+
if (!hasGh) {
|
|
137
|
+
console.log("\nGitHub CLI (gh) not found. Cannot monitor deployment status.");
|
|
138
|
+
console.log("Install it to see live deployment progress: https://cli.github.com/");
|
|
139
|
+
printSiteUrl(config);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log("\nWaiting for GitHub Pages deployment...");
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
// Wait a moment for the workflow to be triggered
|
|
147
|
+
await sleep(3000);
|
|
148
|
+
|
|
149
|
+
// Get the latest workflow run
|
|
150
|
+
const runJson = execSync(
|
|
151
|
+
'gh run list --workflow=deploy.yml --limit=1 --json databaseId,status,conclusion',
|
|
152
|
+
{ cwd, encoding: "utf-8" }
|
|
153
|
+
);
|
|
154
|
+
const runs = JSON.parse(runJson);
|
|
155
|
+
|
|
156
|
+
if (runs.length === 0) {
|
|
157
|
+
console.log("No workflow runs found. The deployment may not be configured yet.");
|
|
158
|
+
console.log("Enable GitHub Pages: Settings → Pages → Source → GitHub Actions");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const runId = runs[0].databaseId;
|
|
163
|
+
|
|
164
|
+
// Watch the run
|
|
165
|
+
console.log(`Monitoring workflow run #${runId}...`);
|
|
166
|
+
execSync(`gh run watch ${runId}`, { cwd, stdio: "inherit" });
|
|
167
|
+
|
|
168
|
+
// Check result
|
|
169
|
+
const resultJson = execSync(
|
|
170
|
+
`gh run view ${runId} --json conclusion`,
|
|
171
|
+
{ cwd, encoding: "utf-8" }
|
|
172
|
+
);
|
|
173
|
+
const result = JSON.parse(resultJson);
|
|
174
|
+
|
|
175
|
+
if (result.conclusion === "success") {
|
|
176
|
+
console.log("\n✅ Deployment successful!");
|
|
177
|
+
printSiteUrl(config);
|
|
178
|
+
} else {
|
|
179
|
+
console.error(`\n❌ Deployment failed (conclusion: ${result.conclusion}).`);
|
|
180
|
+
console.log(`View details: gh run view ${runId} --log`);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
} catch (e) {
|
|
184
|
+
console.warn("\nCould not monitor deployment status.");
|
|
185
|
+
console.log("Check your deployment at: https://github.com → Actions tab");
|
|
186
|
+
printSiteUrl(config);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Print the site URL based on config.
|
|
192
|
+
*/
|
|
193
|
+
function printSiteUrl(config) {
|
|
194
|
+
const siteUrl = config.blogsite || config.githubCNAME;
|
|
195
|
+
if (siteUrl && siteUrl !== "http://localhost:3000") {
|
|
196
|
+
console.log(`\nView your site at: ${siteUrl}`);
|
|
197
|
+
} else {
|
|
198
|
+
// Try to infer from git remote
|
|
199
|
+
try {
|
|
200
|
+
const remoteUrl = execSync("git remote get-url origin", { encoding: "utf-8" }).trim();
|
|
201
|
+
const match = remoteUrl.match(/github\.com[:/](.+?)(?:\.git)?$/);
|
|
202
|
+
if (match) {
|
|
203
|
+
const [owner, repo] = match[1].split("/");
|
|
204
|
+
console.log(`\nView your site at: https://${owner}.github.io/${repo}/`);
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
console.log("\nYour site will be available on GitHub Pages once deployment completes.");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function isGhAvailable() {
|
|
213
|
+
try {
|
|
214
|
+
execSync("gh --version", { stdio: "ignore" });
|
|
215
|
+
return true;
|
|
216
|
+
} catch {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function sleep(ms) {
|
|
222
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Ensure GitHub Pages is enabled with "GitHub Actions" as the build source.
|
|
227
|
+
* Uses the GitHub CLI (gh) to check and create the Pages site if needed.
|
|
228
|
+
*/
|
|
229
|
+
function ensureGitHubPages(cwd) {
|
|
230
|
+
if (!isGhAvailable()) return;
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
// Try to get the current Pages config
|
|
234
|
+
execSync("gh api repos/{owner}/{repo}/pages", {
|
|
235
|
+
cwd,
|
|
236
|
+
stdio: "ignore",
|
|
237
|
+
});
|
|
238
|
+
// Pages already enabled — nothing to do
|
|
239
|
+
} catch {
|
|
240
|
+
// Pages not enabled — try to create it with GitHub Actions source
|
|
241
|
+
try {
|
|
242
|
+
console.log("Enabling GitHub Pages (source: GitHub Actions)...");
|
|
243
|
+
execSync(
|
|
244
|
+
'gh api repos/{owner}/{repo}/pages -X POST -f build_type=workflow',
|
|
245
|
+
{ cwd, stdio: "ignore" }
|
|
246
|
+
);
|
|
247
|
+
console.log("GitHub Pages enabled successfully.");
|
|
248
|
+
} catch (e) {
|
|
249
|
+
console.warn(
|
|
250
|
+
"Warning: Could not auto-enable GitHub Pages.\n" +
|
|
251
|
+
"Please enable it manually: Settings → Pages → Source → GitHub Actions"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
module.exports = { deploy };
|
package/lib/home.js
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const PageBase = require("./mod/page_base");
|
|
4
|
-
|
|
5
|
-
module.exports = class Pagination extends PageBase {
|
|
6
|
-
constructor(config) {
|
|
7
|
-
super(config);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
generateContent(posts) {
|
|
11
|
-
const postsPerPage = 5;
|
|
12
|
-
const numPages = Math.ceil(posts.length / postsPerPage);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const PageBase = require("./mod/page_base");
|
|
4
|
+
|
|
5
|
+
module.exports = class Pagination extends PageBase {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
generateContent(posts) {
|
|
11
|
+
const postsPerPage = 5;
|
|
12
|
+
const numPages = Math.ceil(posts.length / postsPerPage);
|
|
13
|
+
|
|
14
|
+
const pageDir = path.join(this.config.dev.outdir, "page");
|
|
15
|
+
if (fs.existsSync(pageDir))
|
|
16
|
+
fs.rmSync(pageDir, { recursive: true });
|
|
17
|
+
|
|
18
|
+
fs.mkdirSync(pageDir);
|
|
19
|
+
|
|
20
|
+
// copy content/page/1.html to outdir/page/1.html
|
|
21
|
+
const contentPagePath = path.join(this.config.dev.content, "page", "1.html");
|
|
22
|
+
if (fs.existsSync(contentPagePath))
|
|
23
|
+
fs.copyFileSync(
|
|
24
|
+
contentPagePath,
|
|
25
|
+
path.join(pageDir, "1.html"),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < numPages; i++) {
|
|
29
|
+
const pagePosts = posts.slice(i * postsPerPage, (i + 1) * postsPerPage);
|
|
30
|
+
|
|
31
|
+
let filePath;
|
|
32
|
+
let url;
|
|
33
|
+
if (i === 0) {
|
|
34
|
+
filePath = path.join(this.config.dev.outdir, "index.html");
|
|
35
|
+
url = this.config.blogsite;
|
|
36
|
+
} else {
|
|
37
|
+
filePath = path.join(pageDir, `${i + 1}.html`);
|
|
38
|
+
url = `${this.config.blogsite}/page/${i + 1}.html`;
|
|
39
|
+
}
|
|
40
|
+
const prev = i - 1 >= 0 ? i : null;
|
|
41
|
+
const next = i + 1 < numPages ? i + 2 : null;
|
|
42
|
+
|
|
43
|
+
console.log("prev", prev, "next", next);
|
|
44
|
+
this.url = url;
|
|
45
|
+
this.title = `${this.config.blogName}`;
|
|
46
|
+
this.imageURL = this.config.image;
|
|
47
|
+
const data = { posts: pagePosts, prev: prev, next: next };
|
|
48
|
+
|
|
49
|
+
const templatePath = path.join(this.config.themePath, "layouts", "home.html");
|
|
50
|
+
fs.writeFile(
|
|
51
|
+
`${filePath}`,
|
|
52
|
+
this.generateHTML(templatePath, data),
|
|
53
|
+
(e) => {
|
|
54
|
+
if (e) throw e;
|
|
55
|
+
console.log(`page/${i + 1}.html was created successfully`);
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|