@@ -0,0 +1,60 @@
1+package site
2+
3+import (
4+ "cmp"
5+ "fmt"
6+ "os"
7+ "path/filepath"
8+ "slices"
9+ "strings"
10+
11+ "xonecas.io/site/internal/project"
12+)
13+
14+// BaseURL is where the site is served, for the files crawlers and agents read.
15+const BaseURL = "https://xonecas.io"
16+
17+// writeSEO writes robots.txt, sitemap.xml with the main pages and every project, and llms.txt,
18+// a markdown map of the site and its projects for language models.
19+func writeSEO(out string, shown []project.Project) error {
20+ if len(shown) == 0 {
21+ return nil
22+ }
23+ commits := 0
24+ for _, p := range shown {
25+ commits += p.Commits
26+ }
27+ shown = slices.Clone(shown)
28+ slices.SortStableFunc(shown, func(a, b project.Project) int { return cmp.Compare(b.Last, a.Last) })
29+ var sitemap, llms strings.Builder
30+ sitemap.WriteString(`<?xml version="1.0" encoding="UTF-8"?>` + "\n" + `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">` + "\n")
31+ for _, p := range []string{"/", "/projects/", "/activity/"} {
32+ fmt.Fprintf(&sitemap, "<url><loc>%s%s</loc></url>\n", BaseURL, p)
33+ }
34+ fmt.Fprintf(&llms, "# xonecas.io\n\n> Every public project by Sean Caetano Martin (xonecas, sacenox) since %s: %d projects and %d commits, read-only.\n\n",
35+ shown[len(shown)-1].First[:4], len(shown), commits)
36+ fmt.Fprintf(&llms, "- [Overview](%s/): totals and every month of commits\n- [Projects](%[1]s/projects/): all projects, filterable by tag, topic, date and name\n- [Activity](%[1]s/activity/): my commits by year, newest first\n\n", BaseURL)
37+ fmt.Fprintf(&llms, "Each project has its files and README at /projects/<name>/, its history at /projects/<name>/commits/, and clones with `git clone %s/<name>.git`.\n\n## Projects\n\n", BaseURL)
38+ for _, p := range shown {
39+ fmt.Fprintf(&sitemap, "<url><loc>%s/projects/%s/</loc><lastmod>%s</lastmod></url>\n", BaseURL, p.Name, p.Last)
40+ about := []string{p.First + " to " + p.Last}
41+ if len(p.Languages) > 0 {
42+ about = append(about, p.Languages[0].Name)
43+ }
44+ if len(p.Topics) > 0 {
45+ about = append(about, strings.Join(p.Topics, ", "))
46+ }
47+ fmt.Fprintf(&llms, "- [%s](%s/projects/%s/): %s (%s)\n", p.Name, BaseURL, p.Name, cmp.Or(p.Description, "No description"), strings.Join(about, "; "))
48+ }
49+ sitemap.WriteString("</urlset>\n")
50+ for name, text := range map[string]string{
51+ "robots.txt": "User-agent: *\nAllow: /\n\nSitemap: " + BaseURL + "/sitemap.xml\n",
52+ "sitemap.xml": sitemap.String(),
53+ "llms.txt": llms.String(),
54+ } {
55+ if err := os.WriteFile(filepath.Join(out, name), []byte(text), 0o644); err != nil {
56+ return err
57+ }
58+ }
59+ return nil
60+}