job-board
job-board copied to clipboard
[DX] use nested templates and make header/footer/nav reusable
all html views right now are copy-pasta and nothing is re-used, mostly the header and footer which can be plugged into a nested template and included in the view could simplify a lot the html and the overall maintenance of the views
https://pkg.go.dev/text/template#hdr-Nested_template_definitions
for instance this would look like something like this
footer.html
{{define "footer"}}
<syle type="text/css"> /** all css used only by the footer here **/</style>
<script>/** all js used only by the footer here **/</script>
<footer>
<p>
Golang Cafe ...
</p>
</footer>
{{end}}
landing.html
<html>
// ...
<body>
// ...
</div>
{{ template "footer" }}
</body>
</html>
Not sure if this exactly works like this but i can see that is possible to import and include other html files/templates in any Go html file template
https://stackoverflow.com/questions/33984147/golang-embed-html-from-file
Potentially there are a lot of components that can be extracted into a re-usable template, some that come to mind:
- footer
- navbar
- newsletter banner
- newsletter box
- company item in search (probably?)
- job item in search (probably?)
- developer item in search (probably?)
any of these will be a template file ending in .html and will include all the re-usable HTML/CSS/JS. Most of these will also have to take Go template variable as parameters. Like for instance the navbar will take active page so we can know how to underline a given nav/menu entry.
It will need a little research and trial so we can start just by extracting footer or nav
for the approach please see discussion here https://github.com/golang-cafe/golang.cafe/pull/39#issuecomment-1046150761
Would be good to have different html template with css js html so that these get included/imported in the right locations (head for styles, end of body for javascript and wherever is needed for html)
already started on this with newsletter template and others, could do the same for various re-usable components:
- header
- footer
- etc