@daz4126/swifty 2.3.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 +17 -1
- 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,
|
|
@@ -177,7 +182,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
177
182
|
const generateLinkList = async (name, pages) => {
|
|
178
183
|
const partial = `${name}.md`;
|
|
179
184
|
const partialPath = path.join(dirs.partials, partial);
|
|
180
|
-
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name);
|
|
185
|
+
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name || "links");
|
|
181
186
|
// Check if either file exists in the 'partials' folder
|
|
182
187
|
const fileExists = await fsExtra.pathExists(partialPath);
|
|
183
188
|
const defaultExists = await fsExtra.pathExists(linksPath);
|
|
@@ -226,6 +231,16 @@ const addLinks = async (pages, parent) => {
|
|
|
226
231
|
for (const page of pages) {
|
|
227
232
|
page.data ||= {};
|
|
228
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
|
+
=======
|
|
229
244
|
? page.data.tags.map(
|
|
230
245
|
(tag) =>
|
|
231
246
|
`<a class="${defaultConfig.tag_class}" href="/tags/${tag}">${tag}</a>`,
|
|
@@ -253,6 +268,7 @@ const addLinks = async (pages, parent) => {
|
|
|
253
268
|
"nav",
|
|
254
269
|
pageIndex.filter((p) => p.nav),
|
|
255
270
|
);
|
|
271
|
+
>>>>>>> 61ad6f94b646a80d5857c84b58250ea7f00f2758
|
|
256
272
|
if (page.pages) {
|
|
257
273
|
await addLinks(page.pages, page); // Recursive call
|
|
258
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...`);
|
|
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...");
|