@daz4126/swifty 1.8.1 → 1.10.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/README.md +1 -1
- package/init.js +12 -1
- package/package.json +11 -3
- package/swifty.js +8 -8
- package/serve.json +0 -5
- package/test/swifty.test.js +0 -78
package/README.md
CHANGED
|
@@ -17,4 +17,4 @@ It also uses convention over configuration to make is super simple to build site
|
|
|
17
17
|
5. Change the `sitename` in `config.yaml`
|
|
18
18
|
6. Add some markdown files to the 'pages' directory
|
|
19
19
|
7. `npx swifty start` to rebuild and start the server
|
|
20
|
-
8. Visit [http://localhost:3000] to see your site
|
|
20
|
+
8. Visit [http://localhost:3000](http://localhost:3000) to see your site
|
package/init.js
CHANGED
|
@@ -17,7 +17,18 @@ const structure = {
|
|
|
17
17
|
"css/": null,
|
|
18
18
|
"js/": null,
|
|
19
19
|
"images/": null,
|
|
20
|
-
"config.yaml":
|
|
20
|
+
"config.yaml": `sitename: Swifty
|
|
21
|
+
breadcrumb_separator: "»"
|
|
22
|
+
breadcrumb_class: swifty_breadcrumb
|
|
23
|
+
link_class: swifty_link
|
|
24
|
+
tag_class: tag
|
|
25
|
+
max_image_size: 800
|
|
26
|
+
|
|
27
|
+
dateFormat:
|
|
28
|
+
weekday: short
|
|
29
|
+
month: short
|
|
30
|
+
day: numeric
|
|
31
|
+
year: numeric`,
|
|
21
32
|
"template.html": `<!DOCTYPE html>
|
|
22
33
|
<html lang="en">
|
|
23
34
|
<head>
|
package/package.json
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daz4126/swifty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"swifty": "./cli.js"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"swifty.js",
|
|
11
|
+
"cli.js",
|
|
12
|
+
"init.js"
|
|
13
|
+
],
|
|
9
14
|
"scripts": {
|
|
10
15
|
"test": "mocha",
|
|
11
16
|
"build": "node swifty.js",
|
|
12
17
|
"start": "node swifty.js && serve dist",
|
|
13
18
|
"init": "node init.js"
|
|
14
19
|
},
|
|
15
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"static",
|
|
22
|
+
"site",
|
|
23
|
+
"generator"
|
|
24
|
+
],
|
|
16
25
|
"author": "DAZ",
|
|
17
26
|
"license": "MIT",
|
|
18
27
|
"description": "Super Speedy Static Site Generator",
|
|
@@ -27,7 +36,6 @@
|
|
|
27
36
|
"sharp": "^0.33.5"
|
|
28
37
|
},
|
|
29
38
|
"devDependencies": {
|
|
30
|
-
"jest": "^29.7.0",
|
|
31
39
|
"mocha": "^11.1.0"
|
|
32
40
|
},
|
|
33
41
|
"directories": {
|
package/swifty.js
CHANGED
|
@@ -232,7 +232,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
232
232
|
const name = root ? "Home" : capitalize(file.name.replace(/\.md$/, "").replace(/-/g, " "));
|
|
233
233
|
const stats = await fs.stat(filePath);
|
|
234
234
|
const isDirectory = file.isDirectory();
|
|
235
|
-
const assetPath = parent ? parent.filename : "
|
|
235
|
+
const assetPath = parent ? parent.filename : "layout";
|
|
236
236
|
const layoutFileExists = await fsExtra.pathExists(dirs.layouts + "/" + assetPath + ".html");
|
|
237
237
|
const layout = !root && layoutFileExists && assetPath;
|
|
238
238
|
|
|
@@ -327,12 +327,12 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
|
|
|
327
327
|
const generateLinkList = async (name,pages) => {
|
|
328
328
|
const partial = `${name}.md`;
|
|
329
329
|
const partialPath = path.join(dirs.partials, partial);
|
|
330
|
-
const
|
|
330
|
+
const linksPath = path.join(dirs.partials, "links.md");
|
|
331
331
|
// Check if either file exists in the 'partials' folder
|
|
332
332
|
const fileExists = await fsExtra.pathExists(partialPath);
|
|
333
|
-
const defaultExists = await fsExtra.pathExists(
|
|
333
|
+
const defaultExists = await fsExtra.pathExists(linksPath);
|
|
334
334
|
if (fileExists || defaultExists) {
|
|
335
|
-
const partial = await fs.readFile(fileExists ? partialPath :
|
|
335
|
+
const partial = await fs.readFile(fileExists ? partialPath : linksPath, "utf-8");
|
|
336
336
|
const content = await Promise.all(pages.map(page => replacePlaceholders(partial, page)));
|
|
337
337
|
return content.join('\n');
|
|
338
338
|
} else {
|
|
@@ -343,7 +343,9 @@ const generateLinkList = async (name,pages) => {
|
|
|
343
343
|
const render = async page => {
|
|
344
344
|
const replacedContent = await replacePlaceholders(page.content, page);
|
|
345
345
|
const htmlContent = marked.parse(replacedContent); // Markdown processed once
|
|
346
|
-
|
|
346
|
+
|
|
347
|
+
const wrappedContent = await applyLayoutAndWrapContent(page, htmlContent);
|
|
348
|
+
const turboHTML = wrappedContent.replace(
|
|
347
349
|
/<a\s+([^>]*?)href="(\/[^"#?]+?)"(.*?)>/g,
|
|
348
350
|
(match, beforeHref, href, afterHref) => {
|
|
349
351
|
// Don't double-add .html
|
|
@@ -352,9 +354,7 @@ const render = async page => {
|
|
|
352
354
|
return `<a ${beforeHref}href="${fullHref}" data-turbo-frame="content" data-turbo-action="advance"${afterHref}>`;
|
|
353
355
|
}
|
|
354
356
|
);
|
|
355
|
-
|
|
356
|
-
const wrappedContent = await applyLayoutAndWrapContent(page, turboHTML);
|
|
357
|
-
return wrappedContent;
|
|
357
|
+
return turboHTML;
|
|
358
358
|
};
|
|
359
359
|
|
|
360
360
|
// Function to read and render the index template
|
package/serve.json
DELETED
package/test/swifty.test.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import fsExtra from "fs-extra";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import "../swifty.js";
|
|
6
|
-
|
|
7
|
-
// Helper function to ensure directories exist and copy assets
|
|
8
|
-
async function ensureDirectoriesAndCopyAssets(sourceDir, targetDir) {
|
|
9
|
-
// Ensure the target directory exists
|
|
10
|
-
await fsExtra.ensureDir(targetDir);
|
|
11
|
-
|
|
12
|
-
// Copy assets from source to target
|
|
13
|
-
await copyAssets(sourceDir, targetDir);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Function to render a page with layout and dynamic content
|
|
17
|
-
async function renderPageWithLayout(pagePath, layoutPath) {
|
|
18
|
-
// Read the content of the page and layout
|
|
19
|
-
const pageContent = await fs.readFile(pagePath, "utf-8");
|
|
20
|
-
const layoutContent = await fs.readFile(layoutPath, "utf-8");
|
|
21
|
-
|
|
22
|
-
// Apply the layout and wrap content
|
|
23
|
-
const wrappedContent = await applyLayoutAndWrapContent(pageContent, layoutContent);
|
|
24
|
-
|
|
25
|
-
// Render the final output
|
|
26
|
-
return await render(wrappedContent);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Generate a page and write it to the output directory
|
|
30
|
-
async function generateAndWritePage(pageData, outputDir) {
|
|
31
|
-
const pagePath = path.join(outputDir, `${pageData.title}.html`);
|
|
32
|
-
|
|
33
|
-
// Generate the page content
|
|
34
|
-
const pageContent = await generatePages(pageData);
|
|
35
|
-
|
|
36
|
-
// Write the generated content to the page file
|
|
37
|
-
await fs.writeFile(pagePath, pageContent);
|
|
38
|
-
|
|
39
|
-
console.log(`Page generated at: ${pagePath}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Function to ensure and copy necessary files, then render and generate the pages
|
|
43
|
-
async function prepareAndGeneratePages(sourceDir, targetDir, pagesData) {
|
|
44
|
-
// Ensure directories and copy assets
|
|
45
|
-
await ensureDirectoriesAndCopyAssets(sourceDir, targetDir);
|
|
46
|
-
|
|
47
|
-
// Loop through the pagesData and generate pages
|
|
48
|
-
for (const pageData of pagesData) {
|
|
49
|
-
const outputPagePath = path.join(targetDir, `${pageData.title}.html`);
|
|
50
|
-
|
|
51
|
-
// Ensure the target page directory exists
|
|
52
|
-
await fsExtra.ensureDir(path.dirname(outputPagePath));
|
|
53
|
-
|
|
54
|
-
// Generate and write the page
|
|
55
|
-
await generateAndWritePage(pageData, targetDir);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Example function to demonstrate usage
|
|
60
|
-
async function main() {
|
|
61
|
-
const sourceDir = "./pages"; // Directory where source markdown or assets are located
|
|
62
|
-
const targetDir = "./dist"; // Output directory for generated pages
|
|
63
|
-
const pagesData = [
|
|
64
|
-
{ title: "home", content: "Welcome to our homepage" },
|
|
65
|
-
{ title: "about", content: "Learn more about us" },
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
// Ensure and generate pages
|
|
70
|
-
await prepareAndGeneratePages(sourceDir, targetDir, pagesData);
|
|
71
|
-
console.log("Pages successfully generated!");
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error("Error generating pages:", error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Run the main function
|
|
78
|
-
main();
|