all repos — homestead @ a3ad47b3eb74f281df9f5d3c733fd60c56f5c462

Code for my website

fix static file access in docker

Alan Pearce
commit

a3ad47b3eb74f281df9f5d3c733fd60c56f5c462

parent

fb8cdcbd48543e800aa0f69b9264a09abef86d75

A cmd/server/kodata/feed-styles.xsl
@@ -0,0 +1,1 @@
+../../../templates/feed-styles.xsl
A cmd/server/kodata/robots.tmpl
@@ -0,0 +1,1 @@
+../../../templates/robots.tmpl
A cmd/server/kodata/style.css
@@ -0,0 +1,1 @@
+../../../templates/style.css
M fly.tomlfly.toml
@@ -17,6 +17,7 @@ SERVER_TLS = "true"
POWERDNS_SERVER_URL = "https://pdns.alanpearce.eu" # POWERDNS_API_TOKEN = "from fly secret" WEBSITE_SOURCE = "/data/website" + WEBSITE_DESTINATION = "/data/public" WEBSITE_VCS_REMOTE_URL = "https://git.alanpearce.eu/website.git" GOMEMLIMIT = "128MiB" REDIS_ADDRESS = "redis.alanpearce.eu:6379"
M internal/builder/builder.gointernal/builder/builder.go
@@ -268,9 +268,6 @@ return nil, errors.New("config is nil")
} cfg.InjectLiveReload = options.Development - templates.Setup() - loadCSS() - storage, err := files.NewWriter(options.Destination, log, &files.Options{ Compress: !options.Development, })
M internal/builder/template.gointernal/builder/template.go
@@ -4,13 +4,13 @@ import (
"bytes" "encoding/xml" "io" - "os" "strings" "text/template" "go.alanpearce.eu/website/internal/atom" "go.alanpearce.eu/website/internal/config" "go.alanpearce.eu/website/internal/content" + "go.alanpearce.eu/website/templates" "github.com/PuerkitoBio/goquery" "github.com/antchfx/xmlquery"
@@ -19,7 +19,6 @@ "gitlab.com/tozd/go/errors"
) var ( - css string nsMap = map[string]string{ "xsl": "http://www.w3.org/1999/XSL/Transform", "atom": "http://www.w3.org/2005/Atom",
@@ -27,14 +26,6 @@ "xhtml": "http://www.w3.org/1999/xhtml",
} ) -func loadCSS() { - bytes, err := os.ReadFile("templates/style.css") - if err != nil { - panic(err) - } - css = string(bytes) -} - type QuerySelection struct { *goquery.Selection }
@@ -55,7 +46,7 @@ }
func renderRobotsTXT(config *config.Config) (io.Reader, error) { r, w := io.Pipe() - tpl, err := template.ParseFiles("templates/robots.tmpl") + tpl, err := template.ParseFS(templates.Files, "robots.tmpl") if err != nil { return nil, err }
@@ -118,13 +109,14 @@ return buf, nil
} func renderFeedStyles() (*strings.Reader, error) { - tpl, err := template.ParseFiles("templates/feed-styles.xsl") + tpl, err := template.ParseFS(templates.Files, "feed-styles.xsl") if err != nil { return nil, err } esc := &strings.Builder{} - err = xml.EscapeText(esc, []byte(css)) + err = xml.EscapeText(esc, []byte(templates.CSS)) + if err != nil { return nil, err }
M internal/website/mux.gointernal/website/mux.go
@@ -98,8 +98,6 @@ Development: opts.Development,
Destination: opts.Destination, } - templates.Setup() - repo, err, exists := vcs.CloneOrOpen(&vcs.Options{ LocalPath: opts.Source, RemoteURL: opts.VCS.RemoteURL,
D templates/dev.go
@@ -1,9 +0,0 @@
-//go:build !embed - -package templates - -import ( - "os" -) - -var Files = os.DirFS("templates/")
A templates/files.go
@@ -0,0 +1,15 @@
+package templates + +import ( + "os" +) + +var Files = os.DirFS(getEnvFallback("KO_DATA_PATH", "cmd/server/kodata")) + +func getEnvFallback(key, fallback string) string { + if value, found := os.LookupEnv(key); found { + return value + } + + return fallback +}
M templates/page.templtemplates/page.templ
@@ -9,15 +9,15 @@ "net/url"
) var ( - css string + CSS string ) -func Setup() { +func init() { bytes, err := fs.ReadFile(Files, "style.css") if err != nil { panic(err) } - css = string(bytes) + CSS = string(bytes) } type PageSettings struct {
@@ -52,7 +52,7 @@ <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>{ page.Title }</title> <link rel="alternate" type="application/atom+xml" title={ site.Title } href="/atom.xml"/> - @style(css) + @style(CSS) </head> <body { page.BodyAttrs... }> <a class="skip" href="#main">Skip to main content</a>