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/bin/fossbook.js CHANGED
@@ -1,119 +1,120 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require("path");
4
- const { loadConfig } = require("../lib/mod/config");
5
-
6
- const args = process.argv.slice(2);
7
- const command = args[0];
8
-
9
- function printHelp() {
10
- console.log(`
11
- Usage: fossbook <command> [options]
12
-
13
- Commands:
14
- build Build the static site
15
- serve Build and start a local dev server
16
- new <title> Create a new post
17
- init Create a new fossbook site project
18
- deploy Build, commit, push, and monitor deployment
19
-
20
- Options:
21
- -c, --config Path to config file (default: ./fossbook.config.js)
22
- -o, --output Output directory (default: ./public)
23
- -p, --port Dev server port (default: 3000)
24
- --clean Remove output directory before build (default: true)
25
- --github (init) Also create a GitHub repo and push
26
- -m, --message (deploy) Custom commit message
27
- --no-wait (deploy) Push without waiting for CI status
28
- --draft (deploy) Commit locally without pushing
29
- -v, --version Show version number
30
- -h, --help Show help
31
- `);
32
- }
33
-
34
- function getOption(flag, alias) {
35
- const idx = args.indexOf(flag);
36
- const aliasIdx = alias ? args.indexOf(alias) : -1;
37
- const foundIdx = idx !== -1 ? idx : aliasIdx;
38
- if (foundIdx !== -1 && foundIdx + 1 < args.length) {
39
- return args[foundIdx + 1];
40
- }
41
- return null;
42
- }
43
-
44
- function hasFlag(flag, alias) {
45
- return args.includes(flag) || (alias && args.includes(alias));
46
- }
47
-
48
- if (hasFlag("-v", "--version")) {
49
- const pkg = require("../package.json");
50
- console.log(`fossbook v${pkg.version}`);
51
- process.exit(0);
52
- }
53
-
54
- if (hasFlag("-h", "--help") || !command) {
55
- printHelp();
56
- process.exit(0);
57
- }
58
-
59
- const configPath = getOption("-c", "--config");
60
-
61
- switch (command) {
62
- case "build": {
63
- const config = loadConfig(configPath);
64
- const outputOverride = getOption("-o", "--output");
65
- if (outputOverride) config.dev.outdir = outputOverride;
66
-
67
- const { build } = require("../lib/index");
68
- build(config);
69
- break;
70
- }
71
-
72
- case "serve": {
73
- const config = loadConfig(configPath);
74
- const outputOverride = getOption("-o", "--output");
75
- if (outputOverride) config.dev.outdir = outputOverride;
76
- const port = getOption("-p", "--port") || 3000;
77
-
78
- const { build } = require("../lib/index");
79
- build(config);
80
-
81
- const { serve } = require("../lib/server");
82
- serve(config, Number(port));
83
- break;
84
- }
85
-
86
- case "new": {
87
- const title = args[1];
88
- if (!title) {
89
- console.error('Error: Please provide a post title. Usage: fossbook new "My Post Title"');
90
- process.exit(1);
91
- }
92
- const config = loadConfig(configPath);
93
- const { createPost } = require("../lib/new");
94
- createPost(config, title);
95
- break;
96
- }
97
-
98
- case "init": {
99
- const { initProject } = require("../lib/init");
100
- initProject({ github: hasFlag("--github") });
101
- break;
102
- }
103
-
104
- case "deploy": {
105
- const config = loadConfig(configPath);
106
- const { deploy } = require("../lib/deploy");
107
- deploy(config, {
108
- message: getOption("-m", "--message"),
109
- noWait: hasFlag("--no-wait"),
110
- draft: hasFlag("--draft"),
111
- });
112
- break;
113
- }
114
-
115
- default:
116
- console.error(`Unknown command: ${command}`);
117
- printHelp();
118
- process.exit(1);
119
- }
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const { loadConfig } = require("../lib/mod/config");
5
+
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+
9
+ function printHelp() {
10
+ console.log(`
11
+ Usage: fossbook <command> [options]
12
+
13
+ Commands:
14
+ build Build the static site
15
+ serve Build and start a local dev server
16
+ new <title> Create a new post
17
+ init [name] Create a new fossbook site project
18
+ deploy Build, commit, push, and monitor deployment
19
+
20
+ Options:
21
+ -c, --config Path to config file (default: ./fossbook.config.js)
22
+ -o, --output Output directory (default: ./public)
23
+ -p, --port Dev server port (default: 3000)
24
+ --clean Remove output directory before build (default: true)
25
+ --github (init) Also create a GitHub repo and push
26
+ -m, --message (deploy) Custom commit message
27
+ --no-wait (deploy) Push without waiting for CI status
28
+ --draft (deploy) Commit locally without pushing
29
+ -v, --version Show version number
30
+ -h, --help Show help
31
+ `);
32
+ }
33
+
34
+ function getOption(flag, alias) {
35
+ const idx = args.indexOf(flag);
36
+ const aliasIdx = alias ? args.indexOf(alias) : -1;
37
+ const foundIdx = idx !== -1 ? idx : aliasIdx;
38
+ if (foundIdx !== -1 && foundIdx + 1 < args.length) {
39
+ return args[foundIdx + 1];
40
+ }
41
+ return null;
42
+ }
43
+
44
+ function hasFlag(flag, alias) {
45
+ return args.includes(flag) || (alias && args.includes(alias));
46
+ }
47
+
48
+ if (hasFlag("-v", "--version")) {
49
+ const pkg = require("../package.json");
50
+ console.log(`fossbook v${pkg.version}`);
51
+ process.exit(0);
52
+ }
53
+
54
+ if (hasFlag("-h", "--help") || !command) {
55
+ printHelp();
56
+ process.exit(0);
57
+ }
58
+
59
+ const configPath = getOption("-c", "--config");
60
+
61
+ switch (command) {
62
+ case "build": {
63
+ const config = loadConfig(configPath);
64
+ const outputOverride = getOption("-o", "--output");
65
+ if (outputOverride) config.dev.outdir = outputOverride;
66
+
67
+ const { build } = require("../lib/index");
68
+ build(config);
69
+ break;
70
+ }
71
+
72
+ case "serve": {
73
+ const config = loadConfig(configPath);
74
+ const outputOverride = getOption("-o", "--output");
75
+ if (outputOverride) config.dev.outdir = outputOverride;
76
+ const port = getOption("-p", "--port") || 3000;
77
+
78
+ const { build } = require("../lib/index");
79
+ build(config);
80
+
81
+ const { serve } = require("../lib/server");
82
+ serve(config, Number(port));
83
+ break;
84
+ }
85
+
86
+ case "new": {
87
+ const title = args[1];
88
+ if (!title) {
89
+ console.error('Error: Please provide a post title. Usage: fossbook new "My Post Title"');
90
+ process.exit(1);
91
+ }
92
+ const config = loadConfig(configPath);
93
+ const { createPost } = require("../lib/new");
94
+ createPost(config, title);
95
+ break;
96
+ }
97
+
98
+ case "init": {
99
+ const { initProject } = require("../lib/init");
100
+ const projectName = !args[1] || args[1].startsWith("--") ? null : args[1];
101
+ initProject({ github: hasFlag("--github"), name: projectName });
102
+ break;
103
+ }
104
+
105
+ case "deploy": {
106
+ const config = loadConfig(configPath);
107
+ const { deploy } = require("../lib/deploy");
108
+ deploy(config, {
109
+ message: getOption("-m", "--message"),
110
+ noWait: hasFlag("--no-wait"),
111
+ draft: hasFlag("--draft"),
112
+ });
113
+ break;
114
+ }
115
+
116
+ default:
117
+ console.error(`Unknown command: ${command}`);
118
+ printHelp();
119
+ process.exit(1);
120
+ }
package/lib/all_posts.js CHANGED
@@ -1,32 +1,33 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const PageBase = require("./mod/page_base");
4
-
5
- module.exports = class AllPostsPage extends PageBase {
6
- constructor(config) {
7
- super(config);
8
- }
9
-
10
- // posts: array of Page objects
11
- generateContent(posts) {
12
- const pageTitle = "All posts";
13
- if (!fs.existsSync(`${this.config.dev.outdir}/all_posts/`))
14
- fs.mkdirSync(`${this.config.dev.outdir}/all_posts/`);
15
-
16
- const data = { posts: posts, pageTitle: pageTitle };
17
- this.url = `${this.config.blogsite}/posts.html`;
18
- this.title = `${this.config.blogName}: ${data.pageTitle}`;
19
- this.description = "All posts";
20
- this.imageURL = this.config.image;
21
-
22
- const templatePath = path.join(this.config.themePath, "layouts", "all_posts.html");
23
- fs.writeFileSync(
24
- `${this.config.dev.outdir}/all_posts/index.html`,
25
- this.generateHTML(templatePath, data),
26
- (e) => {
27
- if (e) throw e;
28
- console.log(`posts.html was created successfully`);
29
- },
30
- );
31
- }
32
- };
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const PageBase = require("./mod/page_base");
4
+
5
+ module.exports = class AllPostsPage extends PageBase {
6
+ constructor(config) {
7
+ super(config);
8
+ }
9
+
10
+ // posts: array of Page objects
11
+ generateContent(posts) {
12
+ const pageTitle = "All posts";
13
+ const allPostsDir = path.join(this.config.dev.outdir, "all_posts");
14
+ if (!fs.existsSync(allPostsDir))
15
+ fs.mkdirSync(allPostsDir);
16
+
17
+ const data = { posts: posts, pageTitle: pageTitle };
18
+ this.url = `${this.config.blogsite}/posts.html`;
19
+ this.title = `${this.config.blogName}: ${data.pageTitle}`;
20
+ this.description = "All posts";
21
+ this.imageURL = this.config.image;
22
+
23
+ const templatePath = path.join(this.config.themePath, "layouts", "all_posts.html");
24
+ fs.writeFileSync(
25
+ path.join(allPostsDir, "index.html"),
26
+ this.generateHTML(templatePath, data),
27
+ (e) => {
28
+ if (e) throw e;
29
+ console.log(`posts.html was created successfully`);
30
+ },
31
+ );
32
+ }
33
+ };
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="800" height="400" viewBox="0 0 800 400">
2
- <rect width="800" height="400" fill="#f0f0f0"/>
3
- <text x="400" y="200" font-family="Arial, sans-serif" font-size="32" fill="#999" text-anchor="middle" dominant-baseline="middle">Your Image Here</text>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="800" height="400" viewBox="0 0 800 400">
2
+ <rect width="800" height="400" fill="#f0f0f0"/>
3
+ <text x="400" y="200" font-family="Arial, sans-serif" font-size="32" fill="#999" text-anchor="middle" dominant-baseline="middle">Your Image Here</text>
4
4
  </svg>