about summary refs log tree commit diff stats
path: root/internal/builder/template.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-29 16:48:40 +0200
committerAlan Pearce2024-06-29 16:48:40 +0200
commitb4095d108a2646bcf9e7fff64788b10d9bce8da3 (patch)
treef45554857a3128922b665ab0fb04150380c0d44e /internal/builder/template.go
parente8221541404a8d2ca0758d48ba5fe9c85f9067ac (diff)
downloadwebsite-b4095d108a2646bcf9e7fff64788b10d9bce8da3.tar.lz
website-b4095d108a2646bcf9e7fff64788b10d9bce8da3.tar.zst
website-b4095d108a2646bcf9e7fff64788b10d9bce8da3.zip
build outside of working directory
Diffstat (limited to 'internal/builder/template.go')
-rw-r--r--internal/builder/template.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/internal/builder/template.go b/internal/builder/template.go
index d46844d..0be3214 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -27,8 +27,8 @@ var (
 	}
 )
 
-func loadCSS() {
-	bytes, err := os.ReadFile("templates/style.css")
+func loadCSS(source string) {
+	bytes, err := os.ReadFile(filepath.Join(source, "templates/style.css"))
 	if err != nil {
 		panic(err)
 	}
@@ -66,9 +66,9 @@ func (q *QueryDocument) Find(selector string) *QuerySelection {
 	return &QuerySelection{q.Document.Find(selector)}
 }
 
-func renderRobotsTXT(config *config.Config) (io.Reader, error) {
+func renderRobotsTXT(source string, config *config.Config) (io.Reader, error) {
 	r, w := io.Pipe()
-	tpl, err := template.ParseFiles("templates/robots.tmpl")
+	tpl, err := template.ParseFiles(filepath.Join(source, "templates/robots.tmpl"))
 	if err != nil {
 		return nil, err
 	}
@@ -86,12 +86,13 @@ func renderRobotsTXT(config *config.Config) (io.Reader, error) {
 }
 
 func renderFeed(
+	source string,
 	title string,
 	config *config.Config,
 	posts []content.Post,
 	specific string,
 ) (io.Reader, error) {
-	reader, err := loadTemplate("templates/feed.xml")
+	reader, err := loadTemplate(filepath.Join(source, "templates/feed.xml"))
 	if err != nil {
 		return nil, err
 	}
@@ -153,8 +154,8 @@ func renderFeed(
 	return strings.NewReader(doc.OutputXML(true)), nil
 }
 
-func renderFeedStyles() (*strings.Reader, error) {
-	tpl, err := template.ParseFiles("templates/feed-styles.xsl")
+func renderFeedStyles(source string) (*strings.Reader, error) {
+	tpl, err := template.ParseFiles(filepath.Join(source, "templates/feed-styles.xsl"))
 	if err != nil {
 		return nil, err
 	}