aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-08 20:44:49 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-08 20:44:49 +0200
commit65d379f5db381423165e0da8cc788f85112873b8 (patch)
tree10b52164cc2ae5f863549305ecec97e3ab96cd80
parentfac54389550aaab8bcb4ad1e6b0b1900fd8887d2 (diff)
Add archive publishing
-rw-r--r--README.md3
-rwxr-xr-xbin/blog.js10
-rw-r--r--lib/archivers/gemlog.js32
-rw-r--r--lib/blog.js34
-rw-r--r--package-lock.json17
-rw-r--r--package.json1
-rw-r--r--templates/index.html1
7 files changed, 71 insertions, 27 deletions
diff --git a/README.md b/README.md
index d0c4eb1..41de942 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,8 @@ as a gemlog format).
This gets updated every time you add or update a post.
-The publishing will not publish the archive. This is up to you to control.
+Publishing with `--publish` will not publish the archive. Instead you should
+use `--publish-archive`, which will `rsync` it to the destination provided.
## Debugging
diff --git a/bin/blog.js b/bin/blog.js
index 3c37f47..8f0ab70 100755
--- a/bin/blog.js
+++ b/bin/blog.js
@@ -8,7 +8,7 @@ const Minimist = require('minimist');
const internals = {
blog: new Blog(Config),
- expectedKeys: ['add', 'generate', 'update', 'publish', 'version'],
+ expectedKeys: ['add', 'generate', 'update', 'publish', 'publish-archive', 'version'],
// Application entry point. Reads arguments and calls the
// corresponding method from the blog lib
@@ -47,6 +47,11 @@ const internals = {
await internals.blog.publish(value);
return;
}
+
+ if (argument === 'publish-archive') {
+ await internals.blog.publishArchive(value);
+ return;
+ }
}
}
@@ -89,7 +94,8 @@ const internals = {
console.error('blog --add path/to/blog_post\t\t(creates new blog post)');
console.error('blog --update path/to/blog_post\t\t(updates latest blog post)');
console.error('blog --generate \t\t\t(generates the blog assets)');
- console.error('blog --publish <bucket> \t\t\t\t(publishes the blog to an S3 bucket)');
+ console.error('blog --publish <bucket> \t\t(publishes the blog to an S3 bucket)');
+ console.error('blog --publish-archive <destination> \t(publishes the archive to a remote host)');
console.error('blog --version \t\t\t\t(print the version)');
}
};
diff --git a/lib/archivers/gemlog.js b/lib/archivers/gemlog.js
index d50d411..50bb334 100644
--- a/lib/archivers/gemlog.js
+++ b/lib/archivers/gemlog.js
@@ -1,20 +1,36 @@
const { mkdir, readdir, rm, writeFile } = require('fs/promises');
const { debuglog, promisify } = require('util');
const { ncp } = require('ncp');
-const { join } = require('path');
+const { resolve, join } = require('path');
const internals = {
- kArchiveName: '.gemlog',
+ kArchiveName: resolve(join(__dirname, '../..', '.gemlog')),
kIndexName: 'index.gmi',
kGeminiRe: /\.gmi$/i,
ncp: promisify(ncp),
debuglog: debuglog('blog'),
+
+ buildUrl(id, slug) {
+ return `./${id}/${slug}`;
+ },
+
+ buildTitle (id, slug) {
+ const date = new Date(Number(id));
+ const shortDate = date.toISOString().split('T')[0]
+ const title = slug.split('-').join(' ');
+ return `${shortDate} ${title}`
+ },
+
+ buildLink(id, slug) {
+ return `=> ${internals.buildUrl(id,slug)} ${internals.buildTitle(id,slug)}`;
+ }
};
module.exports = async function(archiveDirectory) {
internals.debuglog(`Reading archive ${archiveDirectory}`);
- const postIds = await readdir(archiveDirectory)
+ const postIds = (await readdir(archiveDirectory))
+ .sort((a, b) => Number(b) - Number(a));
const posts = [];
for (const id of postIds) {
const postDirectory = join(archiveDirectory, id);
@@ -26,8 +42,14 @@ module.exports = async function(archiveDirectory) {
internals.debuglog(`Read ${posts.length} posts`);
- const index = ['# Unlimited Pizza Gemlog Archive', '',
- ...posts.map((post) => `=> ./${post.id}/${post.slug}`)].join('\n');
+ const index = [
+ '# Unlimited Pizza Gemlog Archive', '',
+ '=> https://blog.unlimited.pizza/feed.xml 📰 RSS Feed',
+ '=> https://blog.unlimited.pizza/index.txt 📑 http text version (latest 3 posts)',
+ '',
+ ...posts.map((post) => internals.buildLink(post.id, post.slug)),
+ '', '=> ../ ðŸŠī Back to main page'
+ ].join('\n');
try {
internals.debuglog('Removing index');
diff --git a/lib/blog.js b/lib/blog.js
index 8ae3e21..ff52554 100644
--- a/lib/blog.js
+++ b/lib/blog.js
@@ -3,7 +3,7 @@
const { access, mkdir, readdir, readFile, rm, writeFile } = require('fs/promises');
const { exec } = require('child_process');
const { ncp } = require('ncp');
-const { join } = require('path');
+const { resolve, join } = require('path');
const ParseGemini = require('gemini-to-html/parse');
const RenderGemini = require('gemini-to-html/render');
const { debuglog, promisify } = require('util');
@@ -126,6 +126,38 @@ module.exports = class Blog {
internals.debuglog('Finished publishing');
}
+ /**
+ * Publishes the archive to a host using rsync. Currently assumes
+ * gemlog archive.
+ *
+ * @function publishArchive
+ * @memberof Blog
+ * @return {Promise<undefined>} empty promise, returns no value
+ * @instance
+ */
+ async publishArchive(host) {
+
+ internals.debuglog(`Publishing archive to ${host}`);
+ try {
+ await internals.exec('which rsync');
+ }
+ catch (err) {
+ console.error('Please install rsync to publish the archive.');
+ }
+
+ try {
+ const gemlogPath = resolve(join(__dirname, '../', '.gemlog'));
+ internals.debuglog(`Reading archive from ${gemlogPath}`);
+ await internals.exec(`rsync -r ${gemlogPath}/ ${host}`);
+ }
+ catch (err) {
+ console.error('Failed to publish archive');
+ console.error(err.stderr);
+ }
+
+ internals.debuglog('Finished publishing');
+ }
+
// Parses Gemini for each page, copies assets and generates index.
async generate() {
diff --git a/package-lock.json b/package-lock.json
index 3efff4a..4dfb228 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,6 @@
"entities": "^3.0.1",
"gemini-to-html": "^2.1.0",
"getenv": "^1.0.0",
- "marked": "^4.0.8",
"minimist": "^1.2.5",
"ncp": "^2.0.0"
},
@@ -1320,17 +1319,6 @@
"integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==",
"dev": true
},
- "node_modules/marked": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.8.tgz",
- "integrity": "sha512-dkpJMIlJpc833hbjjg8jraw1t51e/eKDoG8TFOgc5O0Z77zaYKigYekTDop5AplRoKFGIaoazhYEhGkMtU3IeA==",
- "bin": {
- "marked": "bin/marked.js"
- },
- "engines": {
- "node": ">= 12"
- }
- },
"node_modules/mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
@@ -2984,11 +2972,6 @@
"dev": true,
"requires": {}
},
- "marked": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.8.tgz",
- "integrity": "sha512-dkpJMIlJpc833hbjjg8jraw1t51e/eKDoG8TFOgc5O0Z77zaYKigYekTDop5AplRoKFGIaoazhYEhGkMtU3IeA=="
- },
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
diff --git a/package.json b/package.json
index 8bc21f9..1df9fb3 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,6 @@
"entities": "^3.0.1",
"gemini-to-html": "^2.1.0",
"getenv": "^1.0.0",
- "marked": "^4.0.8",
"minimist": "^1.2.5",
"ncp": "^2.0.0"
},
diff --git a/templates/index.html b/templates/index.html
index b8f9213..f5dbbc3 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -28,6 +28,7 @@
<main>
<p>
This blog is also available in <a href="/index.txt">plain text</a>.
+ Archive available in <a href="gemini://gemini.unlimited.pizza/gemlog">gemini</a>
</p>
<p>
→ <a href="http://unlimited.pizza">home</a>.