aboutsummaryrefslogtreecommitdiff
path: root/lib
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 /lib
parentfac54389550aaab8bcb4ad1e6b0b1900fd8887d2 (diff)
Add archive publishing
Diffstat (limited to 'lib')
-rw-r--r--lib/archivers/gemlog.js32
-rw-r--r--lib/blog.js34
2 files changed, 60 insertions, 6 deletions
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() {