fossbook 0.0.2

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.
Files changed (53) hide show
  1. package/README.md +246 -0
  2. package/bin/fossbook.js +119 -0
  3. package/lib/all_posts.js +32 -0
  4. package/lib/assets/placeholder.svg +4 -0
  5. package/lib/deploy.js +202 -0
  6. package/lib/home.js +59 -0
  7. package/lib/index.js +79 -0
  8. package/lib/init.js +253 -0
  9. package/lib/mod/config.js +98 -0
  10. package/lib/mod/marked.js +95 -0
  11. package/lib/mod/page.js +115 -0
  12. package/lib/mod/page_base.js +97 -0
  13. package/lib/new.js +48 -0
  14. package/lib/posts.js +42 -0
  15. package/lib/server.js +14 -0
  16. package/lib/tag/index.js +69 -0
  17. package/lib/tag/tag.js +29 -0
  18. package/package.json +45 -0
  19. package/themes/archie/assets/fonts/ComicNeue-Bold.ttf +0 -0
  20. package/themes/archie/assets/fonts/ComicNeue-BoldItalic.ttf +0 -0
  21. package/themes/archie/assets/fonts/ComicNeue-Italic.ttf +0 -0
  22. package/themes/archie/assets/fonts/ComicNeue-Light.ttf +0 -0
  23. package/themes/archie/assets/fonts/ComicNeue-LightItalic.ttf +0 -0
  24. package/themes/archie/assets/fonts/ComicNeue-Regular.ttf +0 -0
  25. package/themes/archie/assets/fonts/LyonDisplay-Bold.otf +0 -0
  26. package/themes/archie/assets/fonts/OFL.txt +93 -0
  27. package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.eot +0 -0
  28. package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.svg +330 -0
  29. package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.ttf +0 -0
  30. package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.woff +0 -0
  31. package/themes/archie/assets/fonts/fira-sans-v10-latin-regular.woff2 +0 -0
  32. package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.eot +0 -0
  33. package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.svg +365 -0
  34. package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.ttf +0 -0
  35. package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.woff +0 -0
  36. package/themes/archie/assets/fonts/ibm-plex-mono-v6-latin-500italic.woff2 +0 -0
  37. package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.eot +0 -0
  38. package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.svg +405 -0
  39. package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.ttf +0 -0
  40. package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.woff +0 -0
  41. package/themes/archie/assets/fonts/roboto-mono-v12-latin-regular.woff2 +0 -0
  42. package/themes/archie/assets/images/node-ssg-1.png +0 -0
  43. package/themes/archie/assets/images/node-ssg-2.png +0 -0
  44. package/themes/archie/assets/styles/fonts.css +51 -0
  45. package/themes/archie/assets/styles/highlights.css +75 -0
  46. package/themes/archie/assets/styles/main.css +402 -0
  47. package/themes/archie/layouts/all_posts.html +42 -0
  48. package/themes/archie/layouts/home.html +62 -0
  49. package/themes/archie/layouts/page.html +50 -0
  50. package/themes/archie/layouts/partials/footer.html +10 -0
  51. package/themes/archie/layouts/post.html +82 -0
  52. package/themes/archie/layouts/tag.html +43 -0
  53. package/themes/archie/layouts/tag_list.html +44 -0
