Skip to content

Commit 9fdfa55

Browse files
committed
Finish first pass at templates
1 parent 68148a3 commit 9fdfa55

File tree

8 files changed

+205
-4
lines changed

8 files changed

+205
-4
lines changed

.github/workflows/update-flake-lock.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ jobs:
5959
committer: github-actions[bot] github-actions[bot]@users.noreply.github.com
6060
assignees: lucperkins
6161
reviewers: lucperkins
62-
labels:
63-
automated
62+
labels: automated
6463
templates
6564
update
6665
body: |

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pnpm-lock.yaml
77
**/*.mdx
88
src/components/Posthog.astro
99
**/*.lock
10+
**/*.hbs

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
overrides:
2-
devalue@<5.3.2: '>=5.3.2'
2+
devalue@<5.3.2: ">=5.3.2"

src/pages/llms-full.txt.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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-full.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+
system:
26+
"This is the complete documentation for Zero to Nix, including the learning journey (start) and concept pages.",
27+
instructions:
28+
"Learning journey (start) and concept page items begin and end with a --- and all page titles are in bold.",
29+
tagline,
30+
description: llms.description,
31+
startPages: startPages.map(({ data: { title }, slug, body }) => ({
32+
title,
33+
href: `${root}/${startPagePath(slug)}`,
34+
content: body,
35+
})),
36+
conceptPages: conceptPages.map(({ data: { title }, slug, body }) => ({
37+
title,
38+
href: `${root}/${conceptPagePath(slug)}`,
39+
content: body,
40+
})),
41+
otherFormats: [
42+
{
43+
root,
44+
file: "llms.txt",
45+
description: "the main version",
46+
},
47+
{
48+
root,
49+
file: "llms-full.txt",
50+
description: "complete content in one file",
51+
},
52+
],
53+
});
54+
55+
return new Response(content, {
56+
headers: {
57+
"Content-Type": "text/plain; charset=utf-8",
58+
},
59+
});
60+
};
61+
62+
export const prerender = true;

src/pages/llms-small.txt.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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, llms } = site;
10+
11+
const templateFile = fs.readFileSync(
12+
path.join(process.cwd(), "src/templates/llms-small.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+
description: llms.description,
26+
startPages: startPages.map(({ data: { title } }) => ({
27+
title,
28+
})),
29+
conceptPages: conceptPages.map(({ data: { title } }) => ({
30+
title,
31+
})),
32+
otherFormats: [
33+
{
34+
root,
35+
file: "llms.txt",
36+
description: "the main version",
37+
},
38+
{
39+
root,
40+
file: "llms-full.txt",
41+
description: "complete content in one file",
42+
},
43+
],
44+
});
45+
46+
return new Response(content, {
47+
headers: {
48+
"Content-Type": "text/plain; charset=utf-8",
49+
},
50+
});
51+
};
52+
53+
export const prerender = true;

src/templates/llms-full.txt.hbs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<SYSTEM>{{system}}</SYSTEM>
2+
3+
<INSTRUCTIONS>{{instructions}}</INSTRUCTIONS>
4+
5+
# {{title}}
6+
7+
> {{tagline}}
8+
9+
{{description}}
10+
11+
## Start pages
12+
13+
---
14+
15+
{{#each startPages}}
16+
**{{{this.title}}}**
17+
18+
Published: {{this.date}}
19+
URL: {{this.href}}
20+
21+
{{{this.content}}}
22+
23+
{{#unless @last}}
24+
---
25+
26+
{{/unless}}
27+
{{/each}}
28+
---
29+
30+
## Concept pages
31+
32+
---
33+
34+
{{#each conceptPages}}
35+
**{{{this.title}}}**
36+
37+
Published: {{this.date}}
38+
URL: {{this.href}}
39+
40+
{{{this.content}}}
41+
42+
{{#unless @last}}
43+
---
44+
45+
{{/unless}}
46+
{{/each}}
47+
---
48+
49+
## Other formats
50+
51+
For other documentation formats, see also:
52+
53+
{{#each otherFormats}}
54+
- [`{{this.file}}`]({{root}}/{{this.file}}) ({{this.description}})
55+
{{/each}}

src/templates/llms-small.txt.hbs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# {{title}}
2+
3+
{{description}}
4+
5+
## Start pages These pages take you on a Nix journey from installing Nix through
6+
accomplishing meaningful tasks with Nix:
7+
8+
{{#each startPages}}
9+
- {{this.title}}
10+
{{/each}}
11+
12+
## Concept pages These pages provide a more theoretical take on some of the
13+
trickier corners of Nix:
14+
15+
{{#each conceptPages}}
16+
- {{this.title}}
17+
{{/each}}
18+
19+
## Other formats
20+
21+
For other documentation formats, see also:
22+
23+
{{#each otherFormats}}
24+
- [`{{this.file}}`]({{root}}/{{this.file}}) ({{this.description}})
25+
{{/each}}

src/templates/llms.txt.hbs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66

77
## Start pages
88

9+
These pages take you on a Nix journey from installing Nix through
10+
accomplishing meaningful tasks with Nix:
11+
912
{{#each startPages}}
1013
- [{{this.title}}]({{this.href}})
1114
{{/each}}
1215

1316
## Concept pages
1417

18+
These pages provide a more theoretical take on some of the
19+
trickier corners of Nix:
20+
1521
{{#each conceptPages}}
1622
- [{{this.title}}]({{this.href}})
1723
{{/each}}
1824

1925
## Other formats
2026

21-
For more detailed documentation, see also:
27+
For other documentation formats, see also:
2228

2329
{{#each otherFormats}}
2430
- [`{{this.file}}`]({{root}}/{{this.file}}) ({{this.description}})

0 commit comments

Comments
 (0)