Accounting for indexed posts.

This commit is contained in:
2018-06-30 21:47:43 +02:00
parent 74e36a6826
commit a859ac573c
4 changed files with 13 additions and 14 deletions

View File

@@ -12,8 +12,8 @@ async function writeToIndex(posts, user) {
// Individual posts are wrapped in [] to get a YAML array value for each individual item, allowing them to be joined manually with a newline
// between each entry to improve human readability of the index while maintaining a valid YAML list
const oldEntries = user.indexed.map(entry => yaml.safeDump([entry]));
const newEntries = posts.map(post => yaml.safeDump([{
const originalEntries = user.indexed.original.map(entry => yaml.safeDump([entry]));
const newAndUpdatedEntries = posts.concat(user.indexed.updated).map(post => yaml.safeDump([{
id: post.id,
subreddit: post.subreddit,
permalink: post.permalink,
@@ -24,7 +24,7 @@ async function writeToIndex(posts, user) {
title: post.title,
}]));
const entries = newEntries.concat(oldEntries).join('\n');
const entries = newAndUpdatedEntries.concat(originalEntries).join('\n');
return fs.writeFile(filename, entries);
}