-
Notifications
You must be signed in to change notification settings - Fork 45
feat: generate markdown static files for LLM agent token optimization #2862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattheworiordan
wants to merge
5
commits into
main
Choose a base branch
from
markdown-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f15fee
feat: generate markdown static files for LLM agent token optimization
mattheworiordan 2fbeaff
refactor: address Copilot PR feedback
mattheworiordan 979a8d3
fix: resolve markdown generation issues
mattheworiordan 8f10806
refactor: improve code quality in markdown generation
mattheworiordan 7dcc0d3
refactor: improve markdown file structure and validator
mattheworiordan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Validates that markdown files exist for all HTML pages in the public directory. | ||
| * This script ensures the markdown generation process completed successfully. | ||
| */ | ||
|
|
||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import fastGlob from 'fast-glob'; | ||
|
|
||
| const publicDir = path.join(process.cwd(), 'public', 'docs'); | ||
|
|
||
| interface ValidationResult { | ||
| totalPages: number; | ||
| markdownFound: number; | ||
| markdownMissing: number; | ||
| redirectPages: number; | ||
| missingFiles: string[]; | ||
| } | ||
|
|
||
| const validateMarkdownFiles = async (): Promise<ValidationResult> => { | ||
| // Find all index.html files in the docs directory | ||
| const htmlFiles = await fastGlob('**/index.html', { | ||
| cwd: publicDir, | ||
| absolute: false, | ||
| }); | ||
|
|
||
| const result: ValidationResult = { | ||
| totalPages: htmlFiles.length, | ||
| markdownFound: 0, | ||
| markdownMissing: 0, | ||
| redirectPages: 0, | ||
| missingFiles: [], | ||
| }; | ||
|
|
||
| for (const htmlFile of htmlFiles) { | ||
| // Get the directory of the HTML file | ||
| const dir = path.dirname(htmlFile); | ||
|
|
||
| // Check if this is a redirect page (skip validation for these) | ||
| const htmlPath = path.join(publicDir, htmlFile); | ||
| const htmlContent = fs.readFileSync(htmlPath, 'utf8'); | ||
|
|
||
| if (htmlContent.length < 1000 && htmlContent.includes('window.location.href')) { | ||
| result.redirectPages++; | ||
| continue; // Skip redirect pages | ||
| } | ||
|
|
||
| // Check if corresponding markdown file exists | ||
| const markdownFile = path.join(publicDir, dir, 'index.md'); | ||
|
|
||
| if (fs.existsSync(markdownFile)) { | ||
| result.markdownFound++; | ||
|
|
||
| // Verify the markdown file has content | ||
| const stats = fs.statSync(markdownFile); | ||
| if (stats.size === 0) { | ||
| console.warn(`⚠️ Warning: ${dir}/index.md is empty`); | ||
| } | ||
| } else { | ||
| result.markdownMissing++; | ||
| result.missingFiles.push(dir); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const main = async () => { | ||
| console.log('🔍 Validating markdown files...\n'); | ||
|
|
||
| if (!fs.existsSync(publicDir)) { | ||
| console.error(`❌ Error: Public docs directory not found: ${publicDir}`); | ||
| console.error(' Make sure to run this script after the build process.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| const result = await validateMarkdownFiles(); | ||
|
|
||
| console.log(`📊 Validation Results:`); | ||
| console.log(` Total HTML pages: ${result.totalPages}`); | ||
| console.log(` 🔀 Redirect pages (skipped): ${result.redirectPages}`); | ||
| console.log(` 📄 Content pages: ${result.totalPages - result.redirectPages}`); | ||
| console.log(` ✅ Markdown files found: ${result.markdownFound}`); | ||
| console.log(` ❌ Markdown files missing: ${result.markdownMissing}`); | ||
|
|
||
| if (result.markdownMissing > 0) { | ||
| console.log('\n⚠️ Missing markdown files:'); | ||
| result.missingFiles.slice(0, 10).forEach((file) => { | ||
| console.log(` - ${file}/index.md`); | ||
| }); | ||
|
|
||
| if (result.missingFiles.length > 10) { | ||
| console.log(` ... and ${result.missingFiles.length - 10} more`); | ||
| } | ||
|
|
||
| console.log('\n❌ Validation failed: Some markdown files are missing.'); | ||
| console.log(' This may indicate an issue with the markdown generation process.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Calculate coverage percentage | ||
| const coverage = (result.markdownFound / result.totalPages) * 100; | ||
| console.log(`\n✅ Validation passed! Markdown coverage: ${coverage.toFixed(1)}%`); | ||
| } catch (error) { | ||
| console.error('❌ Error during validation:', error); | ||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| main(); | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More relevant for the generation script, but, and this is grounded more in my own opinion than anything,
/docs/thing/index.mdis less ergonomic to me than/docs/thing.md. We get away with it with HTML, but having "index" in a URL is a dated practice.If you agree, the upshot is that the only thing that would need to happen is to rename the generated MD file and move it a directory up
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh, it's a bit shit, but I really didn't think it mattered because in practice a) who is reading Markdown files in their browser, b) the website is using an Accept header. I can change it, but it feels like a low importance change.