DEV Community

Vinci Rufus
Vinci Rufus

Posted on

Genereate LLMs.txt for your Astro site

Llms.txt are now becoming the standard way to help AI chatbots like ChatGPT, and Perplexity to easily find your content.

The easiest way to generate this file in your astro project is by creating a pages/llms.txt file with the following content

import { getCollection } from "astro:content";
import type { APIRoute } from "astro";

export const GET: APIRoute = async () => {
    const posts = await getCollection("blog"); // adjust "blog" to your collection name
    const content = `# Vinci Rufus Blog\n
    ${posts
            .map(
                (post) =>
                    `# ${post.data.title}\n\n
                https://www.vincirufus.com/postss/${post.slug}.md \n
                ${post.data.description} \n
                  ${post.body}
                }`
            )
            .join("\n\n")}`;
    return new Response(content, {
        headers: { "Content-Type": "text/plain; charset=utf-8" },
    });
};
Enter fullscreen mode Exit fullscreen mode

and then just build your application using the usual commands.
Read the full article here Generating llms.txt file for your astro site

Top comments (0)