feat(vitepress-config): Add support for downloading and organizing additional documentation from external sources
This commit is contained in:
@ -35,6 +35,12 @@ export default async () => {
|
||||
plugins.path.join(paths.docsDir, 'serve.zone'),
|
||||
);
|
||||
|
||||
await helpers.downloadReadmes(
|
||||
'https://code.foss.global',
|
||||
'social.io',
|
||||
plugins.path.join(paths.docsDir, 'social.io'),
|
||||
);
|
||||
|
||||
|
||||
return plugins.vitepress.defineConfig({
|
||||
lang: 'en-US',
|
||||
@ -80,6 +86,11 @@ export default async () => {
|
||||
items: await helpers.generateNavLinks('serve.zone'),
|
||||
collapsed: true,
|
||||
},
|
||||
{
|
||||
text: 'social.io',
|
||||
items: await helpers.generateNavLinks('social.io'),
|
||||
collapsed: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -50,6 +50,38 @@ export async function downloadReadmes(
|
||||
): Promise<void> {
|
||||
// Ensure the output directory exists
|
||||
await plugins.fs.mkdir(outputDir, { recursive: true });
|
||||
/**
|
||||
* Reads all existing .md files in the specified directory and deletes any
|
||||
* whose frontmatter has `source === "gitea"`.
|
||||
*/
|
||||
async function removeGiteaSourceFiles(dirPath: string): Promise<void> {
|
||||
try {
|
||||
const existingFiles = await plugins.fs.readdir(dirPath);
|
||||
for (const file of existingFiles) {
|
||||
if (file.endsWith('.md')) {
|
||||
const filePath = plugins.path.join(dirPath, file);
|
||||
const fileContent = await plugins.fs.readFile(filePath, 'utf8');
|
||||
|
||||
// Parse frontmatter
|
||||
const smartfmInstance = new plugins.smartfm.Smartfm({
|
||||
fmType: 'yaml'
|
||||
});
|
||||
const frontmatter = smartfmInstance.parse(fileContent);
|
||||
|
||||
// If `source` is "gitea", delete this file
|
||||
if (frontmatter.data && frontmatter.data.source === 'gitea') {
|
||||
await plugins.fs.rm(filePath);
|
||||
console.log(`Deleted file with frontmatter source === "gitea": ${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error removing files with gitea source frontmatter:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Call the function to remove existing .md files with frontmatter source === "gitea"
|
||||
await removeGiteaSourceFiles(outputDir);
|
||||
|
||||
// Helper function to construct headers
|
||||
const getHeaders = (additionalHeaders: Record<string, string> = {}) => {
|
||||
|
Reference in New Issue
Block a user