-
Notifications
You must be signed in to change notification settings - Fork 22
Optimize docs for LLM navigation (AI SEO / llms.txt / markdown mirrors) #426
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8c82998
feat(llm): fix LLM export pipeline, sitemap hygiene, robots.txt, redi…
09837a7
feat(llm): per-page .md mirrors, generated llms.txt, JSON-LD, page me…
7764f41
feat(llm): freshness signals, content negotiation, md 404, regression…
44eabc7
docs: answer-first intros + meta descriptions for 94 pages (Codex ret…
0e509d9
chore: fix .gitignore line merge, untrack retrofit run log
f757bfe
chore: sync package-lock.json with @napi-rs/simple-git dev dependency
2e6a631
docs(studio): use Intelligent Contracts terminology, add description
b57636b
fix: dedupe llm export routes
MuncleUscles 53f0e18
docs(examples): rewrite LlmHelloWorld as salute with non-comparative EP
a0eec70
fix: address llm docs review feedback
MuncleUscles 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,30 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| // Content negotiation for AI agents: clients that explicitly ask for | ||
| // `Accept: text/markdown` on a docs page get the raw-markdown mirror | ||
| // generated by scripts/generate-full-docs.js (same content the `.md` URL | ||
| // suffix serves). Browsers never send text/markdown, so human traffic is | ||
| // unaffected. `Vary: Accept` keeps CDN caches from mixing the two. | ||
| export function middleware(req: NextRequest) { | ||
| const { pathname } = req.nextUrl; | ||
| const accept = req.headers.get("accept") || ""; | ||
|
|
||
| const isPageRoute = | ||
| !pathname.startsWith("/_next") && | ||
| !pathname.startsWith("/api") && | ||
| !/\.[a-zA-Z0-9]+$/.test(pathname); | ||
|
|
||
| if (isPageRoute && accept.includes("text/markdown")) { | ||
| const url = req.nextUrl.clone(); | ||
| url.pathname = pathname === "/" ? "/index.md" : `${pathname.replace(/\/$/, "")}.md`; | ||
| const res = NextResponse.rewrite(url); | ||
| res.headers.set("Vary", "Accept"); | ||
| return res; | ||
| } | ||
|
|
||
| const res = NextResponse.next(); | ||
| if (isPageRoute) { | ||
| res.headers.set("Vary", "Accept"); | ||
| } | ||
| return res; | ||
| } |
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.
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.
When users or crawlers hit the legacy feature overview URL, this redirect now sends them to
/developers/intelligent-contracts/features, but this commit deletedpages/developers/intelligent-contracts/features/features.mdxwithout addingpages/developers/intelligent-contracts/features/index.mdxorindex.md, so the target is not a routable Next/Nextra page. The empty:page*case for/developers/intelligent-contracts/advanced-featuresabove has the same missing target; point these overview redirects to an existing feature page or add an index page.Useful? React with 👍 / 👎.