about summary refs log tree commit diff stats
path: root/internal/builder/template.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-05 22:15:05 +0200
committerAlan Pearce2024-06-05 22:15:05 +0200
commita9337d346ca6d82bbe203d50b176af9b7c146db0 (patch)
tree324818852995470cb4833bb6fe79dfead3d17957 /internal/builder/template.go
parentab5a866278bec429657b61bf0d0a370757b5e922 (diff)
downloadwebsite-a9337d346ca6d82bbe203d50b176af9b7c146db0.tar.lz
website-a9337d346ca6d82bbe203d50b176af9b7c146db0.tar.zst
website-a9337d346ca6d82bbe203d50b176af9b7c146db0.zip
generate sitemap and robots.txt
Diffstat (limited to 'internal/builder/template.go')
-rw-r--r--internal/builder/template.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/builder/template.go b/internal/builder/template.go
index 5e2af1a..ab36c85 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -8,6 +8,7 @@ import (
 	"os"
 	"strings"
 	"sync"
+	"text/template"
 	"time"
 	"website/internal/atom"
 	"website/internal/config"
@@ -295,6 +296,24 @@ func renderHomepage(config config.Config, posts []Post, url string) (io.Reader,
 	return renderHTML(doc), nil
 }
 
+func renderRobotsTXT(config config.Config) (io.Reader, error) {
+	r, w := io.Pipe()
+	tpl, err := template.ParseFiles("templates/robots.tmpl")
+	if err != nil {
+		return nil, err
+	}
+	go func() {
+		err = tpl.Execute(w, map[string]interface{}{
+			"BaseURL": config.BaseURL,
+		})
+		if err != nil {
+			w.CloseWithError(err)
+		}
+		w.Close()
+	}()
+	return r, nil
+}
+
 func render404(config config.Config, url string) (io.Reader, error) {
 	doc, err := layout("templates/404.html", config, "404 Not Found", url)
 	if err != nil {