Remix向けllms.txt
Remix には2つの方法があります。public/ に設定不要の静的ファイルを置く方法と、app/routes/llms[.]txt.ts にリソースルートを作成してプレーンテキストの Response を返す方法です。後者では、必要に応じてコンテンツから生成できます。
最終更新:
オプション 1:public/ 内の静的ファイル
Remixは public/ サイトのルートディレクトリに静的に配置してください。 ファイルを以下の場所に配置してください
public/llms.txt、ルーティング設定は不要です。
# Remix static file approach
#
# Place your file at: public/llms.txt
# Remix (and the underlying Node/Cloudflare/Vercel adapter)
# serves everything in public/ at the root of your site.
#
# Project structure:
# your-remix-app/
# ├── public/
# │ └── llms.txt ← add this
# ├── app/
# └── remix.config.js (or vite.config.ts)
この方法はすべての Remix アダプターで動作します: @remix-run/node, @remix-run/cloudflare, @remix-run/vercel、および @remix-run/netlify。静的ファイルは、一致するルートより優先されます。
選択肢2:リソースルート
リソースルートを作成する: app/routes/llms[.]txt.ts。 [.] 構文はファイル名のドットをエスケープするため、RemixはそれをURLパス /llms.txt。 loader 正しい Content-Type を持つ Response を返す関数。 Response 正しい
Content-Type.
// app/routes/llms[.]txt.ts
// Remix resource route, the [.] escapes the dot in the filename
// This file is served at exactly /llms.txt
import type { LoaderFunctionArgs } from '@remix-run/node';
export async function loader({ request }: LoaderFunctionArgs) {
const content = `# Your Site
> One-sentence description of what your site or product does.
## Documentation
- [Getting Started](https://yoursite.com/docs/start): Install and configure.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog.
## Product
- [Overview](https://yoursite.com/product): Features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing.
## Optional
- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
`;
return new Response(content, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}
コンテンツ層から動的に生成するには、loaderでドキュメントを取得し、Markdownのリンク一覧をプログラムで構築します:
// app/routes/llms[.]txt.ts
// Generate from your content / MDX files
import type { LoaderFunctionArgs } from '@remix-run/node';
import { getAllDocs } from '~/models/docs.server';
export async function loader({ request }: LoaderFunctionArgs) {
// Fetch your documentation index from a DB or file system
const docs = await getAllDocs();
const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com/docs/${doc.slug}/): ${doc.summary}`)
.join('\n');
const body = [
'# Your Site',
'',
'> One-sentence summary of your project.',
'',
'## Documentation',
'',
links,
].join('\n');
return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}
Viteプラグインによるアプローチ
RemixでVite(Remix v2.7+のデフォルト)を使う場合、 llms.txt を Vite プラグインでビルドの一部として生成できます。生成されたファイルは ビルド出力ディレクトリに配置され、静的アセットとして提供されます。これにより、静的ファイルの簡便さと
ビルド時のコンテンツアクセスを両立できます。
import { vitePlugin as remix } from '@remix-run/dev';
import { defineConfig } from 'vite';
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
// Simple Vite plugin to generate llms.txt at build time
function llmsTxtPlugin() {
return {
name: 'generate-llms-txt',
buildStart() {
const content = `# Your Site\n\n> Summary.\n\n## Documentation\n\n- [Docs](https://yoursite.com/docs): Guide.\n`;
writeFileSync(resolve(__dirname, 'public/llms.txt'), content, 'utf-8');
},
};
}
export default defineConfig({
plugins: [remix(), llmsTxtPlugin()],
}); 検証
デプロイ後、ファイルが正しく配信されていることを確認します:
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8
curl https://yoursite.com/llms.txt | head -5 関連ガイド
- llms.txtの作成方法、テンプレート、チェックリスト。
- llms.txt フォーマットリファレンス、仕様の詳細。
- Vercelガイド、Remix を Vercel にデプロイします。
- Cloudflare Pages ガイド, CloudflareでのRemix。
- バリデータ · ジェネレーター.