@daz4126/swifty 2.4.0 → 2.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/swifty",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,6 +25,7 @@
25
25
  "license": "MIT",
26
26
  "description": "Super Speedy Static Site Generator",
27
27
  "dependencies": {
28
+ "chokidar": "^4.0.0",
28
29
  "fs-extra": "^11.2.0",
29
30
  "gray-matter": "^4.0.3",
30
31
  "highlight.js": "^11.11.1",
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
@@ -48,10 +48,6 @@ 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
- =======
55
51
  const layoutFileExists =
56
52
  parent &&
57
53
  (await fsExtra.pathExists(`${dirs.layouts}/${parent.filename}.html`));
@@ -60,7 +56,6 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
60
56
  : parent
61
57
  ? parent.layout
62
58
  : config.default_layout_name;
63
- >>>>>>> 61ad6f94b646a80d5857c84b58250ea7f00f2758
64
59
 
65
60
  const page = {
66
61
  name,
@@ -231,16 +226,6 @@ const addLinks = async (pages, parent) => {
231
226
  for (const page of pages) {
232
227
  page.data ||= {};
233
228
  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 || "&raquo;"} <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
- =======
244
229
  ? page.data.tags.map(
245
230
  (tag) =>
246
231
  `<a class="${defaultConfig.tag_class}" href="/tags/${tag}">${tag}</a>`,
@@ -268,7 +253,6 @@ const addLinks = async (pages, parent) => {
268
253
  "nav",
269
254
  pageIndex.filter((p) => p.nav),
270
255
  );
271
- >>>>>>> 61ad6f94b646a80d5857c84b58250ea7f00f2758
272
256
  if (page.pages) {
273
257
  await addLinks(page.pages, page); // Recursive call
274
258
  }
package/src/partials.js CHANGED
@@ -45,8 +45,9 @@ const replacePlaceholders = async (template, values) => {
45
45
  },
46
46
  );
47
47
  // Replace other placeholders **only outside of code blocks**
48
+ // Fenced blocks require closing ``` to be at start of line (after newline)
48
49
  const codeBlockRegex =
49
- /```[\s\S]*?```|`[^`]+`|<(pre|code)[^>]*>[\s\S]*?<\/\1>/g;
50
+ /```[\s\S]*?\n```|`[^`\n]+`|<(pre|code)[^>]*>[\s\S]*?<\/\1>/g;
50
51
  const codeBlocks = [];
51
52
  template = template.replace(codeBlockRegex, (match) => {
52
53
  codeBlocks.push(match);
package/src/watcher.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import chokidar from "chokidar";
2
- import { exec } from "child_process";
3
2
  import path from "path";
4
3
 
5
4
  // Define files to watch, resolving relative to the current working directory
@@ -16,35 +15,35 @@ const filesToWatch = [
16
15
  "config.json",
17
16
  ].map((pattern) => path.join(process.cwd(), pattern));
18
17
 
19
- const buildScript = "npm run build";
18
+ export default async function watch(outDir = "dist") {
19
+ const build = await import("./build.js");
20
20
 
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
- });
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
+ });
30
30
 
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) {
31
+ // Rebuild function
32
+ async function triggerBuild(event, filePath) {
33
+ console.log(`File ${event}: ${filePath}. Running build...`);
34
+ try {
35
+ await build.default(outDir);
36
+ console.log("Build complete.");
37
+ } catch (error) {
36
38
  console.error(`Build failed: ${error.message}`);
37
- return;
38
39
  }
39
- if (stderr) console.error(`stderr: ${stderr}`);
40
- if (stdout) console.log(stdout);
41
- });
42
- }
40
+ }
43
41
 
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));
42
+ // Set up event listeners
43
+ watcher
44
+ .on("change", (filePath) => triggerBuild("changed", filePath))
45
+ .on("add", (filePath) => triggerBuild("added", filePath))
46
+ .on("unlink", (filePath) => triggerBuild("deleted", filePath));
49
47
 
50
- console.log("Watching for file changes...");
48
+ console.log("Watching for file changes...");
49
+ }