X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/6cd62e795e3716aa0cbd2d1ff8c1b3a345803563..refs/heads/rust:/lib/blog.js diff --git a/lib/blog.js b/lib/blog.js index 04106b0..e1a76a8 100644 --- a/lib/blog.js +++ b/lib/blog.js @@ -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; } } -}; +}