@daz4126/swifty 2.3.0 → 2.4.1
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/init.js +1 -1
- package/src/pages.js +1 -1
- package/src/watcher.js +42 -35
package/package.json
CHANGED
package/src/init.js
CHANGED
|
@@ -42,7 +42,7 @@ dateFormat:
|
|
|
42
42
|
<link rel="apple-touch-icon" href="path/to/apple-touch-icon.png">
|
|
43
43
|
<link rel="icon" sizes="192x192" href="android-chrome-192x19.png">
|
|
44
44
|
<link rel="icon" sizes="512x512" href="android-chrome-512x512.png">
|
|
45
|
-
<title>{{sitename}}</title>
|
|
45
|
+
<title>{{ sitename }} || {{ title }}</title>
|
|
46
46
|
</head>
|
|
47
47
|
<body>
|
|
48
48
|
<header>
|
package/src/pages.js
CHANGED
|
@@ -177,7 +177,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
177
177
|
const generateLinkList = async (name, pages) => {
|
|
178
178
|
const partial = `${name}.md`;
|
|
179
179
|
const partialPath = path.join(dirs.partials, partial);
|
|
180
|
-
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name);
|
|
180
|
+
const linksPath = path.join(dirs.partials, defaultConfig.default_link_name || "links");
|
|
181
181
|
// Check if either file exists in the 'partials' folder
|
|
182
182
|
const fileExists = await fsExtra.pathExists(partialPath);
|
|
183
183
|
const defaultExists = await fsExtra.pathExists(linksPath);
|
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...");
|