Skip to content

feat: serve pages as markdown and update llms.txt (#2249) - #2289

Merged
kaankacar merged 5 commits into
mainfrom
2249-serve-pages-as-markdown-and-update-llmstxt-to-reference-them
Jun 17, 2026
Merged

kaankacar merged 5 commits into
mainfrom
2249-serve-pages-as-markdown-and-update-llmstxt-to-reference-them

Conversation

@kaankacar

Copy link
Copy Markdown
Contributor
  • Installed docusaurus-markdown-source-plugin to inject "Open Markdown" dropdown on every /docs/ page linking to currentPath + .md
  • Added nginx location block to intercept .md URLs, strip the extension, and proxy to developers.stellar.org with Accept: text/markdown header
  • Updated static/llms.txt to document the .md URL scheme and Accept header

Copilot AI review requested due to automatic review settings March 2, 2026 19:32
@kaankacar kaankacar linked an issue Mar 2, 2026 that may be closed by this pull request
@socket-security

socket-security Bot commented Mar 2, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addeddocusaurus-markdown-source-plugin@​2.2.57410010092100

View full report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “markdown view” pathway for Stellar developer docs so tooling/LLMs can retrieve page content as Markdown via a .md URL pattern (and documents the behavior in llms.txt).

Changes:

  • Add docusaurus-markdown-source-plugin and enable it in Docusaurus config.
  • Add an nginx rule to intercept *.md requests and proxy to the corresponding non-.md path with Accept: text/markdown.
  • Update static/llms.txt to describe the .md URL scheme and header-based access.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Adds docusaurus-markdown-source-plugin dependency.
yarn.lock Locks the new plugin and its dependency tree.
docusaurus.config.ts Enables the markdown-source plugin in the Docusaurus plugins list.
nginx/nginx.conf Proxies *.md requests to the corresponding page with Accept: text/markdown.
static/llms.txt Documents the Markdown access pattern for consumers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread nginx/nginx.conf Outdated
Comment on lines +36 to +40
location ~* ^(.+)\.md$ {
resolver 1.1.1.1 valid=300s;
proxy_pass https://developers.stellar.org$1;
proxy_set_header Accept "text/markdown";
proxy_set_header Host "developers.stellar.org";

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex location will be considered against all requests ending in .md (including under /assets/, /img/, etc.) and can override the existing prefix locations because they aren't marked ^~. To avoid unexpected proxying of static paths, scope the match to the intended docs routes (e.g., only /docs/...\.md$) and/or mark the static prefix locations as ^~ so they always win.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scoped the regex to /docs/ only in a follow-up commit

Comment thread nginx/nginx.conf Outdated
add_header 'Cache-Control' 'no-store' always;
}
location ~* ^(.+)\.md$ {
resolver 1.1.1.1 valid=300s;

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolver 1.1.1.1 hard-codes a public DNS resolver. This can break in restricted networks and may violate infra/security expectations; prefer using the environment's DNS (or a configurable internal resolver) and consider defining it at the http {} level to keep resolver policy centralized.

Suggested change
resolver 1.1.1.1 valid=300s;

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolver is required here, nginx won't resolve the hostname in proxy_pass without an explicit resolver directive. Removing it would break the proxy entirely. 1.1.1.1 is intentional for this public-facing deployment is what i see. @ElliotFriend thoughts?

Comment thread static/llms.txt
Comment on lines +4 to +6
Each documentation page is available as clean markdown by appending `.md` to the URL
(e.g. `https://developers.stellar.org/docs/build/smart-contracts/overview.md`).
Alternatively, send an `Accept: text/markdown` request header to any page URL to receive markdown without modifying the URL.

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llms.txt claims that sending Accept: text/markdown to any page URL returns markdown, but the nginx config in this repo only forces that header when a .md URL is requested (and otherwise serves static HTML). Either adjust this wording to match the actual behavior, or add server/CDN logic to honor Accept: text/markdown on normal page URLs.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The accept: text/markdown behavior is handled by Cloudflare in front of this nginx. Tt already performs the HTML-to-markdown conversion when it sees that header, for any page URL. The nginx config in this repo only needs to handle the .md URL scheme (which it does by stripping .md and setting the header before passing to Cloudflare)

@ElliotFriend
ElliotFriend self-requested a review March 3, 2026 17:06
2 similar comments
@kaankacar kaankacar self-assigned this Mar 31, 2026
1 similar comment
- Install docusaurus-markdown-source-plugin (v2.2.4) to inject "Open
  Markdown" dropdown on every /docs/ page and generate static .md files
  at build time for all .md and .mdx source pages
- Update static/llms.txt to document the .md URL scheme and list all
  pages with .md URLs, including new Building with AI page
@kaankacar
kaankacar force-pushed the 2249-serve-pages-as-markdown-and-update-llmstxt-to-reference-them branch from 7488704 to cffb2be Compare April 28, 2026 21:57
1 similar comment
@kaankacar

Copy link
Copy Markdown
Contributor Author

Hey @ElliotFriend , In line with our last conversation I revised the approach to solely rely on the plugin and dropped the nginx proxy block entirely. The .md files are now generated statically at build time and served directly from disk.

- main migrated yarn -> pnpm; resolve the yarn.lock modify/delete conflict
  by removing yarn.lock and adding the plugin to pnpm-lock.yaml
- bump docusaurus-markdown-source-plugin floor ^2.0.1 -> ^2.2.4 (first
  version with .mdx source support); lock resolves to 2.2.5
The markdown-source plugin emits .md twins of docs pages but leaves
intra-doc links pointing at source .mdx paths, which 404 when followed
(only the .md twin is served). Add a postbuild step that rewrites those
links to their .md twin — inside generated build/**/*.md only.

- scripts/rewrite_md_links.mjs: filesystem-verified rewrite that only
  changes a link when the target .md twin actually exists, so it can never
  introduce a broken link. Handles the plugin's README->parent collapse and
  section-index depth via a per-file resolution-base vote. Touches generated
  .md artifacts exclusively: never a source file, never HTML (verified
  byte-identical before/after).
- package.json: wire it as the postbuild hook so it runs automatically after
  'pnpm build' in CI and the Docker production build.
Switch the post-build link rewrite from relative paths (../../foo.md) to
full canonical URLs (https://developers.stellar.org/docs/foo.md) so the .md
twins are self-contained for agents/LLMs and consistent with static/llms.txt.
Origin and baseUrl are read from docusaurus.config.ts (single source of truth).

Still output-only (HTML verified byte-identical) and idempotent — full-URL
links are skipped as external on re-runs.

@ElliotFriend ElliotFriend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super cool!!!

@kaankacar
kaankacar merged commit 36f43c9 into main Jun 17, 2026
9 checks passed
@kaankacar
kaankacar deleted the 2249-serve-pages-as-markdown-and-update-llmstxt-to-reference-them branch June 17, 2026 12:22
zachfedor pushed a commit to zachfedor/stellar-docs that referenced this pull request Jun 18, 2026
…llar#2289)

* feat: serve pages as markdown and update llms.txt (stellar#2249)

- Install docusaurus-markdown-source-plugin (v2.2.4) to inject "Open
  Markdown" dropdown on every /docs/ page and generate static .md files
  at build time for all .md and .mdx source pages
- Update static/llms.txt to document the .md URL scheme and list all
  pages with .md URLs, including new Building with AI page

* trigger preview rebuild

* Rewrite intra-doc links to .md in generated markdown twins

The markdown-source plugin emits .md twins of docs pages but leaves
intra-doc links pointing at source .mdx paths, which 404 when followed
(only the .md twin is served). Add a postbuild step that rewrites those
links to their .md twin — inside generated build/**/*.md only.

- scripts/rewrite_md_links.mjs: filesystem-verified rewrite that only
  changes a link when the target .md twin actually exists, so it can never
  introduce a broken link. Handles the plugin's README->parent collapse and
  section-index depth via a per-file resolution-base vote. Touches generated
  .md artifacts exclusively: never a source file, never HTML (verified
  byte-identical before/after).
- package.json: wire it as the postbuild hook so it runs automatically after
  'pnpm build' in CI and the Docker production build.

* Emit full canonical URLs for rewritten markdown links

Switch the post-build link rewrite from relative paths (../../foo.md) to
full canonical URLs (https://developers.stellar.org/docs/foo.md) so the .md
twins are self-contained for agents/LLMs and consistent with static/llms.txt.
Origin and baseUrl are read from docusaurus.config.ts (single source of truth).

Still output-only (HTML verified byte-identical) and idempotent — full-URL
links are skipped as external on re-runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serve pages as markdown and update llms.txt to reference them

4 participants