]> git.r.bdr.sh - rbdr/blog/blobdiff - lib/blog.js
Escape ampersand in titles
[rbdr/blog] / lib / blog.js
index d2acbb48d2c11739b4cdf09bd50f915962200f9e..05c1ab6c847b36b218d61abfad2a39b7dfc4b3e6 100644 (file)
@@ -59,13 +59,12 @@ module.exports = class Blog {
   }
 
   /**
-   * Shifts the blog posts, adds the passed path to slot 0, and
+   * Shifts the blog posts, adds the passed file to slot 0, and
    * generates files.
    *
    * @function add
    * @memberof Blog
-   * @param {string} postLocation the path to the directory containing
-   * the post structure
+   * @param {string} postLocation the path to the blog post file
    * @return {Promise<undefined>} empty promise, returns no value
    * @instance
    */
@@ -84,12 +83,11 @@ module.exports = class Blog {
   }
 
   /**
-   * Adds the passed path to slot 0, and generates files.
+   * Update slot 0 with the passed gmi file, and generates files.
    *
    * @function update
    * @memberof Blog
-   * @param {string} postLocation the path to the directory containing
-   * the post structure
+   * @param {string} postLocation the path to the blog post file
    * @return {Promise<undefined>} empty promise, returns no value
    * @instance
    */
@@ -110,9 +108,9 @@ module.exports = class Blog {
    * @return {Promise<undefined>} empty promise, returns no value
    * @instance
    */
-  async publish(bucket) {
+  async publish(host) {
 
-    internals.debuglog(`Publishing to ${bucket}`);
+    internals.debuglog(`Publishing to ${host}`);
     try {
       await internals.exec('which aws');
     }
@@ -121,8 +119,8 @@ module.exports = class Blog {
     }
 
     try {
-      await internals.exec(`aws s3 sync --acl public-read --delete ${this.staticDirectory} s3://${bucket}`);
-      await internals.exec(`aws s3 cp --content-type 'text/plain; charset=utf-8 ' --acl public-read ${this.staticDirectory}/index.txt s3://${bucket}`);
+      internals.debuglog(`Copying ephemeral blog from ${this.staticDirectory}`);
+      await internals.exec(`rsync -r ${this.staticDirectory}/ ${host}`);
     }
     catch (err) {
       console.error('Failed to publish');
@@ -153,7 +151,7 @@ module.exports = class Blog {
 
     try {
       const gemlogPath = resolve(join(__dirname, '../', '.gemlog'));
-      internals.debuglog(`Reading archive from ${gemlogPath}`);
+      internals.debuglog(`Copying archive from ${gemlogPath}`);
       await internals.exec(`rsync -r ${gemlogPath}/ ${host}`);
     }
     catch (err) {
@@ -199,6 +197,7 @@ module.exports = class Blog {
    */
   async syncDown() {
     internals.debuglog('Pulling remote state');
+    await ensureDirectoryExists(this.postsDirectory);
     await Remote.syncDown(this.remoteConfig, this.blogDirectory)
     internals.debuglog('Pulled remote state');
   }
@@ -213,6 +212,7 @@ module.exports = class Blog {
    */
   async syncUp() {
     internals.debuglog('Pushing remote state');
+    await ensureDirectoryExists(this.postsDirectory);
     await Remote.syncUp(this.remoteConfig, this.blogDirectory)
     internals.debuglog('Pushed remote state');
   }
@@ -378,18 +378,17 @@ module.exports = class Blog {
     await writeFile(metadataTarget, JSON.stringify(metadata, null, 2));
   }
 
-  // Copies a post directory to the latest slot.
+  // Copies a post file to the latest slot.
 
   async _copyPost(postLocation) {
 
+    internals.debuglog(`Copying ${postLocation}`);
     const targetPath = join(this.postsDirectory, '0');
     const postName = basename(postLocation);
     const targetPost = join(targetPath, postName);
 
-    internals.debuglog(`Removing ${targetPath}`);
     await rmIfExists(targetPath);
     await ensureDirectoryExists(targetPath);
-    internals.debuglog(`Adding ${postLocation} to ${targetPost}`);
     await cp(postLocation, targetPost, { recursive: true });
     internals.debuglog(`Added ${postLocation} to ${targetPath}`);
   }