diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2022-05-08 20:44:49 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2022-05-08 20:44:49 +0200 |
| commit | 65d379f5db381423165e0da8cc788f85112873b8 (patch) | |
| tree | 10b52164cc2ae5f863549305ecec97e3ab96cd80 /lib/archivers | |
| parent | fac54389550aaab8bcb4ad1e6b0b1900fd8887d2 (diff) | |
Add archive publishing
Diffstat (limited to 'lib/archivers')
| -rw-r--r-- | lib/archivers/gemlog.js | 32 |
1 files changed, 27 insertions, 5 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'); |