Skip to content

Commit d823900

Browse files
committed
feat: enhanced llms.txt support
1 parent 1c06ae5 commit d823900

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

docs/hugo.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ hasCJKLanguage: true
1414

1515
outputs:
1616
home: [html, llms]
17-
page: [html]
18-
section: [html, rss]
17+
page: [html, markdown]
18+
section: [html, markdown, rss]
1919

2020
defaultContentLanguage: en
2121
languages:

hugo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
baseName = 'llms'
99
mediaType = 'text/plain'
1010
isPlainText = true
11+
[outputFormats.markdown]
12+
name = 'Markdown'
13+
baseName = 'index.html'

layouts/list.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# {{ .Title }}
2+
{{ .RawContent | htmlUnescape }}

layouts/llms.txt

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,49 @@
22

33
> {{ .Site.Params.description }}
44

5-
{{ range $section := site.Sections }}
6-
{{- template "llms-section-tree" dict "context" . "level" 2 }}
7-
{{ end }}
5+
{{- if and (not .Params.llmsTxtOptional) (gt (len .Pages) 0) }}
6+
{{- $sortedSections := sort .Site.Sections "Title" }}
7+
{{- range $sortedSections }}
8+
{{- $allSections := slice . -}}
9+
{{- range .Sections -}}
10+
{{- if not .Params.llmsTxtOptional -}}
11+
{{- $allSections = $allSections | append . -}}
12+
{{- end -}}
13+
{{- end -}}
14+
{{- $sortedAllSections := sort $allSections "Title" -}}
15+
{{- range $sortedAllSections }}
816

9-
{{- $rootPages := where site.RegularPages "Section" "" }}
10-
{{- if $rootPages }}
17+
## {{ .Title }}
18+
{{- $pages := sort .Pages "Title" "asc" }}
19+
{{- range $pages }}
20+
- [{{ .Title }}]({{ .Permalink }}index.html.md): {{ .Summary | plainify | truncate 100 | strings.TrimSpace }}{{ if .Date }} - Published {{ .Date.Format "2006-01-02" }}{{ end }}
21+
{{- end }}
22+
{{- end }}
23+
{{- end }}
1124

12-
## Root Pages
13-
{{- range $rootPages }}
14-
- [{{ .Title }}]({{ .Permalink }}): {{ .Summary | plainify | truncate 100 | strings.TrimSpace }}{{ if .Date }} - Published {{ .Date.Format "2006-01-02" }}{{ end }}
25+
## Optional
26+
{{- range .Site.Sections }}
27+
{{- if .Params.llmsTxtOptional }}
28+
{{- $pages := sort .Pages "Title" "asc" }}
29+
{{- range $pages }}
30+
- [{{ .Title }}]({{ .Permalink }}index.html.md){{ with .Description }}: {{ . }}{{ end }}
1531
{{- end }}
1632
{{- end }}
33+
{{- range .Sections }}
34+
{{- if .Params.llmsTxtOptional }}
35+
{{- $pages := sort .Pages "Title" "asc" }}
36+
{{- range $pages }}
37+
- [{{ .Title }}]({{ .RelPermalink }}index.html.md){{ with .Description }}: {{ . }}{{ end }}
38+
{{- end }}
39+
{{- end }}
40+
{{- end }}
41+
{{- end }}
42+
{{- else -}}
43+
{{- .RawContent | .Page.RenderString -}}
44+
{{- end -}}
45+
{{- "\n" -}}
46+
{{- "\n" -}}
1747

1848
---
1949
Generated on {{ now.Format "2006-01-02 15:04:05 UTC" }}
2050
Site: {{ .Site.BaseURL }}
21-
22-
{{- define "llms-section-tree" -}}
23-
{{- $context := .context -}}
24-
{{- $level := .level | default 2 -}}
25-
{{- $headerHashes := strings.Repeat $level "#" -}}
26-
{{- "\n" -}}
27-
{{ $headerHashes }} {{ $context.Title }}
28-
29-
{{- range $context.RegularPages }}
30-
- [{{ .Title }}]({{ .Permalink }}): {{ .Summary | plainify | truncate 100 | strings.TrimSpace }}{{ if .Date }} - Published {{ .Date.Format "2006-01-02" }}{{ end }}
31-
{{- end }}
32-
33-
{{- range $context.Sections }}
34-
{{ template "llms-section-tree" dict "context" . "level" (add $level 1) }}
35-
{{- end }}
36-
{{- end -}}

layouts/single.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# {{ .Title }}
2+
{{ .RawContent | htmlUnescape }}

0 commit comments

Comments
 (0)