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));
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`);
...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 {
internals.debuglog('Copying posts to archive');
await cp(source, target, { recursive: true });
}
-};
+}
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;
}
}
-};
+}