Next.js 向け

Next.js の AIエージェント対応ガイド

App Router を使った Next.js なら、47項目をほぼ全て pass させられます。`/llms.txt`, `/sitemap.xml`, Markdown ミラー、JSON-LD、content negotiation、全部 App Router の慣用パターンで書けます。

技術担当が直接コードを触れる前提なら、Grade A を取りに行く最短経路。YomuScore 自体も Next.js 15 App Router で実装しています。

1

app/llms.txt/route.ts で llms.txt を動的生成

S1S2S3

`app/llms.txt/route.ts` を作り、`GET` ハンドラから `new NextResponse(body, { headers: { 'Content-Type': 'text/plain' } })` を返します。body は `# サイト名` + blockquote + `## カテゴリ別セクション` + markdown リンクのテンプレート。コンテンツは Markdown ファイルから動的にビルドするか、静的に文字列で書く。`force-static` を付ければビルド時に静的化されます。

2

app/sitemap.ts で lastmod 付き sitemap.xml

S8S9

Next.js は `app/sitemap.ts` を作るだけで `/sitemap.xml` を自動配信します。各 URL に `lastModified` フィールドを Date オブジェクトで返せば `<lastmod>` も自動付与され、S8 / S9 が同時に pass します。

3

Layout.tsx に JSON-LD を inline で埋め込む

P10P11

`app/layout.tsx` の `<head>` 内に `<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />` を追加します (next/script ではなく素の <script> タグであることが重要 — script コンポーネントは afterInteractive 等のデフォルトでクライアント側に移動するため、初期 HTML に出ない)。YomuScore 自身もこのパターンで P10 / P11 を pass しています。

4

Markdown ミラー + content negotiation

P15P17P19P20

実装は (1) `app/[...slug]/page.tsx` の隣に `app/[...slug]/route.ts` を置き、Accept ヘッダで切り分ける、(2) リバースプロキシ (Caddy/Nginx) 側で `Accept: text/markdown` のとき `/{path}.md` にリライトする、の2択。簡単なのは後者。YomuScore は Caddy で `@accept-md header Accept *text/markdown* → rewrite path /{path}.md` を使っています。

5

<link rel='alternate'> を全ページで出す

P17

`app/layout.tsx` の `metadata.alternates.types['text/markdown']` を設定するだけで、Next.js が自動で `<link rel="alternate" type="text/markdown" href="...">` を出力します。

まずは現状スコアを把握する

上記の手順を当てる前に、サイトの現在のスコアと fail 項目を一覧で確認すると、どこから手を付ければインパクトが大きいかが分かります。47項目のスキャンは登録不要・無料で1日 5 回まで実行できます。

無料で診断する →

他の CMS のガイド