fossbook 0.0.4 → 0.0.6

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/lib/index.js CHANGED
@@ -1,79 +1,79 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- const Page = require("./mod/page");
5
- const HomePagination = require("./home");
6
- const AllPostsPage = require("./all_posts");
7
- const Posts = require("./posts");
8
- const TagPages = require("./tag");
9
-
10
- function copyDirectoryRecursive(src, dest) {
11
- fs.mkdirSync(dest, { recursive: true });
12
- const entries = fs.readdirSync(src, { withFileTypes: true });
13
-
14
- for (const entry of entries) {
15
- const srcPath = path.join(src, entry.name);
16
- const destPath = path.join(dest, entry.name);
17
-
18
- if (entry.isDirectory()) {
19
- copyDirectoryRecursive(srcPath, destPath);
20
- } else {
21
- fs.copyFileSync(srcPath, destPath);
22
- }
23
- }
24
- }
25
-
26
- function build(config) {
27
- // Remove the output directory
28
- if (fs.existsSync(config.dev.outdir))
29
- fs.rmSync(config.dev.outdir, { recursive: true });
30
- fs.mkdirSync(config.dev.outdir);
31
-
32
- // Create post pages in output directory
33
- const posts = new Posts(config);
34
- const postObjects = posts.createPostObjects();
35
-
36
- postObjects.forEach((post) => {
37
- post.generateContent("post.html");
38
- });
39
-
40
- // Create home page and pagination in output/page directory
41
- const homePagination = new HomePagination(config);
42
- homePagination.generateContent(postObjects);
43
-
44
- // Create all posts page in output/all_posts directory
45
- const allPostsPage = new AllPostsPage(config);
46
- allPostsPage.generateContent(postObjects);
47
-
48
- // Create tag pages in output/tags directory
49
- const tagPages = new TagPages(config);
50
- tagPages.generateContent(postObjects);
51
-
52
- // Create about page in output/about directory
53
- const aboutPath = config.dev.about;
54
- if (fs.existsSync(aboutPath)) {
55
- const aboutPage = new Page(config);
56
- aboutPage.readSource(aboutPath);
57
- aboutPage.generateContent("page.html", "about");
58
- }
59
-
60
- // Copy static directory to output directory
61
- const staticImagesDir = path.join(config.dev.staticDir, "images");
62
- if (fs.existsSync(staticImagesDir)) {
63
- copyDirectoryRecursive(staticImagesDir, path.join(config.dev.outdir, "images"));
64
- }
65
-
66
- // Copy theme assets to output directory
67
- const themeAssetsDir = path.join(config.themePath, "assets");
68
- if (fs.existsSync(themeAssetsDir)) {
69
- copyDirectoryRecursive(themeAssetsDir, config.dev.outdir);
70
- }
71
-
72
- // Create CNAME file for GitHub Pages
73
- if (config.githubCNAME)
74
- fs.writeFileSync(path.join(config.dev.outdir, "CNAME"), config.githubCNAME);
75
-
76
- console.log("Build completed successfully");
77
- }
78
-
79
- module.exports = { build };
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const Page = require("./mod/page");
5
+ const HomePagination = require("./home");
6
+ const AllPostsPage = require("./all_posts");
7
+ const Posts = require("./posts");
8
+ const TagPages = require("./tag");
9
+
10
+ function copyDirectoryRecursive(src, dest) {
11
+ fs.mkdirSync(dest, { recursive: true });
12
+ const entries = fs.readdirSync(src, { withFileTypes: true });
13
+
14
+ for (const entry of entries) {
15
+ const srcPath = path.join(src, entry.name);
16
+ const destPath = path.join(dest, entry.name);
17
+
18
+ if (entry.isDirectory()) {
19
+ copyDirectoryRecursive(srcPath, destPath);
20
+ } else {
21
+ fs.copyFileSync(srcPath, destPath);
22
+ }
23
+ }
24
+ }
25
+
26
+ function build(config) {
27
+ // Remove the output directory
28
+ if (fs.existsSync(config.dev.outdir))
29
+ fs.rmSync(config.dev.outdir, { recursive: true });
30
+ fs.mkdirSync(config.dev.outdir);
31
+
32
+ // Create post pages in output directory
33
+ const posts = new Posts(config);
34
+ const postObjects = posts.createPostObjects();
35
+
36
+ postObjects.forEach((post) => {
37
+ post.generateContent("post.html");
38
+ });
39
+
40
+ // Create home page and pagination in output/page directory
41
+ const homePagination = new HomePagination(config);
42
+ homePagination.generateContent(postObjects);
43
+
44
+ // Create all posts page in output/all_posts directory
45
+ const allPostsPage = new AllPostsPage(config);
46
+ allPostsPage.generateContent(postObjects);
47
+
48
+ // Create tag pages in output/tags directory
49
+ const tagPages = new TagPages(config);
50
+ tagPages.generateContent(postObjects);
51
+
52
+ // Create about page in output/about directory
53
+ const aboutPath = config.dev.about;
54
+ if (fs.existsSync(aboutPath)) {
55
+ const aboutPage = new Page(config);
56
+ aboutPage.readSource(aboutPath);
57
+ aboutPage.generateContent("page.html", "about");
58
+ }
59
+
60
+ // Copy static directory to output directory
61
+ const staticImagesDir = path.join(config.dev.staticDir, "images");
62
+ if (fs.existsSync(staticImagesDir)) {
63
+ copyDirectoryRecursive(staticImagesDir, path.join(config.dev.outdir, "images"));
64
+ }
65
+
66
+ // Copy theme assets to output directory
67
+ const themeAssetsDir = path.join(config.themePath, "assets");
68
+ if (fs.existsSync(themeAssetsDir)) {
69
+ copyDirectoryRecursive(themeAssetsDir, config.dev.outdir);
70
+ }
71
+
72
+ // Create CNAME file for GitHub Pages
73
+ if (config.githubCNAME)
74
+ fs.writeFileSync(path.join(config.dev.outdir, "CNAME"), config.githubCNAME);
75
+
76
+ console.log("Build completed successfully");
77
+ }
78
+
79
+ module.exports = { build };