]> git.r.bdr.sh - rbdr/blog/commitdiff
Lint
authorRuben Beltran del Rio <redacted>
Wed, 14 Feb 2024 16:15:11 +0000 (17:15 +0100)
committerRuben Beltran del Rio <redacted>
Wed, 14 Feb 2024 16:15:11 +0000 (17:15 +0100)
.eslintrc
config/config.js
lib/archivers/gemlog.js
lib/blog.js
lib/generators/html.js
lib/generators/rss.js
lib/generators/static.js
lib/generators/txt.js
lib/remote.js
lib/remotes/git.js
lib/utils.js

index fa9328d089f96fa48f63b13d9704a1c9472e1586..efbe3ab23ec723c3f5de43b3c859844cbcfac6ba 100644 (file)
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,7 +1,15 @@
 {
+  "root": true,
   "plugins": ["@hapi"],
+  "extends": "plugin:@hapi/recommended",
   "parserOptions": {
     "ecmaVersion": "latest",
     "sourceType": "module"
+  },
+  "rules": {
+    "indent": [
+      2,
+      2
+    ]
   }
 }
index 531f3e9358cf685a98e96f5eac4e61cad0ef4e75..cf2a386e2e38292ba2bb76f3c4c984a44ab1e930 100644 (file)
@@ -93,5 +93,5 @@ export default {
   archiveOutputDirectory: resolve(join(internals.outputDirectory, 'archive')),
 
   // Internal config: This can't be modified.
-  defaultTemplatesDirectory: resolve(join(__dirname, '../templates')),
+  defaultTemplatesDirectory: resolve(join(__dirname, '../templates'))
 };
