Added option to index (specified) ignored posts. Saving index through save module, and it now notifies the user that an index has been written.

This commit is contained in:
2018-07-07 02:17:41 +02:00
parent fd4fe8a0c5
commit d9ce4dd056
6 changed files with 30 additions and 19 deletions

View File

@@ -1,16 +1,17 @@
'use strict';
const config = require('config');
const fs = require('fs-extra');
const yaml = require('js-yaml');
const interpolate = require('../interpolate.js');
const interpolate = require('../interpolate');
const textToStream = require('./textToStream');
const save = require('./save');
async function writeToIndex(posts, profilePaths, user) {
const filename = interpolate(config.library.index.file, user, null, false);
async function writeToIndex(posts, profilePaths, user, args) {
const filepath = interpolate(config.library.index.file, user, null, false);
const now = new Date();
const newAndUpdatedEntries = posts.concat(user.indexed.updated).map((post) => {
const newAndUpdatedEntries = posts.concat(user.indexed.updated, args.indexIgnored ? user.indexed.ignored : []).map((post) => {
const entryPost = {
id: post.id,
subreddit: post.subreddit,
@@ -41,7 +42,7 @@ async function writeToIndex(posts, profilePaths, user) {
return;
}
return fs.writeFile(filename, yaml.safeDump(data));
return save(filepath, textToStream(yaml.safeDump(data)));
}
module.exports = writeToIndex;