Skip to content

Commit

Permalink
fix: automatic metadata generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Dec 9, 2024
1 parent 0809c59 commit 4a9c593
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
4 changes: 2 additions & 2 deletions packages/akiradocs/compiled/en/articles/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"defaultRoute": "/articles/welcome",
"welcome": {
"title": "Welcome to Akira Doc",
"path": "/en/articles/welcome"
"path": "/articles/welcome"
},
"template": {
"title": "Test Blog Post",
"path": "/articles/template"
},
"ai_integration": {
"title": "Ai Integration",
"path": "/en/articles/ai_integration"
"path": "/articles/ai_integration"
}
}
2 changes: 1 addition & 1 deletion packages/akiradocs/compiled/en/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"defaultRoute": "/docs/introduction",
"introduction": {
"title": "Introduction",
"path": "/en/docs/introduction"
"path": "/docs/introduction"
},
"guides": {
"title": "Guides",
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions packages/akiradocs/compiled/en/docs/guides/_meta.json

This file was deleted.

20 changes: 10 additions & 10 deletions packages/akiradocs/public/context/en_docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[Document: docs/introduction.json]
Title: Introduction
<strong>Akira Docs</strong> is a modern documentation platform that combines the power of AI with an intuitive block-based content system. This guide will help you understand the core concepts and features.
Key Features
AI-powered search
Block-based content editing
Responsive design
Customizable themes
Markdown support
-------------
[Document: articles/welcome.json]
Title: Welcome to Akira Doc
Get started with Akira Docs - Next-gen documentation powered by AI
Expand Down Expand Up @@ -56,16 +66,6 @@ ai_assistant:
Next Steps
Explore our [Advanced AI Features](/advanced-ai-features) guide to learn more about specialized use cases and integration possibilities.
-------------
[Document: docs/introduction.json]
Title: Introduction
<strong>Akira Docs</strong> is a modern documentation platform that combines the power of AI with an intuitive block-based content system. This guide will help you understand the core concepts and features.
Key Features
AI-powered search
Block-based content editing
Responsive design
Customizable themes
Markdown support
-------------
[Document: docs/guides/analytics.json]
Title: Analytics Integration
Learn how to add analytics tracking to your documentation
Expand Down
20 changes: 10 additions & 10 deletions packages/akiradocs/scripts/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,15 @@ async function updateMetaFile(folderPath, newFile) {
.split('_')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');

const pathWithoutLang = relativePath.split(path.sep).slice(1).join(path.sep);
meta[fileName] = {
title: compiledContent.title || humanReadableFileName,
path: path.join('/', relativePath, fileName)
path: path.join('/', pathWithoutLang, fileName)
};
} else {
meta[fileName].path = path.join('/', relativePath, fileName);
const pathWithoutLang = relativePath.split(path.sep).slice(1).join(path.sep);
meta[fileName].path = path.join('/', pathWithoutLang, fileName);
}

await writeFile(metaPath, JSON.stringify(meta, null, 2));
Expand Down Expand Up @@ -281,7 +284,7 @@ async function compileMarkdownFiles() {
await mkdir(path.dirname(compiledPath), { recursive: true });
await writeFile(compiledPath, JSON.stringify(compiledContent, null, 2));

await updateMetaFile(path.dirname(compiledPath), compiledPath);
// await updateMetaFile(path.dirname(compiledPath), compiledPath);

console.log(`Compiled ${file} -> ${compiledPath}`);
}
Expand Down Expand Up @@ -315,7 +318,7 @@ async function createMetaFilesForAllFolders() {

const jsonFiles = await glob('**/*.json', {
cwd: sectionPath,
ignore: '**/_meta.json'
ignore: ['**/_meta.json']
});

const meta = {
Expand All @@ -326,7 +329,7 @@ async function createMetaFilesForAllFolders() {
const fileName = path.basename(jsonFile, '.json');
const filePath = path.join(sectionPath, jsonFile);
const content = JSON.parse(await readFile(filePath, 'utf-8'));
const dirs = path.dirname(jsonFile).split('/').filter(d => d !== '.');
const dirs = path.dirname(jsonFile).split(path.sep).filter(d => d !== '.');

const fileKey = fileName.replace(/-/g, ' ')
.split(' ')
Expand Down Expand Up @@ -371,11 +374,8 @@ async function createMetaFilesForAllFolders() {
};
}

const metaDataPath = path.join(sectionPath, '_meta.json');
if (!existsSync(metaDataPath)) {
await writeFile(metaDataPath, JSON.stringify(meta, null, 2));
console.log(`Created meta file: ${metaDataPath}`);
}
await writeFile(metaPath, JSON.stringify(meta, null, 2));
console.log(`Created/Updated meta file: ${metaPath}`);
}
}
} catch (error) {
Expand Down

0 comments on commit 4a9c593

Please sign in to comment.