This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
generated from Green-Software-Foundation/doc-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
277e56b
commit 97b2b71
Showing
39 changed files
with
178 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
import * as dotenv from "dotenv" | ||
dotenv.config() | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
import algoliasearch from "algoliasearch" | ||
import algoliasearch from "algoliasearch"; | ||
const client = algoliasearch( | ||
process.env.ALGOLIA_APP_ID, | ||
process.env.ALGOLIA_WRITE_API_KEY | ||
) | ||
); | ||
|
||
// 1. Build a dataset | ||
import fs from "fs" | ||
import path from "path" | ||
import matter from "gray-matter" | ||
import removeMd from "remove-markdown" | ||
import fs from "fs"; | ||
import path from "path"; | ||
import matter from "gray-matter"; | ||
import removeMd from "remove-markdown"; | ||
|
||
const filenames = fs.readdirSync(path.join("./src/pages/insights")) | ||
const data = filenames.map(filename => { | ||
try { | ||
const markdownWithMeta = fs.readFileSync("./src/pages/insights/" + filename) | ||
const { data: frontmatter, content } = matter(markdownWithMeta) | ||
return { | ||
url: filename.replace(/\.mdx$/, ''), | ||
objectID: filename.replace(/\.mdx$/, ''), | ||
title: frontmatter.title, | ||
tags: frontmatter.tags, | ||
insightNo: frontmatter.insightNo, | ||
content: removeMd(content).replace(/\n/g, ""), | ||
// Function to process files in a given insights directory | ||
function processInsightsDirectory(directory) { | ||
const filenames = fs.readdirSync(path.join(directory)); | ||
const data = filenames.map((filename) => { | ||
try { | ||
const fullPath = path.join(directory, filename); | ||
const markdownWithMeta = fs.readFileSync(fullPath); | ||
const { data: frontmatter, content } = matter(markdownWithMeta); | ||
const language = directory.split('/')[3]; | ||
return { | ||
url: filename.replace(/\.mdx?$/, ''), | ||
objectID: language + " - " + filename.replace(/\.mdx?$/, ''), | ||
title: frontmatter.title, | ||
tags: frontmatter.tags, | ||
insightNo: frontmatter.insightNo, | ||
content: removeMd(content).replace(/\n/g, ""), | ||
language | ||
}; | ||
} catch (e) { | ||
console.log(e.message); | ||
} | ||
} catch (e) { | ||
console.log(e.message) | ||
} | ||
}) | ||
}); | ||
return data; | ||
} | ||
|
||
// 1. Build datasets for each language | ||
const englishInsights = processInsightsDirectory("./src/pages/en/insights/"); | ||
const japaneseInsights = processInsightsDirectory("./src/pages/ja/insights/"); | ||
|
||
// 2. Send the dataset in JSON format | ||
// Combine the insights from both languages | ||
const combinedData = [...englishInsights, ...japaneseInsights]; | ||
|
||
// 2. Send the combined dataset in JSON format | ||
const index = client.initIndex('Insights - SoGS'); | ||
|
||
index.saveObjects(data) | ||
index.saveObjects(combinedData) | ||
.then(({ objectIDs }) => { | ||
console.log("Algolia: All records have been imported"); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.