index d56a1f6d4c647f45609f34118d943aa24743b1a8..1bb0c10d6d31740c930c09e29436018c0abc142a 100644 (file)
@@ -11,22 +11,26 @@ const internals = {
   debuglog: debuglog('blog'),
 
   buildUrl(id, slug) {
+
     return `./${id}/${slug}`;
   },
 
-  buildTitle (id, slug) {
+  buildTitle(id, slug) {
+
     const date = new Date(Number(id));
-    const shortDate = date.toISOString().split('T')[0]
+    const shortDate = date.toISOString().split('T')[0];
     const title = slug.split('-').join(' ');
-    return `${shortDate} ${title}`
+    return `${shortDate} ${title}`;
   },
 
   buildLink(id, slug) {
+
     return `=> ${internals.buildUrl(id,slug)} ${internals.buildTitle(id,slug)}`;
   }
 };
 
-export default async function(templateDirectory, source, target) {
+export default async function (templateDirectory, source, target) {
+
   internals.debuglog(`Reading archive ${source}`);
   const postIds = (await readdir(source))
     .sort((a, b) => Number(b) - Number(a));
@@ -34,10 +38,10 @@ export default async function(templateDirectory, source, target) {
   for (const id of postIds) {
     const postDirectory = join(source, id);
     const slug = (await readdir(postDirectory))
-        .filter((entry) => internals.kGeminiRe.test(entry))[0];
+      .filter((entry) => internals.kGeminiRe.test(entry))[0];
 
-      posts.push({ id, slug })
-  };
+    posts.push({ id, slug });
+  }
 
   internals.debuglog(`Read ${posts.length} posts`);
 
@@ -52,7 +56,7 @@ export default async function(templateDirectory, source, target) {
     ...Dot.templateSettings,
     strip: false
   })({
-    posts: posts.map((post) => internals.buildLink(post.id, post.slug)).join('\n'),
+    posts: posts.map((post) => internals.buildLink(post.id, post.slug)).join('\n')
   });
 
   try {
@@ -68,4 +72,4 @@ export default async function(templateDirectory, source, target) {
     internals.debuglog('Copying posts to archive');
     await cp(source, target, { recursive: true });
   }
-};
+}
index 04106b0a57cb8be39d69ee741595caabf00063e4..e1a76a8d848e2803d6f116495307f7d66698d8c3 100644 (file)
@@ -1,6 +1,6 @@
 import { access, cp, readdir, readFile, writeFile } from 'fs/promises';
 import { exec } from 'child_process';
-import { basename, resolve, join } from 'path';
+import { basename, join } from 'path';
 import ParseGemini from 'gemini-to-html/parse.js';
 import RenderGemini from 'gemini-to-html/render.js';
 import { debuglog, promisify } from 'util';
@@ -72,9 +72,10 @@ export default class Blog {
     try {
       await this.syncDown();
     }
-    catch {};
+    catch {}
+
     await this._shift();
-    const firstDirectory = join(this.postsDirectory, '0'); 
+    const firstDirectory = join(this.postsDirectory, '0');
     await rmIfExists(firstDirectory);
     await ensureDirectoryExists(firstDirectory);
     await this._update(postLocation);
@@ -94,8 +95,9 @@ export default class Blog {
     try {
       await this.syncDown();
     }
-    catch {};
-    const metadata = await this._update(postLocation);
+    catch {}
+
+    await this._update(postLocation);
   }
 
   /**
@@ -168,8 +170,9 @@ export default class Blog {
    * @instance
    */
   async addRemote(remote) {
+
     await ensureDirectoryExists(this.configDirectory);
-    await Remote.add(this.remoteConfig, remote)
+    await Remote.add(this.remoteConfig, remote);
   }
 
   /**
@@ -181,7 +184,8 @@ export default class Blog {
    * @instance
    */
   async removeRemote() {
-    await Remote.remove(this.remoteConfig)
+
+    await Remote.remove(this.remoteConfig);
   }
 
 
@@ -194,9 +198,10 @@ export default class Blog {
    * @instance
    */
   async syncDown() {
+
     internals.debuglog('Pulling remote state');
     await ensureDirectoryExists(this.dataDirectory);
-    await Remote.syncDown(this.remoteConfig, this.dataDirectory)
+    await Remote.syncDown(this.remoteConfig, this.dataDirectory);
     internals.debuglog('Pulled remote state');
   }
 
@@ -209,9 +214,10 @@ export default class Blog {
    * @instance
    */
   async syncUp() {
+
     internals.debuglog('Pushing remote state');
     await ensureDirectoryExists(this.dataDirectory);
-    await Remote.syncUp(this.remoteConfig, this.dataDirectory)
+    await Remote.syncUp(this.remoteConfig, this.dataDirectory);
     internals.debuglog('Pushed remote state');
   }
 
@@ -230,7 +236,7 @@ export default class Blog {
     try {
       await this.syncUp();
     }
-    catch {};
+    catch {}
   }
 
 
@@ -288,27 +294,28 @@ export default class Blog {
 
   // Reads an individual post
 
-  async _readPost(index=0) {
-      const postSourcePath = join(this.postsDirectory, `${index}`);
+  async _readPost(index = 0) {
 
-      internals.debuglog(`Reading ${postSourcePath}`);
+    const postSourcePath = join(this.postsDirectory, `${index}`);
 
-      await access(postSourcePath);
+    internals.debuglog(`Reading ${postSourcePath}`);
 
-      const metadata = await this._getMetadata(index);
+    await access(postSourcePath);
 
-      const postContentPath = await this._findBlogContent(postSourcePath);
-      internals.debuglog(`Reading ${postContentPath}`);
-      const postContent = await readFile(postContentPath, { encoding: 'utf8' });
+    const metadata = await this._getMetadata(index);
 
-      internals.debuglog('Parsing Gemini');
-      return {
-        ...metadata,
-        location: postSourcePath,
-        index,
-        html: RenderGemini(ParseGemini(postContent)),
-        raw: postContent
-      };
+    const postContentPath = await this._findBlogContent(postSourcePath);
+    internals.debuglog(`Reading ${postContentPath}`);
+    const postContent = await readFile(postContentPath, { encoding: 'utf8' });
+
+    internals.debuglog('Parsing Gemini');
+    return {
+      ...metadata,
+      location: postSourcePath,
+      index,
+      html: RenderGemini(ParseGemini(postContent)),
+      raw: postContent
+    };
   }
 
   // Shift the posts, delete any remainder.
@@ -342,6 +349,7 @@ export default class Blog {
   // Moves older posts to the archive
 
   async _archive() {
+
     internals.debuglog('Archiving post');
     const post = await this._readPost(0);
     await ensureDirectoryExists(this.archiveDirectory);
@@ -423,6 +431,7 @@ export default class Blog {
 
   // Gets the template directory for a given template.
   async _templateDirectoryFor(template) {
+
     try {
       await access(join(this.templatesDirectory, template));
       return this.templatesDirectory;
@@ -436,4 +445,4 @@ export default class Blog {
       throw error;
     }
   }
-};
+}
index f7c7966b08da7af556377a04954de87898ee1847..20046962ce29416bd8b190c38ef4b71ff64552f2 100644 (file)
@@ -1,5 +1,3 @@
-'use strict';
-
 import Dot from 'dot';
 import { readFile, writeFile } from 'fs/promises';
 import { join } from 'path';
@@ -34,5 +32,4 @@ export default async function HTMLGenerator(source, target, posts) {
     strip: false
   })({ posts });
   await writeFile(indexTarget, indexHtml);
-};
-
+}
index a46a394f1f6a1c74b4ab72fcc2edd1d5d1a38b3d..c47ba038ea1ccd3c81849af42cce8bca04fb8b68 100644 (file)
@@ -1,5 +1,3 @@
-'use strict';
-
 import Dot from 'dot';
 import { encodeXML } from 'entities';
 import { readFile, writeFile } from 'fs/promises';
@@ -50,4 +48,4 @@ export default async function RSSGenerator(source, target, posts) {
     strip: false
   })({ posts });
   await writeFile(feedTarget, feedXml);
-};
+}
index 60719e2ef5ee7e1fbe7159a92c321da7b1f6b7d9..45f5a04ed1c1a763bc8e6b128ac5c6a80984934a 100644 (file)
@@ -1,5 +1,3 @@
-'use strict';
-
 import { access, cp, readdir } from 'fs/promises';
 import { constants } from 'fs';
 import { join } from 'path';
@@ -33,7 +31,8 @@ export default async function StaticGenerator(source, target, _) {
 
       if (entry.isDirectory()) {
         await cp(sourceAsset, targetAsset, { recursive: true });
-      } else {
+      }
+      else {
         await cp(sourceAsset, targetAsset);
       }
     }
@@ -46,4 +45,4 @@ export default async function StaticGenerator(source, target, _) {
 
     throw error;
   }
-};
+}
index dddcbafae55d87a7332ddac8a998425457b02946..c3d777806f85b56520dc77fa7920f9153420ff39 100644 (file)
@@ -1,5 +1,3 @@
-'use strict';
-
 import Dot from 'dot';
 import { readFile, writeFile } from 'fs/promises';
 import { join } from 'path';
