8356
Wx
www-xonecas-io / files
www-xonecas-io / internal / site / seo.go
2.3 KB
1package site 2 3import ( 4 "cmp" 5 "fmt" 6 "slices" 7 "strings" 8 9 "xonecas.io/site/internal/project" 10) 11 12// BaseURL is where the site is served, for the files crawlers and agents read. 13const BaseURL = "https://xonecas.io" 14 15// SEO is robots.txt, sitemap.xml with the main pages and every project, and llms.txt, 16// a markdown map of the site and its projects for language models, by path. 17func SEO(shown []project.Project) map[string]string { 18 if len(shown) == 0 { 19 return nil 20 } 21 commits := 0 22 for _, p := range shown { 23 commits += p.Commits 24 } 25 shown = slices.Clone(shown) 26 slices.SortStableFunc(shown, func(a, b project.Project) int { return cmp.Compare(b.Last, a.Last) }) 27 var sitemap, llms strings.Builder 28 sitemap.WriteString(`<?xml version="1.0" encoding="UTF-8"?>` + "\n" + `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">` + "\n") 29 for _, p := range []string{"/", "/projects/", "/activity/"} { 30 fmt.Fprintf(&sitemap, "<url><loc>%s%s</loc></url>\n", BaseURL, p) 31 } 32 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", 33 shown[len(shown)-1].First[:4], len(shown), commits) 34 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) 35 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) 36 for _, p := range shown { 37 fmt.Fprintf(&sitemap, "<url><loc>%s/projects/%s/</loc><lastmod>%s</lastmod></url>\n", BaseURL, p.Name, p.Last) 38 about := []string{p.First + " to " + p.Last} 39 if len(p.Languages) > 0 { 40 about = append(about, p.Languages[0].Name) 41 } 42 if len(p.Topics) > 0 { 43 about = append(about, strings.Join(p.Topics, ", ")) 44 } 45 fmt.Fprintf(&llms, "- [%s](%s/projects/%s/): %s (%s)\n", p.Name, BaseURL, p.Name, cmp.Or(p.Description, "No description"), strings.Join(about, "; ")) 46 } 47 sitemap.WriteString("</urlset>\n") 48 return map[string]string{ 49 "robots.txt": "User-agent: *\nAllow: /\n\nSitemap: " + BaseURL + "/sitemap.xml\n", 50 "sitemap.xml": sitemap.String(), 51 "llms.txt": llms.String(), 52 } 53}