@daz4126/swifty 2.2.0 → 2.4.0
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/package.json +1 -1
- package/src/pages.js +23 -8
- package/src/watcher.js +42 -35
package/package.json
CHANGED
package/src/pages.js
CHANGED
|
@@ -48,6 +48,10 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
48
48
|
: capitalize(file.name.replace(/\.md$/, "").replace(/-/g, " "));
|
|
49
49
|
const stats = await fs.stat(filePath);
|
|
50
50
|
const isDirectory = file.isDirectory();
|
|
51
|
+
<<<<<<< HEAD
|
|
52
|
+
const layoutFileExists = parent && await fsExtra.pathExists(`${dirs.layouts}/${parent.filename}.html`);
|
|
53
|
+
const layout = layoutFileExists ? parent.filename : parent ? parent.layout : config.default_layout_name || "site";
|
|
54
|
+
=======
|
|
51
55
|
const layoutFileExists =
|
|
52
56
|
parent &&
|
|
53
57
|
(await fsExtra.pathExists(`${dirs.layouts}/${parent.filename}.html`));
|
|
@@ -56,6 +60,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
56
60
|
: parent
|
|
57
61
|
? parent.layout
|
|
58
62
|
: config.default_layout_name;
|
|
63
|
+
>>>>>>> 61ad6f94b646a80d5857c84b58250ea7f00f2758
|
|
59
64
|
|
|
60
65
|
const page = {
|
|
61
66
|
name,
|
|
@@ -123,7 +128,9 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
pages.push(page);
|
|
126
|
-
pageIndex.
|
|
131
|
+
if (!pageIndex.some((p) => p.url === page.url)) {
|
|
132
|
+
pageIndex.push({ url: page.url, title: page.title, nav: page.nav });
|
|
133
|
+
}
|
|
127
134
|
});
|
|
128
135
|
|
|
129
136
|
// Await all directory recursion
|
|
@@ -141,7 +148,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
141
148
|
folder: true,
|
|
142
149
|
name: "Tags",
|
|
143
150
|
title: "All Tags",
|
|
144
|
-
layout: "
|
|
151
|
+
layout: tagLayout ? "tags" : defaultConfig.default_layout_name,
|
|
145
152
|
updated_at: new Date().toLocaleDateString(
|
|
146
153
|
undefined,
|
|
147
154
|
defaultConfig.dateFormat,
|
|
@@ -159,16 +166,13 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
159
166
|
defaultConfig.dateFormat,
|
|
160
167
|
),
|
|
161
168
|
url: `/tags/${tag}`,
|
|
162
|
-
layout: tagLayout ? "tags" :
|
|
169
|
+
layout: tagLayout ? "tags" : defaultConfig.default_layout_name,
|
|
163
170
|
data: { ...config, title: `Pages tagged with ${capitalize(tag)}` },
|
|
164
171
|
};
|
|
165
|
-
page.content = pagesForTag
|
|
166
|
-
.map((p) => `* <a href="${p.url}">${p.title}</a>`)
|
|
167
|
-
.join("\n");
|
|
172
|
+
page.content = await generateLinkList("tags", pagesForTag);
|
|
168
173
|
|
|
169
174
|
tagPage.pages.push(page);
|
|
170
175
|
}
|
|
171
|
-
|
|
172
176
|
tagPage.content = await generateLinkList("tags", tagPage.pages);
|
|
173
177
|
pages.push(tagPage);
|
|
174
178
|
}
|
|
@@ -178,7 +182,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
178
182
|
const generateLinkList = async (name, pages) => {
|
|
179
183
|
const partial = `${name}.md`;
|
|
180
184
|
const partialPath = path.join(dirs.partials, partial);
|
|
181
|
-
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name);
|
|
185
|
+
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name || "links");
|
|
182
186
|
// Check if either file exists in the 'partials' folder
|
|
183
187
|
const fileExists = await fsExtra.pathExists(partialPath);
|
|
184
188
|
const defaultExists = await fsExtra.pathExists(linksPath);
|
|
@@ -227,6 +231,16 @@ const addLinks = async (pages, parent) => {
|
|
|
227
231
|
for (const page of pages) {
|
|
228
232
|
page.data ||= {};
|
|
229
233
|
page.data.links_to_tags = page?.data?.tags?.length
|
|
234
|
+
<<<<<<< HEAD
|
|
235
|
+
? page.data.tags.map(tag => `<a class="${defaultConfig.tag_class}" href="/tags/${tag}">${tag}</a>`).join`` : "";
|
|
236
|
+
const crumb = page.root ? "" : ` ${defaultConfig.breadcrumb_separator || "»"} <a class="${defaultConfig.breadcrumb_class}" href="${page.url}">${page.name}</a>`;
|
|
237
|
+
page.data.breadcrumbs = parent ? parent.data.breadcrumbs + crumb
|
|
238
|
+
: `<a class="${defaultConfig.breadcrumb_class}" href="/">Home</a>` + crumb;
|
|
239
|
+
page.data.links_to_children = page.pages ? await generateLinkList(page.filename, page.pages) : "";
|
|
240
|
+
page.data.links_to_siblings = await generateLinkList(page.parent?.filename || "pages", pages.filter(p => p.url !== page.url));
|
|
241
|
+
page.data.links_to_self_and_siblings = await generateLinkList(page.parent?.filename || "pages", pages);
|
|
242
|
+
page.data.nav_links = await generateLinkList("nav", pageIndex.filter(p => p.nav));
|
|
243
|
+
=======
|
|
230
244
|
? page.data.tags.map(
|
|
231
245
|
(tag) =>
|
|
232
246
|
`<a class="${defaultConfig.tag_class}" href="/tags/${tag}">${tag}</a>`,
|
|
@@ -254,6 +268,7 @@ const addLinks = async (pages, parent) => {
|
|
|
254
268
|
"nav",
|
|
255
269
|
pageIndex.filter((p) => p.nav),
|
|
256
270
|
);
|
|
271
|
+
>>>>>>> 61ad6f94b646a80d5857c84b58250ea7f00f2758
|
|
257
272
|
if (page.pages) {
|
|
258
273
|
await addLinks(page.pages, page); // Recursive call
|
|
259
274
|
}
|
package/src/watcher.js
CHANGED
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
import chokidar from "chokidar";
|
|
2
|
+
import { exec } from "child_process";
|
|
3
|
+
import path from "path";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
// Define files to watch, resolving relative to the current working directory
|
|
6
|
+
const filesToWatch = [
|
|
7
|
+
"pages/**/*.{md,html}",
|
|
8
|
+
"layouts/**/*.html",
|
|
9
|
+
"images/**/*",
|
|
10
|
+
"css/**/*.css",
|
|
11
|
+
"js/**/*.js",
|
|
12
|
+
"partials/**/*.{md,html}",
|
|
13
|
+
"template.html",
|
|
14
|
+
"config.yaml",
|
|
15
|
+
"config.yml",
|
|
16
|
+
"config.json",
|
|
17
|
+
].map((pattern) => path.join(process.cwd(), pattern));
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
persistent: true,
|
|
19
|
-
ignoreInitial: true,
|
|
20
|
-
awaitWriteFinish: { stabilityThreshold: 100 },
|
|
21
|
-
debounceDelay: 200,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const buildModule = await import("./build.js");
|
|
25
|
-
const build = buildModule.default;
|
|
19
|
+
const buildScript = "npm run build";
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
// Initialize watcher
|
|
22
|
+
const watcher = chokidar.watch(filesToWatch, {
|
|
23
|
+
persistent: true,
|
|
24
|
+
ignoreInitial: true,
|
|
25
|
+
awaitWriteFinish: {
|
|
26
|
+
stabilityThreshold: 200,
|
|
27
|
+
pollInterval: 100,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// Rebuild function
|
|
32
|
+
function triggerBuild(event, filePath) {
|
|
33
|
+
console.log(`File ${event}: ${filePath}. Running build...`);
|
|
34
|
+
exec(buildScript, (error, stdout, stderr) => {
|
|
35
|
+
if (error) {
|
|
36
|
+
console.error(`Build failed: ${error.message}`);
|
|
37
|
+
return;
|
|
39
38
|
}
|
|
39
|
+
if (stderr) console.error(`stderr: ${stderr}`);
|
|
40
|
+
if (stdout) console.log(stdout);
|
|
40
41
|
});
|
|
41
|
-
|
|
42
|
-
console.log(`👀 Watching for changes in ${outDir}...`);
|
|
43
42
|
}
|
|
43
|
+
|
|
44
|
+
// Set up event listeners
|
|
45
|
+
watcher
|
|
46
|
+
.on("change", (filePath) => triggerBuild("changed", filePath))
|
|
47
|
+
.on("add", (filePath) => triggerBuild("added", filePath))
|
|
48
|
+
.on("unlink", (filePath) => triggerBuild("deleted", filePath));
|
|
49
|
+
|
|
50
|
+
console.log("Watching for file changes...");
|