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';
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);
try {
await this.syncDown();
}
- catch {};
- const metadata = await this._update(postLocation);
+ catch {}
+
+ await this._update(postLocation);
}
/**
* @instance
*/
async addRemote(remote) {
+
await ensureDirectoryExists(this.configDirectory);
- await Remote.add(this.remoteConfig, remote)
+ await Remote.add(this.remoteConfig, remote);
}
/**
* @instance
*/
async removeRemote() {
- await Remote.remove(this.remoteConfig)
+
+ await Remote.remove(this.remoteConfig);
}
* @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');
}
* @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');
}
try {
await this.syncUp();
}
- catch {};
+ catch {}
}
// 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.
// Moves older posts to the archive
async _archive() {
+
internals.debuglog('Archiving post');
const post = await this._readPost(0);
await ensureDirectoryExists(this.archiveDirectory);
// Gets the template directory for a given template.
async _templateDirectoryFor(template) {
+
try {
await access(join(this.templatesDirectory, template));
return this.templatesDirectory;
throw error;
}
}
-};
+}