Skip to content

Commit

Permalink
Remove Algolia excluded keys (#8231)
Browse files Browse the repository at this point in the history
Signed-off-by: H. Kamran <hkamran@hkamran.com>
  • Loading branch information
hkamran80 authored Oct 24, 2024
1 parent c080e36 commit 685f7f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 6 additions & 5 deletions scripts/APIv1-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,13 @@ const generateApi = async (entries, categoriesData, regionsData) => {

// Write categories.json file
const categoriesUsed = categoriesUsedByRegion[region];
const categoriesDataForRegion = Object.fromEntries(
[...categoriesUsed]
.filter((category) => categoriesData[category])
const categoriesDataForRegion = Object.fromEntries([
...[...categoriesUsed]
.filter((category) => categoriesData[category] && category !== "other")
.sort()
.map((category) => [category, categoriesData[category]])
);
.map((category) => [category, categoriesData[category]]),
["other", categoriesData["other"]],
]);

const categoriesWrite = writeJSONFile(
path.join(regionDir, "categories.json"),
Expand Down
9 changes: 2 additions & 7 deletions scripts/Algolia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ const algoliasearch = require("algoliasearch");
const core = require("@actions/core");
require("dotenv").config(); // Load environment variables from .env file

// List of keys to exclude from the search data
const excludes = ["notes", "documentation", "recovery"];

// Initialize Algolia client and index using environment variables
const client = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY,
process.env.ALGOLIA_API_KEY
);
const index = client.initIndex(process.env.ALGOLIA_INDEX_NAME);

Expand All @@ -36,8 +33,6 @@ async function processFile(entry) {
...(categories && { category: categories }),
};

// Remove excluded keys from the data
excludes.forEach((exclude) => delete renamedData[exclude]);
return renamedData;
} else {
// If the file does not exist, remove the corresponding object from Algolia
Expand All @@ -56,7 +51,7 @@ async function main() {

// Process each file in parallel
const results = await Promise.allSettled(
files.map(async (entry) => processFile(entry)),
files.map(async (entry) => processFile(entry))
);

results.forEach((result) => {
Expand Down

0 comments on commit 685f7f6

Please sign in to comment.