@@ -34,4 +32,4 @@ export default async function TXTGenerator(source, target, posts) {
     strip: false
   })({ posts });
   await writeFile(textTarget, text);
-};
+}
index 780ea91ba3493d6d46360179aa546b6e23d49e1a..ad0a4fc77f2a71aa64dd8bd6856957c21708caa3 100644 (file)
@@ -54,4 +54,4 @@ export default {
       throw new Error(internals.strings.configurationNotFound);
     }
   }
-}
+};
index f6d0c07838e3f44769de6aea73a473b9003011c2..75ef43ede2864ca68cd7070107abe9fa972bd42f 100644 (file)
@@ -3,7 +3,7 @@ import { promisify } from 'util';
 
 const internals = {
   // Promisified functions
-  exec: promisify(exec),
+  exec: promisify(exec)
 };
 
 export default {
@@ -28,7 +28,8 @@ export default {
       await internals.exec(`cd ${blogDirectory} && git checkout .`);
     }
     catch {}
+
     await internals.exec(`cd ${blogDirectory} && git clean . -f`);
     await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`);
   }
-}
+};
index 25d204a727743345d96a323a323cbbca11940da4..cee3f4708ad110f83fcbc01dadb2c7695c5a83b1 100644 (file)
@@ -3,7 +3,7 @@ import { kFileNotFoundError } from './constants.js';
 
 // File system utilities
 
-export async function rmIfExists(location) {
+export const rmIfExists = async function rmIfExists(location) {
 
   try {
     await access(location, constants.F_OK);
@@ -16,9 +16,9 @@ export async function rmIfExists(location) {
 
     throw error;
   }
-}
+};
 
-export async function ensureDirectoryExists(directory) {
+export const ensureDirectoryExists = async function ensureDirectoryExists(directory) {
 
   try {
     await access(directory);
@@ -31,4 +31,4 @@ export async function ensureDirectoryExists(directory) {
 
     throw error;
   }
-}
+};