aboutsummaryrefslogtreecommitdiff
path: root/lib/archivers
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 14:17:34 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 14:17:34 +0100
commit172f4c8807d44ebe38c7f227b7fdc2d6a9dbe323 (patch)
treeb880761cf254fbc668cea0d577d5331a28af67cc /lib/archivers
parent36a4680d18de012e2e5c732f9db161dafa884344 (diff)
Allow sync up and down
Diffstat (limited to 'lib/archivers')
-rw-r--r--lib/archivers/gemlog.js75
1 files changed, 0 insertions, 75 deletions
diff --git a/lib/archivers/gemlog.js b/lib/archivers/gemlog.js
deleted file mode 100644
index 1bb0c10..0000000
--- a/lib/archivers/gemlog.js
+++ /dev/null
@@ -1,75 +0,0 @@
-import Dot from 'dot';
-import { cp, mkdir, readdir, readFile, writeFile } from 'fs/promises';
-import { debuglog } from 'util';
-import { join } from 'path';
-import { rmIfExists } from '../utils.js';
-
-const internals = {
- kIndexName: 'index.gmi',
- kGeminiRe: /\.gmi$/i,
-
- 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)}`;
- }
-};
-
-export default async function (templateDirectory, source, target) {
-
- internals.debuglog(`Reading archive ${source}`);
- const postIds = (await readdir(source))
- .sort((a, b) => Number(b) - Number(a));
- const posts = [];
- for (const id of postIds) {
- const postDirectory = join(source, id);
- const slug = (await readdir(postDirectory))
- .filter((entry) => internals.kGeminiRe.test(entry))[0];
-
- posts.push({ id, slug });
- }
-
- internals.debuglog(`Read ${posts.length} posts`);
-
- internals.debuglog('Generating Archive Index');
- const indexLocation = join(templateDirectory, internals.kIndexName);
-
- internals.debuglog(`Reading ${indexLocation}`);
- const indexTemplate = await readFile(indexLocation, { encoding: 'utf8' });
-
- internals.debuglog('Writing Archive Index');
- const index = Dot.template(indexTemplate, {
- ...Dot.templateSettings,
- strip: false
- })({
- posts: posts.map((post) => internals.buildLink(post.id, post.slug)).join('\n')
- });
-
- try {
- internals.debuglog('Removing index');
- await rmIfExists(target);
- }
- finally {
- internals.debuglog('Creating index');
- await mkdir(target);
- const indexFile = join(target, internals.kIndexName);
- await writeFile(indexFile, index);
-
- internals.debuglog('Copying posts to archive');
- await cp(source, target, { recursive: true });
- }
-}