This gets updated every time you add or update a post.
-The publishing will not publish the archive. This is up to you to control.
+Publishing with `--publish` will not publish the archive. Instead you should
+use `--publish-archive`, which will `rsync` it to the destination provided.
## Debugging
const internals = {
blog: new Blog(Config),
- expectedKeys: ['add', 'generate', 'update', 'publish', 'version'],
+ expectedKeys: ['add', 'generate', 'update', 'publish', 'publish-archive', 'version'],
// Application entry point. Reads arguments and calls the
// corresponding method from the blog lib
await internals.blog.publish(value);
return;
}
+
+ if (argument === 'publish-archive') {
+ await internals.blog.publishArchive(value);
+ return;
+ }
}
}
console.error('blog --add path/to/blog_post\t\t(creates new blog post)');
console.error('blog --update path/to/blog_post\t\t(updates latest blog post)');
console.error('blog --generate \t\t\t(generates the blog assets)');
- console.error('blog --publish <bucket> \t\t\t\t(publishes the blog to an S3 bucket)');
+ console.error('blog --publish <bucket> \t\t(publishes the blog to an S3 bucket)');
+ console.error('blog --publish-archive <destination> \t(publishes the archive to a remote host)');
console.error('blog --version \t\t\t\t(print the version)');
}
};
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);
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');
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');
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() {
"entities": "^3.0.1",
"gemini-to-html": "^2.1.0",
"getenv": "^1.0.0",
- "marked": "^4.0.8",
"minimist": "^1.2.5",
"ncp": "^2.0.0"
},
"integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==",
"dev": true
},
- "node_modules/marked": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.8.tgz",
- "integrity": "sha512-dkpJMIlJpc833hbjjg8jraw1t51e/eKDoG8TFOgc5O0Z77zaYKigYekTDop5AplRoKFGIaoazhYEhGkMtU3IeA==",
- "bin": {
- "marked": "bin/marked.js"
- },
- "engines": {
- "node": ">= 12"
- }
- },
"node_modules/mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"dev": true,
"requires": {}
},
- "marked": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.8.tgz",
- "integrity": "sha512-dkpJMIlJpc833hbjjg8jraw1t51e/eKDoG8TFOgc5O0Z77zaYKigYekTDop5AplRoKFGIaoazhYEhGkMtU3IeA=="
- },
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"entities": "^3.0.1",
"gemini-to-html": "^2.1.0",
"getenv": "^1.0.0",
- "marked": "^4.0.8",
"minimist": "^1.2.5",
"ncp": "^2.0.0"
},
<main>
<p>
This blog is also available in <a href="/index.txt">plain text</a>.
+ Archive available in <a href="gemini://gemini.unlimited.pizza/gemlog">gemini</a>
</p>
<p>
â <a href="http://unlimited.pizza">home</a>.