]> git.r.bdr.sh - rbdr/blog/blobdiff - lib/blog.js
Add archive publishing
[rbdr/blog] / lib / blog.js
index 8ae3e21a28884f1b091b1f3e4d221d0543481cf8..ff52554a07ed5faa44c817f4e12bceb35f7ee539 100644 (file)
@@ -3,7 +3,7 @@
 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');
@@ -126,6 +126,38 @@ module.exports = class Blog {
     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() {