refactor: make templates take a more specific struct
1 file changed, 13 insertions(+), 7 deletions(-)
changed files
M templates/homepage.templ → templates/homepage.templ
@@ -5,9 +5,15 @@ "go.alanpearce.eu/homestead/internal/config" "go.alanpearce.eu/homestead/internal/content" ) -templ Homepage(config *config.Config, posts []*content.Post, content templ.Component) { - @Layout(config, PageSettings{ - Title: config.Title, +type HomepageVars struct { + Email string + Me []config.MenuItem + Posts []*content.Post +} + +templ Homepage(site SiteSettings, vars HomepageVars, content templ.Component) { + @Layout(site, PageSettings{ + Title: site.Title, TitleAttrs: templ.Attributes{ "class": "p-name u-url", },@@ -21,17 +27,17 @@ @content </div> <section> <h2>Latest Posts</h2> - @list(posts[0:5]) + @list(vars.Posts[0:5]) </section> <section> <h2>Elsewhere on the Internet</h2> <ul class="elsewhere"> <li> - <a class="u-email" rel="me" href={ templ.SafeURL("mailto:" + config.Email) }> - { config.Email } + <a class="u-email" rel="me" href={ templ.SafeURL("mailto:" + vars.Email) }> + { vars.Email } </a> </li> - for _, link := range config.Menus["me"] { + for _, link := range vars.Me { <li> <a class="u-url" rel="me" href={ templ.SafeURL(link.URL.String()) }>{ link.Name }</a> </li>