]>
git.r.bdr.sh - rbdr/blog/blob - lib/archivers/gemlog.js
1 const { cp
, mkdir
, readdir
, writeFile
} = require('fs/promises');
2 const { debuglog
} = require('util');
3 const { resolve
, join
} = require('path');
4 const { rmIfExists
} = require('../utils');
7 kArchiveName: resolve(join(__dirname
, '../..', '.gemlog')),
8 kIndexName: 'index.gmi',
11 debuglog: debuglog('blog'),
14 return `./${id}/${slug}`;
17 buildTitle (id
, slug
) {
18 const date
= new Date(Number(id
));
19 const shortDate
= date
.toISOString().split('T')[0]
20 const title
= slug
.split('-').join(' ');
21 return `${shortDate} ${title}`
25 return `=> ${internals.buildUrl(id,slug)} ${internals.buildTitle(id,slug)}`;
29 module
.exports
= async
function(archiveDirectory
) {
30 internals
.debuglog(`Reading archive ${archiveDirectory}`);
31 const postIds
= (await
readdir(archiveDirectory
))
32 .sort((a
, b
) => Number(b
) - Number(a
));
34 for (const id
of postIds
) {
35 const postDirectory
= join(archiveDirectory
, id
);
36 const slug
= (await
readdir(postDirectory
))
37 .filter((entry
) => internals
.kGeminiRe
.test(entry
))[0];
39 posts
.push({ id
, slug
})
42 internals
.debuglog(`Read ${posts.length} posts`);
45 '# Unlimited Pizza Gemlog Archive', '',
46 '=> https://blog.unlimited.pizza/feed.xml ð° RSS Feed',
47 '=> https://blog.unlimited.pizza/index.txt ð http text version (latest 3 posts)',
49 ...posts
.map((post
) => internals
.buildLink(post
.id
, post
.slug
)),
50 '', '=> ../ ðŠī Back to main page'
54 internals
.debuglog('Removing index');
55 await
rmIfExists(internals
.kArchiveName
);
58 internals
.debuglog('Creating index');
59 await
mkdir(internals
.kArchiveName
);
60 const indexFile
= join(internals
.kArchiveName
, internals
.kIndexName
);
61 await
writeFile(indexFile
, index
);
63 internals
.debuglog('Copying posts to archive');
64 await
cp(archiveDirectory
, internals
.kArchiveName
, { recursive: true });