all repos — homestead @ 0a5f1b4df8306eaa0d752767f444becf8efa991f

Code for my website

use pointer to config in builder & templates

Alan Pearce
commit

0a5f1b4df8306eaa0d752767f444becf8efa991f

parent

b38e78e775d934fbfd3303b635042d98cac57891

M internal/atom/atom.gointernal/atom/atom.go
@@ -7,7 +7,7 @@
"website/internal/config" ) -func MakeTagURI(config config.Config, specific string) string { +func MakeTagURI(config *config.Config, specific string) string { return "tag:" + config.OriginalDomain + "," + config.DomainStartDate + ":" + specific }
M internal/builder/builder.gointernal/builder/builder.go
@@ -86,7 +86,7 @@
return nil } -func build(outDir string, config config.Config) (*Result, error) { +func build(outDir string, config *config.Config) (*Result, error) { log.Debug("output", "dir", outDir) r := &Result{ Hashes: make([]string, 0),
@@ -252,16 +252,19 @@
return r, nil } -func BuildSite(ioConfig IOConfig) (*Result, error) { - config, err := config.GetConfig() - if err != nil { - return nil, errors.WithMessage(err, "could not get config") +func BuildSite(ioConfig IOConfig, cfg *config.Config) (*Result, error) { + if cfg == nil { + var err error + cfg, err = config.GetConfig() + if err != nil { + return nil, errors.WithMessage(err, "could not get config") + } } - config.InjectLiveReload = ioConfig.Development + cfg.InjectLiveReload = ioConfig.Development compressFiles = !ioConfig.Development templates.Setup() loadCSS() - return build(ioConfig.Destination, *config) + return build(ioConfig.Destination, cfg) }
M internal/builder/template.gointernal/builder/template.go
@@ -66,7 +66,7 @@ func (q *QueryDocument) Find(selector string) *QuerySelection {
return &QuerySelection{q.Document.Find(selector)} } -func renderRobotsTXT(config config.Config) (io.Reader, error) { +func renderRobotsTXT(config *config.Config) (io.Reader, error) { r, w := io.Pipe() tpl, err := template.ParseFiles("templates/robots.tmpl") if err != nil {
@@ -87,7 +87,7 @@ }
func renderFeed( title string, - config config.Config, + config *config.Config, posts []content.Post, specific string, ) (io.Reader, error) {
M internal/server/server.gointernal/server/server.go
@@ -108,7 +108,7 @@ })
} func rebuild(builderConfig builder.IOConfig, config *cfg.Config) error { - r, err := builder.BuildSite(builderConfig) + r, err := builder.BuildSite(builderConfig, config) if err != nil { return errors.WithMessage(err, "could not build site") }
M internal/sitemap/sitemap.gointernal/sitemap/sitemap.go
@@ -13,9 +13,9 @@ config *config.Config
Sitemap *sitemap.Sitemap } -func New(cfg config.Config) *Sitemap { +func New(cfg *config.Config) *Sitemap { return &Sitemap{ - config: &cfg, + config: cfg, Sitemap: sitemap.New(), } }
M internal/website/mux.gointernal/website/mux.go
@@ -50,7 +50,7 @@ }()
if err := fn.handler(w, r); err != nil { if strings.Contains(r.Header.Get("Accept"), "text/html") { w.WriteHeader(err.Code) - err := templates.Error(*fn.config, r.URL.Path, err).Render(r.Context(), w) + err := templates.Error(fn.config, r.URL.Path, err).Render(r.Context(), w) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) }
M templates/error.templtemplates/error.templ
@@ -6,7 +6,7 @@ "website/internal/http"
"strconv" ) -templ Error(config config.Config, path string, err *http.Error) { +templ Error(config *config.Config, path string, err *http.Error) { @Page(config, PageSettings{ Title: "Error", Path: path,
M templates/homepage.templtemplates/homepage.templ
@@ -5,7 +5,7 @@ "website/internal/config"
"website/internal/content" ) -templ Homepage(config config.Config, posts []content.Post, content string) { +templ Homepage(config *config.Config, posts []content.Post, content string) { @Page(config, PageSettings{ Title: config.Title, TitleAttrs: templ.Attributes{
M templates/list.templtemplates/list.templ
@@ -5,7 +5,7 @@ "website/internal/config"
"website/internal/content" ) -templ TagPage(config config.Config, tag string, posts []content.Post, path string) { +templ TagPage(config *config.Config, tag string, posts []content.Post, path string) { @Page(config, PageSettings{ Title: tag, Path: path,
@@ -24,7 +24,7 @@ @list(posts)
} } -templ ListPage(config config.Config, posts []content.Post, path string) { +templ ListPage(config *config.Config, posts []content.Post, path string) { @Page(config, PageSettings{ Title: config.Title, TitleAttrs: templ.Attributes{
M templates/page.templtemplates/page.templ
@@ -43,7 +43,7 @@ }
>{ item.Name }</a> } -templ Page(site config.Config, page PageSettings) { +templ Page(site *config.Config, page PageSettings) { <!DOCTYPE html> <html lang={ site.DefaultLanguage }> <head>
M templates/post.templtemplates/post.templ
@@ -19,7 +19,7 @@ { d.Format("2006-01-02") }
</time> } -templ PostPage(config config.Config, post content.Post) { +templ PostPage(config *config.Config, post content.Post) { @Page(config, PageSettings{ Title: post.Title, TitleAttrs: templ.Attributes{
M templates/tags.templtemplates/tags.templ
@@ -6,7 +6,7 @@ templ tagLink(tag string, attrs templ.Attributes) {
<a { attrs... } href={ templ.SafeURL("/tags/" + tag) }>#{ tag }</a> } -templ TagsPage(config config.Config, title string, tags []string, path string) { +templ TagsPage(config *config.Config, title string, tags []string, path string) { @Page(config, PageSettings{ Title: title, Path: path,