[CMSDS-3954] Add hosted Markdown equivalents for documentation pages#3985
[CMSDS-3954] Add hosted Markdown equivalents for documentation pages#3985tamara-corbalt merged 23 commits intomainfrom
Conversation
jack-ryan-nava-pbc
left a comment
There was a problem hiding this comment.
Mostly minor stuff. I would like to see some specs added, and I'm not sure if we need error handling in place given that most of these functions are find and replace operations, but maybe worth thinking about...
derek-cmsds
left a comment
There was a problem hiding this comment.
I left some questions about some of the Markdown generation. I have one other more general question though: Is there anything in the root LLMs.txt that references these other Markdown files? How do we prompt the chatbot to visit these other paths?
Yes, good question. The change is a bit buried in this PR, but I updated the listed Urls in the root |
…eContentToAnnoations, fix casing logic and retain child text
- removeImportStatements, - stripMarkdownSections, - normalizeThemeContent, - normalizeMarkdownOutput - Adds logic to preserve code snippets
…rocessMdxForHostedMarkdown
|
|
||
| // Run this first on the whole document, since ThemeContent | ||
| // may wrap across fenced code blocks. | ||
| result = normalizeThemeContent(result); |
There was a problem hiding this comment.
With the new code-snippet-aware processing (above in processMdxOutsideCodeFences), the MDX body is split into fenced and non-fenced chunks so cleanup transforms only run on the non-fenced chunks.
Because ThemeContent can wrap both text and fenced code blocks, it must be normalized before this split. Otherwise the opening and closing tags would end up in separate chunks.
| .join('\n\n'); | ||
| }; | ||
|
|
||
| export function processMdxOutsideCodeFences(input, transform) { |
There was a problem hiding this comment.
We want to preserve non-interactive code snippets in the hosted markdown output. Otherwise, large portions of code-heavy pages like for-developers become almost meaningless.
The limitation here is that we don't yet have a reliable way to preserve interactive code examples such as <ThemeCodeBlock/>, whose rendered output changes based on the theme switcher, like this one.
derek-cmsds
left a comment
There was a problem hiding this comment.
No blockers, but I do have some questions about comments and the new doc site tests you added. Well done.
| // Unwraps simple components (e.g., Alerts, Badges) but keeps their text | ||
| chunk = unwrapSimpleComponents(chunk); | ||
| // Final cleanup: removes any remaining JSX. |
There was a problem hiding this comment.
I'm glad these comments are here. Would it make sense to document the functions in mdxToMArkdown.mjs with JSDoc comments so that devs can mouse-over them for more details?
There was a problem hiding this comment.
I appreciate these tests.
| "test:unit:coverage:wc": "npm run test:unit:wc -- --collectCoverage --coverageReporters='json-summary'", | ||
| "test:unit:coverage:all": "npm run test:unit:coverage:react && npm run test:unit:coverage:wc && tsx ./tests/unit/combineTestCoverage.ts", | ||
| "test:unit": "jest --config=tests/unit/jest.config.js", | ||
| "test:unit:docs": "npm --prefix ./packages/docs run test", |
There was a problem hiding this comment.
Should the docs tests be run when running a broader test command like npm run test or npm run test:unit? Are we adding these tests to our CI pipeline?
There was a problem hiding this comment.
Yep, I think that's a good idea to fold the new tests into the npm run test:unit script
There was a problem hiding this comment.
I may need to back out folding the docs tests into npm run test:unit and move that to a follow-up ticket. I forgot there are some downstream side effects: test:unit:coverage calls test:unit, and combineTestCoverage.ts expects a dedicated coverage artifact that no longer appears to be generated in CI.
There was a problem hiding this comment.
Added this follow up ticket: https://jira.cms.gov/browse/CMSDS-3973
jack-ryan-nava-pbc
left a comment
There was a problem hiding this comment.
A few questions and observations, but over all this looks awesome! Well done and thank you!
|
|
||
| result = processMdxOutsideCodeFences(result, (input) => { | ||
| let chunk = input; | ||
| // ⚠️ NOTE: Order matters — do not rearrange these steps. |
There was a problem hiding this comment.
Very helpful comment!
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| const require = createRequire(import.meta.url) | ||
| const normalizePagePath = (slug) => slug.replace(/\d+_/g, ''); |
There was a problem hiding this comment.
This function is actually duplicative of removePositioning, which is in the packages/docs/src/helpers/casingUtils.ts file. You should probably import and use that function instead of duplicating.
There was a problem hiding this comment.
Agree this is duplicative but Node doesn’t love that removePositioning is being imported from a .ts file inside gatsby-node.mjs.
There was a problem hiding this comment.
Does it throw an error or a type warning? I can live with a type warning (or even silence it).
There was a problem hiding this comment.
No this looks like a hard runtime failure; the build fails because node can't resolve the .ts file extension
There was a problem hiding this comment.
Alrighty, let's duplicate the function for now. Thanks for checking! Can you add a brief TODO comment pointing to the other function?
…3985) * Write md files into public folder * Add logic to strip out interative content and import lines. * Readability adjustment * Move buildMarkdownPage utility into llms-txt scripts * Refactor for readability * Small refinements to gatsby-node.mjs * Strip out Code, Examples & Maturity content sections. For convertTHemeContentToAnnoations, fix casing logic and retain child text * Rename function handling the ThemeContent logic * Fixes regex for stripMarkdoSections * Revert change to accordion.mdx * Add warning about order of operations * - Adds tests for: - removeImportStatements, - stripMarkdownSections, - normalizeThemeContent, - normalizeMarkdownOutput - Adds logic to preserve code snippets * Adds tests for unwrapSimpleComponents, normalizeMarkdownOutput, and processMdxForHostedMarkdown * Move all fixtures into dedicated fixture file * Standardize fixture variable names * Adds commands to run unit tests in docs package * Ensure html and css blocks are preserved as well * Remove extra semicolon * Adds jsdocs for mdxToMarkdown utilities * Fold docs tests into broader test command * Revert wrapping docs tests into broader test command * Adds todo
Summary
.mdxcontent into pure Markdown output during build.Jira ticket
How to test
Run docs tests
npm run test:unit:docsGenerate Hosted Markdown
cd packages/docsnpm run buildpublicdirectory:llms.txtfile alongsideindex.html.npm run start(from withinpackages/docs):npm run startfrom the repo root will rungatsby clean && gatsby develop, which clears thepublicdirectory and removes generated files.Checklist
[CMSDS-####] Titleor [NO-TICKET] if this is unticketed work.Type(only one) label for this PR, if it is a breaking change, label should only beType: BreakingImpacts, multiple can be selected.