about summary refs log tree commit diff stats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/elements.go8
-rw-r--r--components/elements_test.go14
2 files changed, 22 insertions, 0 deletions
diff --git a/components/elements.go b/components/elements.go
index f4e347d..c9e1427 100644
--- a/components/elements.go
+++ b/components/elements.go
@@ -8,3 +8,11 @@ import (
 func InputHidden(name, value string, children ...g.Node) g.Node {
 	return Input(Type("hidden"), Name(name), Value(value), g.Group(children))
 }
+
+func LinkStylesheet(href string, children ...g.Node) g.Node {
+	return Link(Rel("stylesheet"), Href(href), g.Group(children))
+}
+
+func LinkPreload(href, as string, children ...g.Node) g.Node {
+	return Link(Rel("preload"), Href(href), As(as), g.Group(children))
+}
diff --git a/components/elements_test.go b/components/elements_test.go
index 334ed2c..7dc4eec 100644
--- a/components/elements_test.go
+++ b/components/elements_test.go
@@ -14,3 +14,17 @@ func TestInputHidden(t *testing.T) {
 		assert.Equal(t, `<input type="hidden" name="id" value="partyhat" class="hat">`, n)
 	})
 }
+
+func TestLinkStylesheet(t *testing.T) {
+	t.Run("returns a link element with rel stylesheet and the given href", func(t *testing.T) {
+		n := c.LinkStylesheet("style.css", g.Attr("media", "print"))
+		assert.Equal(t, `<link rel="stylesheet" href="style.css" media="print">`, n)
+	})
+}
+
+func TestLinkPreload(t *testing.T) {
+	t.Run("returns a link element with rel preload and the given href and as", func(t *testing.T) {
+		n := c.LinkPreload("party.woff2", "font", g.Attr("type", "font/woff2"))
+		assert.Equal(t, `<link rel="preload" href="party.woff2" as="font" type="font/woff2">`, n)
+	})
+}