Skip to content

Commit 68148a3

Browse files
committed
Add initial llms.txt
1 parent ea8cd40 commit 68148a3

File tree

7 files changed

+145
-1
lines changed

7 files changed

+145
-1
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
auto-install-peers = true
21
shamefully-hoist = true

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"astro-expressive-code": "^0.38.3",
3535
"astro-icon": "^1.1.5",
3636
"astro-seo": "^0.8.4",
37+
"handlebars": "^4.7.8",
3738
"marked": "^12.0.2",
3839
"posthog-js": "^1.266.0",
3940
"react": "^18.3.1",

pnpm-lock.yaml

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ export const startPagePath = (slug: string): string => {
1515
const pagePath = (collection: string, slug: string): string => {
1616
return `/${collection}/${slug}`;
1717
};
18+
19+
export const formatDate = (date: Date): string => {
20+
return date.toLocaleDateString("en-us", {
21+
year: "numeric",
22+
month: "long",
23+
day: "numeric",
24+
});
25+
};

src/pages/llms.txt.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { conceptPagePath, startPagePath } from "../lib/utils";
2+
import { site } from "../site";
3+
import type { APIRoute } from "astro";
4+
import { getCollection } from "astro:content";
5+
import Handlebars from "handlebars";
6+
import fs from "node:fs";
7+
import path from "node:path";
8+
9+
const { url: root, title, description: tagline, llms } = site;
10+
11+
const templateFile = fs.readFileSync(
12+
path.join(process.cwd(), "src/templates/llms.txt.hbs"),
13+
"utf-8",
14+
);
15+
16+
const template = Handlebars.compile(templateFile);
17+
18+
export const GET: APIRoute = async () => {
19+
const startPages = await getCollection("start");
20+
const conceptPages = await getCollection("concepts");
21+
22+
const content = template({
23+
root,
24+
title,
25+
tagline,
26+
description: llms.description,
27+
startPages: startPages.map(({ data: { title }, slug }) => ({
28+
title,
29+
href: `${root}/${startPagePath(slug)}`,
30+
})),
31+
conceptPages: conceptPages.map(({ data: { title }, slug }) => ({
32+
title,
33+
href: `${root}/${conceptPagePath(slug)}`,
34+
})),
35+
otherFormats: [
36+
{
37+
root,
38+
file: "llms-small.txt",
39+
description: "compact structure-only version",
40+
},
41+
{
42+
root,
43+
file: "llms-full.txt",
44+
description: "complete content in one file",
45+
},
46+
],
47+
});
48+
49+
return new Response(content, {
50+
headers: {
51+
"Content-Type": "text/plain; charset=utf-8",
52+
},
53+
});
54+
};
55+
56+
export const prerender = true;

src/site.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ type Language =
3232

3333
type Site = {
3434
title: string;
35+
url: string;
3536
description: string;
37+
llms: {
38+
description: string;
39+
};
3640
githubUrl: string;
3741
languages: Language[];
3842
defaultLanguage: Language;
@@ -49,7 +53,12 @@ type Site = {
4953

5054
export const site: Site = {
5155
title: "Zero to Nix",
56+
url: "https://zero-to-nix.com",
5257
description: "Your guide to learning Nix and flakes",
58+
llms: {
59+
description:
60+
"Zero to Nix is an opinionated learning resource for Nix created by [Determinate Systems](https://determinate.systems/llms.txt). It takes you on a [learning journey](#start-pages) from installing Nix to exploring Nix development environments to building Nix packages and more. It also offers a series of [concept pages](#concept-pages) covering some of the trickier corners of Nix.",
61+
},
5362
githubUrl: "https://github.com/DeterminateSystems/zero-to-nix",
5463
languages: ["C++", "Go", "Haskell", "JavaScript", "Python", "Rust", "Scala"],
5564
defaultLanguage: "JavaScript",

src/templates/llms.txt.hbs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# {{title}}
2+
3+
> {{tagline}}
4+
5+
{{description}}
6+
7+
## Start pages
8+
9+
{{#each startPages}}
10+
- [{{this.title}}]({{this.href}})
11+
{{/each}}
12+
13+
## Concept pages
14+
15+
{{#each conceptPages}}
16+
- [{{this.title}}]({{this.href}})
17+
{{/each}}
18+
19+
## Other formats
20+
21+
For more detailed documentation, see also:
22+
23+
{{#each otherFormats}}
24+
- [`{{this.file}}`]({{root}}/{{this.file}}) ({{this.description}})
25+
{{/each}}

0 commit comments

Comments
 (0)