From d063a8da633210baf5fc4fcac17265e499e1504e Mon Sep 17 00:00:00 2001 From: maddalax Date: Tue, 24 Sep 2024 13:05:38 -0500 Subject: [PATCH] add versioning --- framework/h/tag.go | 23 +++++++++++++++++++++++ htmgo-site/pages/base/root.go | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/framework/h/tag.go b/framework/h/tag.go index f63a237..7fe9961 100644 --- a/framework/h/tag.go +++ b/framework/h/tag.go @@ -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, diff --git a/htmgo-site/pages/base/root.go b/htmgo-site/pages/base/root.go index 9d5b9fc..53e26d6 100644 --- a/htmgo-site/pages/base/root.go +++ b/htmgo-site/pages/base/root.go @@ -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(` `),