Accounting for indexed posts.
This commit is contained in:
parent
029351f228
commit
86002ef00b
|
@ -25,8 +25,8 @@ function curatePost(acc, post, user, index, processed, args) {
|
||||||
hash: hashPost(post),
|
hash: hashPost(post),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user.indexed.find(entry => entry.id === post.id)) {
|
if (user.indexed.original.find(entry => entry.id === post.id)) {
|
||||||
return { ...acc, indexed: { ...acc.indexed, [post.id]: curatedPost } };
|
return { ...acc, indexedUpdated: [...acc.indexedUpdated, curatedPost] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// cut-off at limit, but don't count posts requested directly by ID
|
// cut-off at limit, but don't count posts requested directly by ID
|
||||||
|
@ -73,16 +73,16 @@ function curatePost(acc, post, user, index, processed, args) {
|
||||||
const curatePosts = (userPosts, args) => Object.values(userPosts).reduce((accPosts, user) => {
|
const curatePosts = (userPosts, args) => Object.values(userPosts).reduce((accPosts, user) => {
|
||||||
const processed = new Set();
|
const processed = new Set();
|
||||||
|
|
||||||
const { posts, indexed } = user.posts.reduce((accUserPosts, post, index) =>
|
const { posts, indexedUpdated } = user.posts.reduce((accUserPosts, post, index) =>
|
||||||
curatePost(accUserPosts, post, user, index, processed, args), { posts: [], indexed: {} });
|
curatePost(accUserPosts, post, user, index, processed, args), { posts: [], indexedUpdated: [] });
|
||||||
|
|
||||||
const indexedLength = Object.keys(indexed).length;
|
if (indexedUpdated.length > 0) {
|
||||||
|
console.log('\x1b[33m%s\x1b[0m', `Ignoring ${indexedUpdated.length} indexed posts for '${user.name}'`);
|
||||||
if (indexedLength > 0) {
|
|
||||||
console.log('\x1b[33m%s\x1b[0m', `Ignoring ${indexedLength} indexed posts for '${user.name}'`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...accPosts, [user.name]: { ...user, posts } };
|
const indexedOriginal = user.indexed.original.filter(entry => !indexedUpdated.find(post => post.id === entry.id));
|
||||||
|
|
||||||
|
return { ...accPosts, [user.name]: { ...user, posts, indexed: { original: indexedOriginal, updated: indexedUpdated } } };
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
module.exports = curatePosts;
|
module.exports = curatePosts;
|
||||||
|
|
|
@ -5,7 +5,6 @@ const path = require('path');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const dateFns = require('date-fns');
|
const dateFns = require('date-fns');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
const dotty = require('dotty');
|
|
||||||
|
|
||||||
function interpolate(pattern, user, post, item, strip = true, dateFormat = config.library.dateFormat) {
|
function interpolate(pattern, user, post, item, strip = true, dateFormat = config.library.dateFormat) {
|
||||||
const vars = {
|
const vars = {
|
||||||
|
|
|
@ -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
|
// 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
|
// 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 originalEntries = user.indexed.original.map(entry => yaml.safeDump([entry]));
|
||||||
const newEntries = posts.map(post => yaml.safeDump([{
|
const newAndUpdatedEntries = posts.concat(user.indexed.updated).map(post => yaml.safeDump([{
|
||||||
id: post.id,
|
id: post.id,
|
||||||
subreddit: post.subreddit,
|
subreddit: post.subreddit,
|
||||||
permalink: post.permalink,
|
permalink: post.permalink,
|
||||||
|
@ -24,7 +24,7 @@ async function writeToIndex(posts, user) {
|
||||||
title: post.title,
|
title: post.title,
|
||||||
}]));
|
}]));
|
||||||
|
|
||||||
const entries = newEntries.concat(oldEntries).join('\n');
|
const entries = newAndUpdatedEntries.concat(originalEntries).join('\n');
|
||||||
|
|
||||||
return fs.writeFile(filename, entries);
|
return fs.writeFile(filename, entries);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ function getUserPostsWrap(reddit, args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (posts.length) {
|
if (posts.length) {
|
||||||
return { ...user, posts, indexed };
|
return { ...user, posts, indexed: { original: indexed, updated: [] } };
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue