add versioning

This commit is contained in:
maddalax 2024-09-24 13:05:38 -05:00
parent 90117e7b0f
commit d063a8da63
2 changed files with 28 additions and 2 deletions

View file

@ -63,6 +63,18 @@ func Meta(name string, content string) Ren {
}
}
func LinkWithVersion(href string, rel string, version string) Ren {
attributeMap := AttributeMap{
"href": href + "?v=" + version,
"rel": rel,
}
return &Element{
tag: "link",
attributes: attributeMap.ToMap(),
children: make([]Ren, 0),
}
}
func Link(href string, rel string) Ren {
attributeMap := AttributeMap{
"href": href,
@ -75,6 +87,17 @@ func Link(href string, rel string) Ren {
}
}
func ScriptWithVersion(url string, version string) Ren {
attributeMap := AttributeMap{
"src": url + "?v=" + version,
}
return &Element{
tag: "script",
attributes: attributeMap.ToMap(),
children: make([]Ren, 0),
}
}
func Script(url string) Ren {
attributeMap := AttributeMap{
"src": url,

View file

@ -1,17 +1,20 @@
package base
import (
"github.com/google/uuid"
"github.com/maddalax/htmgo/framework/h"
"htmgo-site/partials"
)
var Version = uuid.NewString()[0:6]
func RootPage(children ...h.Ren) *h.Element {
return h.Html(
h.HxExtension(h.BaseExtensions()),
h.Head(
h.Meta("viewport", "width=device-width, initial-scale=1"),
h.Link("/public/main.css", "stylesheet"),
h.Script("/public/htmgo.js"),
h.LinkWithVersion("/public/main.css", "stylesheet", Version),
h.ScriptWithVersion("/public/htmgo.js", Version),
h.Raw(`
<script async defer src="https://buttons.github.io/buttons.js"></script>
`),