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