Skip to content

Commit

Permalink
feat: added a frontmatter reporting step to algolia indexing (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrymatio authored Jul 22, 2023
1 parent 85f2c90 commit 76853ce
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions packages/gatsby-theme-aio/algolia/index-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ function indexRecords() {
allFile: { nodes },
},
}) {

let productIndexMap;
try {
const result = await axios.get("https://raw.githubusercontent.com/AdobeDocs/search-indices/main/product-index-map.json");
const result = await axios.get(
'https://raw.githubusercontent.com/AdobeDocs/search-indices/main/product-index-map.json'
);
productIndexMap = result.data;
} catch (error) {
console.error(`AIO: Failed fetching search index.\n${error}`)
console.error(`AIO: Failed fetching search index.\n${error}`);
process.exit();
}

const productFromPath = productIndexMap.find(prod => {
return prod.productIndices.some(index => {
return index.indexPathPrefix.includes(pathPrefix)
})
return index.indexPathPrefix.includes(pathPrefix);
});
});

const markdownFiles = [];
Expand Down Expand Up @@ -75,14 +76,35 @@ function indexRecords() {
});
}

// markdownFiles frontmatter report - start

console.log('\x1b[35m ==== FRONTMATTER REPORT - STARTING ==================== \x1b[0m');
console.info('\x1b[36m [cmd + click] on the file path to open \x1b[0m');

markdownFiles.forEach(file => {
if (!file.description || !file.keywords || !file.title) {
console.log('\n\x1b[41mFail\x1b[0m - ' + file.fileAbsolutePath + ': ');
if (!file.title) console.log('\x1b[33m\tMissing Title \x1b[0m');
if (!file.description) console.log('\x1b[33m\tMissing Description \x1b[0m');
if (!file.keywords) console.log('\x1b[33m\tMissing Keywords \x1b[0m');
} else {
console.log('\x1b[42mPass\x1b[0m - ' + file.fileAbsolutePath);
}
});

console.log('\x1b[35m ==== FRONTMATTER REPORT - FINISHED ==================== \x1b[0m');

// markdownFiles frontmatter report - end

const algoliaRecords = [];

for (const markdownFile of markdownFiles) {
// Get source content
const htmlContent =
(await getImportedContent(markdownFile)) ??
(await getIFrameContent(markdownFile)) ??
(await getOpenApiContent(markdownFile)) ?? {};
(await getOpenApiContent(markdownFile)) ??
{};

// Create 'raw' records from content
let rawRecords =
Expand Down

0 comments on commit 76853ce

Please sign in to comment.