folderToDocuments(linksPath).toArray(data => { fs.writeFile(dataPath, JSON.stringify(data), () => { console.log('Successfully saved data!'); }); });
_(sections) .map(section => section.replace(/\r/g, '')) .filter(section => section && section.length > 0 && section.replace(/\n/g, '').length > 0) .map(text => ({text, filename})) .flatMap(({text, filename}) => { const [, episodeName] = /\d+-\d+-(.+?)\./.exec(filename); const [name, linksText] = text.split(/:\n/g); if (!linksText) { console.error('Error processing file:', filename, 'section:', text); return _([]); return _(links) .filter(l => l && l.length > 0) .map(link => { const urls = extractLinks(link); const title = link }); }) .filter(result => result)
const run = async () => { await folderToDocuments(linksPath, {arrayMod}) .each(result => index.addDoc(result)) .toPromise(Promise); console.log('Successfully generated index!'); let shouldThrow = false; const res = await fileToContent(lastFile, linksPath) .flatMap(content => fileToDocuments(content)) .flatMap(doc => { const titleRes = findInTitles(doc.title, index); const urlsRes = findInUrls(doc.urls, index); return _([]); }; return _([possibleDuplicate]); }) .filter(result => result) .each(duplicate => { if (duplicate.levels.includes('error')) { shouldThrow = true; .done(() => { if (shouldThrow) { throw new Error('Possible duplicate detected!');