@@ -0,0 +1,97 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ module.exports = class PageBase {
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.title = "";
8
+ this.image = this.config.image;
9
+ this.description = this.config.blogDescription;
10
+ this.date = "";
11
+ this.tags = [];
12
+ this.content = "";
13
+ this.url = "";
14
+ this.theme = this.config.theme;
15
+ }
16
+
17
+ formatDate(date) {
18
+ const options = { year: "numeric", month: "short", day: "numeric" };
19
+ return date.toLocaleDateString("en-US", options);
20
+ }
21
+
22
+ googleAnalytics(trackingId) {
23
+ return `<script async src="https://www.googletagmanager.com/gtag/js?id=${trackingId}"></script>
24
+ <script>
25
+ window.dataLayer = window.dataLayer || [];
26
+ function gtag() {
27
+ dataLayer.push(arguments);
28
+ }
29
+ gtag("js", new Date());
30
+ gtag("config", "${trackingId}");
31
+ </script>`;
32
+ }
33
+
34
+ // https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/abouts-cards
35
+ twitterCard(card) {
36
+ return `<meta name="twitter:card" content="${card}" />
37
+ <meta name="twitter:site" content="${this.config.siteTwitter}" />
38
+ <meta name="twitter:creator" content="${this.config.authorTwitter}" />
39
+ <meta name="twitter:title" content="${this.title}" />
40
+ <meta name="twitter:description" content="${this.description}" />
41
+ <meta name="twitter:image" content="${this.imageURL}" />`;
42
+ }
43
+
44
+ // https://ogp.me/
45
+ openGraph(type, articleObj) {
46
+ const result = `<meta property="og:type" content="${type}" />
47
+ <meta property="og:site_name" content="${this.config.blogName}" />
48
+ <meta property="og:url" content="${this.url}" />
49
+ <meta property="og:title" content="${this.title}" />
50
+ <meta property="og:description" content="${this.description}" />
51
+ <meta property="og:image" content="${this.imageURL}" />`;
52
+
53
+ if (type === "article" && articleObj) {
54
+ return (
55
+ result +
56
+ `
57
+ <meta property="article:author" content="${articleObj.authorName}" />
58
+ <meta property="article:published_time" content="${articleObj.publishedDate}" />
59
+ ${articleObj.tags.map((tag) => `<meta property="article:tag" content="${tag}">`).join("\n ")}`
60
+ );
61
+ }
62
+ return result;
63
+ }
64
+
65
+ footer() {
66
+ const footerPath = path.join(this.config.themePath, "layouts", "partials", "footer.html");
67
+ const footerTemplate = fs.readFileSync(footerPath, "utf-8");
68
+
69
+ const funcFooter = new Function(
70
+ "config",
71
+ `return () => \`${footerTemplate}\`;`,
72
+ );
73
+ const result = funcFooter(this.config)();
74
+ const footerHTML = result
75
+ .split("\n")
76
+ .map((line, index) => (index !== 0 ? ` ${line}` : line))
77
+ .join("\n");
78
+
79
+ return footerHTML;
80
+ }
81
+
82
+ generateHTML(templatePath, data) {
83
+ const postTemplate = fs.readFileSync(templatePath, "utf-8");
84
+
85
+ const funcPost = new Function(
86
+ "page, data",
87
+ `return () => \`${postTemplate}\`;`,
88
+ );
89
+ const result = funcPost(this, data)();
90
+ const postHTML = result
91
+ .split("\n")
92
+ .map((line, index) => (index !== 0 ? `${line}` : line))
93
+ .join("\n");
94
+
95
+ return postHTML;
96
+ }
97
+ };
package/lib/new.js ADDED
@@ -0,0 +1,48 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ function createPost(config, title) {
5
+ const postsDir = config.dev.postsdir;
6
+ const postDir = path.join(postsDir, title);
7
+
8
+ if (fs.existsSync(postDir)) {
9
+ console.error(`Error: Post "${title}" already exists at ${postDir}`);
10
+ process.exit(1);
11
+ }
12
+
13
+ // Ensure the posts directory exists
14
+ fs.mkdirSync(postsDir, { recursive: true });
15
+
16
+ // Create the post directory and images subdirectory
17
+ fs.mkdirSync(postDir, { recursive: true });
18
+ fs.mkdirSync(path.join(postDir, "images"), { recursive: true });
19
+
20
+ // Generate today's date in YYYY-MM-DD format
21
+ const today = new Date();
22
+ const dateStr = today.toISOString().split("T")[0];
23
+
24
+ // Copy placeholder image to the post's images directory
25
+ const placeholderSrc = path.join(__dirname, "assets", "placeholder.svg");
26
+ const placeholderDest = path.join(postDir, "images", "placeholder.svg");
27
+ if (fs.existsSync(placeholderSrc)) {
28
+ fs.copyFileSync(placeholderSrc, placeholderDest);
29
+ }
30
+
31
+ // Write index.md with front-matter
32
+ const frontMatter = `---
33
+ title: ${title}
34
+ date: ${dateStr}
35
+ description: ""
36
+ image: "placeholder.svg"
37
+ tags: ""
38
+ ---
39
+ `;
40
+
41
+ fs.writeFileSync(path.join(postDir, "index.md"), frontMatter);
42
+
43
+ console.log(`Created new post: ${postDir}`);
44
+ console.log(` - ${path.join(postDir, "index.md")}`);
45
+ console.log(` - ${path.join(postDir, "images/")}`);
46
+ }
47
+
48
+ module.exports = { createPost };
package/lib/posts.js ADDED
@@ -0,0 +1,42 @@
1
+ const fs = require("fs");
2
+ const Page = require("./mod/page");
3
+
4
+ module.exports = class Posts {
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.posts = [];
8
+ }
9
+
10
+ // Read all markdown articles from content/posts and sort them by date
11
+ createPostObjects() {
12
+ const postPaths = fs.readdirSync(this.config.dev.postsdir);
13
+ postPaths.forEach((postPath) => {
14
+ const indexPath = `${this.config.dev.postsdir}/${postPath}/index.md`;
15
+ if (!fs.existsSync(indexPath)) {
16
+ console.warn(`Skipping "${postPath}": no index.md found`);
17
+ return;
18
+ }
19
+ const post = new Page(this.config);
20
+ post.readSource(`${this.config.dev.postsdir}/${postPath}`);
21
+ post.url = `${this.config.blogsite}/${post.path}/`;
22
+ post.imageURL = `${this.config.blogsite}/${post.path}/images/${post.image}`;
23
+ this.posts.push(post);
24
+ });
25
+ // sort by date
26
+ this.posts.sort(function (a, b) {
27
+ return new Date(b.date) - new Date(a.date);
28
+ });
29
+
30
+ // loop through posts and add previous and next post to each post
31
+ for (let i = 0; i < this.posts.length; i++) {
32
+ if (i > 0) {
33
+ this.posts[i].next = this.posts[i - 1];
34
+ }
35
+ if (i < this.posts.length - 1) {
36
+ this.posts[i].previous = this.posts[i + 1];
37
+ }
38
+ }
39
+
40
+ return this.posts;
41
+ }
42
+ };
package/lib/server.js ADDED
@@ -0,0 +1,14 @@
1
+ const express = require("express");
2
+
3
+ function serve(config, port) {
4
+ const app = express();
5
+ const PORT = port || process.env.PORT || 3000;
6
+
7
+ app.use(express.static(config.dev.outdir));
8
+
9
+ app.listen(PORT, () => {
10
+ console.log(`fossbook dev server running at http://localhost:${PORT}`);
11
+ });
12
+ }
13
+
14
+ module.exports = { serve };
@@ -0,0 +1,69 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const PageBase = require("../mod/page_base");
5
+ const TagPage = require("./tag");
6
+
7
+ module.exports = class TagList extends PageBase {
8
+ constructor(config) {
9
+ super(config);
10
+ }
11
+
12
+ gatherTags(posts) {
13
+ const tags = new Map();
14
+ posts.forEach((post) => {
15
+ post.tags.forEach((tag) => {
16
+ if (!tags.has(tag)) {
17
+ tags.set(tag, []);
18
+ }
19
+ tags.get(tag).push({
20
+ path: post.path,
21
+ title: post.title,
22
+ date: post.date,
23
+ description: post.description,
24
+ });
25
+ });
26
+ });
27
+
28
+ return tags;
29
+ }
30
+
31
+ generateContent(articles) {
32
+ const tagMap = this.gatherTags(articles);
33
+
34
+ let tagArray = [];
35
+ for (let [tag, posts] of tagMap) {
36
+ tagArray.push({
37
+ name: tag,
38
+ path: tag.replace(/\s+/g, "_"),
39
+ count: posts.length,
40
+ });
41
+ }
42
+
43
+ tagArray.sort((a, b) => a.name.localeCompare(b.name));
44
+
45
+ if (!fs.existsSync(`${this.config.dev.outdir}/tags/`))
46
+ fs.mkdirSync(`${this.config.dev.outdir}/tags/`);
47
+
48
+ this.imageURL = this.config.image;
49
+ this.description = "Tag List";
50
+ const data = { tags: tagArray, pageTitle: "All tags" };
51
+ this.url = `${this.config.blogsite}/tag_list.html`;
52
+ this.title = `${this.config.blogName}: ${data.pageTitle}`;
53
+
54
+ const templatePath = path.join(this.config.themePath, "layouts", "tag_list.html");
55
+ fs.writeFile(
56
+ `${this.config.dev.outdir}/tags/index.html`,
57
+ this.generateHTML(templatePath, data),
58
+ (e) => {
59
+ if (e) throw e;
60
+ console.log(`tags/index.html for tags was created successfully`);
61
+ },
62
+ );
63
+
64
+ const tagPage = new TagPage(this.config);
65
+ for (let [tag, posts] of tagMap) {
66
+ tagPage.createPages(tag, posts);
67
+ }
68
+ }
69
+ };
package/lib/tag/tag.js ADDED
@@ -0,0 +1,29 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const PageBase = require("../mod/page_base");
4
+
5
+ module.exports = class TagPage extends PageBase {
6
+ createPages(tag, posts) {
7
+ let tagPath = tag.replace(/\s+/g, "_"); // Replace spaces with underscores
8
+ if (!fs.existsSync(`${this.config.dev.outdir}/tags/${tagPath}`))
9
+ fs.mkdirSync(`${this.config.dev.outdir}/tags/${tagPath}`);
10
+
11
+ // FIXME: imageURL should refer to the image related to the tag
12
+ this.imageURL = this.config.image;
13
+
14
+ const data = { tag: tag, posts: posts, url: "tags/" + tagPath };
15
+ this.url = `${this.config.blogsite}/${data.url}`;
16
+ this.title = `${this.config.blogName}: Entries tagged - ${data.tag}`;
17
+ this.description = `List up all posts including '${data.tag}' tag.`;
18
+
19
+ const templatePath = path.join(this.config.themePath, "layouts", "tag.html");
20
+ fs.writeFile(
21
+ `${this.config.dev.outdir}/tags/${tagPath}/index.html`,
22
+ this.generateHTML(templatePath, data),
23
+ (e) => {
24
+ if (e) throw e;
25
+ console.log(`/tags/${tagPath}/index.html was created successfully`);
26
+ },
27
+ );
28
+ }
29
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "fossbook",
3
+ "version": "0.0.2",
4
+ "description": "A lightweight static blog site generator for GitHub Pages",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "build": "node bin/fossbook.js build",
8
+ "start": "node bin/fossbook.js serve",
9
+ "test": "mocha test",
10
+ "prettier": "prettier --write ."
11
+ },
12
+ "keywords": [
13
+ "static-site-generator",
14
+ "blog",
15
+ "github-pages",
16
+ "markdown"
17
+ ],
18
+ "author": "Joone Hur",
19
+ "license": "BSD-3-Clause",
20
+ "dependencies": {
21
+ "express": "^4.19.1",
22
+ "front-matter": "^4.0.2",
23
+ "highlight.js": "^11.9.0",
24
+ "marked": "^12.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "mocha": "^10.2.0",
28
+ "prettier": "^3.2.5"
29
+ },
30
+ "bin": {
31
+ "fossbook": "bin/fossbook.js"
32
+ },
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "files": [
37
+ "bin/",
38
+ "lib/",
39
+ "themes/"
40
+ ],
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/joone/fossbook"
44
+ }
45
+ }
@@ -0,0 +1,93 @@
1
+ Copyright 2014 The Comic Neue Project Authors (https://github.com/crozynski/comicneue)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.