diff options
Diffstat (limited to 'templates')
-rw-r--r-- | templates/404.html | 37 | ||||
-rw-r--r-- | templates/atom.xml | 48 | ||||
-rw-r--r-- | templates/count.html | 8 | ||||
-rw-r--r-- | templates/dev.go | 9 | ||||
-rw-r--r-- | templates/dev.html | 8 | ||||
-rw-r--r-- | templates/embed.go | 8 | ||||
-rw-r--r-- | templates/error.templ | 17 | ||||
-rw-r--r-- | templates/feed-styles.xsl | 4 | ||||
-rw-r--r-- | templates/feed.xml | 24 | ||||
-rw-r--r-- | templates/homepage.html | 63 | ||||
-rw-r--r-- | templates/homepage.templ | 42 | ||||
-rw-r--r-- | templates/list.html | 52 | ||||
-rw-r--r-- | templates/list.templ | 51 | ||||
-rw-r--r-- | templates/page.templ | 115 | ||||
-rw-r--r-- | templates/post.html | 78 | ||||
-rw-r--r-- | templates/post.templ | 56 | ||||
-rw-r--r-- | templates/style.css | 9 | ||||
-rw-r--r-- | templates/tags.html | 42 | ||||
-rw-r--r-- | templates/tags.templ | 23 |
19 files changed, 329 insertions, 365 deletions
diff --git a/templates/404.html b/templates/404.html deleted file mode 100644 index 81b2a54..0000000 --- a/templates/404.html +++ /dev/null @@ -1,37 +0,0 @@ -<!doctype html> -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>Site Title</title> - <link - rel="alternate" - type="application/atom+xml" - title="" - href="/atom.xml" - /> - <style></style> - </head> - <body> - <a class="skip" href="#main">Skip to main content</a> - <header> - <h2> - <a href="/" class="title">Site title</a> - </h2> - <nav> - <a href="/">Home</a> - </nav> - </header> - <main id="main"> - <h1>404</h1> - <h2>ʕノ•ᴥ•ʔノ ︵ ┻━┻</h2> - </main> - <footer> - Content is - <a rel="license" href="http://creativecommons.org/licenses/by/4.0/" - >CC BY 4.0</a - >. <a href="https://git.alanpearce.eu/website/">Site source code</a> is - <a href="https://opensource.org/licenses/MIT">MIT</a> - </footer> - </body> -</html> diff --git a/templates/atom.xml b/templates/atom.xml deleted file mode 100644 index 81c9a76..0000000 --- a/templates/atom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?xml-stylesheet href="/feed-styles.xsl" type="text/xsl"?> -<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}"> - <title>{{ config.title }} - {%- if term %} - {{ term.name }} - {%- elif section.title %} - {{ section.title }} - {%- endif -%} - </title> - {%- if config.description %} - <subtitle>{{ config.description }}</subtitle> - {%- endif %} - <link href="{{ feed_url | safe }}" rel="self" type="application/atom+xml"/> - <link href=" - {%- if section -%} - {{ section.permalink | escape_xml | safe }} - {%- else -%} - {{ config.base_url | escape_xml | safe }} - {%- endif -%} - "/> - <generator uri="https://www.getzola.org/">Zola</generator> - <updated>{{ last_updated | date(format="%+") }}</updated> - <id>{{ feed_url | safe }}</id> - {%- for page in pages %} - <entry xml:lang="{{ page.lang }}"> - <title>{{ page.title }}</title> - <published>{{ page.date | date(format="%+") }}</published> - <updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated> - <author> - <name> - {%- if page.authors -%} - {{ page.authors[0] }} - {%- elif config.author -%} - {{ config.author }} - {%- else -%} - Unknown - {%- endif -%} - </name> - </author> - <link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/> - <id>{{ page.permalink | safe }}</id> - {% if page.summary %} - <summary type="html">{{ page.summary }}</summary> - {% else %} - <content type="html">{{ page.content }}</content> - {% endif %} - </entry> - {%- endfor %} -</feed> diff --git a/templates/count.html b/templates/count.html deleted file mode 100644 index 46d5ac4..0000000 --- a/templates/count.html +++ /dev/null @@ -1,8 +0,0 @@ -<body> - <script data-goatcounter="https://alanpearce-eu.goatcounter.com/count" - async src="https://gc.zgo.at/count.v4.js" crossorigin="anonymous" - integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"></script> - <noscript> - <img src="https://alanpearce-eu.goatcounter.com/count?p=/updated-in-template.go" /> - </noscript> -</body> diff --git a/templates/dev.go b/templates/dev.go new file mode 100644 index 0000000..37a6416 --- /dev/null +++ b/templates/dev.go @@ -0,0 +1,9 @@ +//go:build !embed + +package templates + +import ( + "os" +) + +var Files = os.DirFS("templates/") diff --git a/templates/dev.html b/templates/dev.html deleted file mode 100644 index 0ca383e..0000000 --- a/templates/dev.html +++ /dev/null @@ -1,8 +0,0 @@ -<body> - <script defer> - new EventSource("/_/reload").onmessage = event => { - console.log("got message", event) - window.location.reload() - }; - </script> -</body> diff --git a/templates/embed.go b/templates/embed.go new file mode 100644 index 0000000..e7e1f18 --- /dev/null +++ b/templates/embed.go @@ -0,0 +1,8 @@ +//go:build embed + +package templates + +import "embed" + +//go:embed * +var Files embed.FS diff --git a/templates/error.templ b/templates/error.templ new file mode 100644 index 0000000..369cb83 --- /dev/null +++ b/templates/error.templ @@ -0,0 +1,17 @@ +package templates + +import ( + "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/http" + "strconv" +) + +templ Error(config *config.Config, path string, err *http.Error) { + @Page(config, PageSettings{ + Title: "Error", + Path: path, + }) { + <h1>{ strconv.Itoa(err.Code) } { err.Message }</h1> + <h2>ʕノ•ᴥ•ʔノ ︵ ┻━┻</h2> + } +} diff --git a/templates/feed-styles.xsl b/templates/feed-styles.xsl index fcca39d..679d064 100644 --- a/templates/feed-styles.xsl +++ b/templates/feed-styles.xsl @@ -12,7 +12,9 @@ <meta charset="utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> - <style></style> + <style> + {{ .css }} + </style> </head> <body> <main> diff --git a/templates/feed.xml b/templates/feed.xml deleted file mode 100644 index ddc90dd..0000000 --- a/templates/feed.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<?xml-stylesheet href="/feed-styles.xsl" type="text/xsl"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - <title>Example Feed</title> - <link href="http://example.org/"></link> - <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id> - <updated>2003-12-13T18:30:02Z</updated> - <entry> - <title>Atom-Powered Robots Run Amok</title> - <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"></link> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - <updated>2003-12-13T18:30:02Z</updated> - <summary>Some text.</summary> - <content type="html"> - <div> - <p>This is the entry content.</p> - </div> - </content> - <author> - <name>John Doe</name> - </author> - </entry> - -</feed> diff --git a/templates/homepage.html b/templates/homepage.html deleted file mode 100644 index 60bedb8..0000000 --- a/templates/homepage.html +++ /dev/null @@ -1,63 +0,0 @@ -<!doctype html> -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>Site Title</title> - <link - rel="alternate" - type="application/atom+xml" - title="" - href="/atom.xml" - /> - <link href="" rel="canonical" /> - <style></style> - </head> - <body> - <a class="skip" href="#main">Skip to main content</a> - <header> - <h2> - <a href="/" class="title">Site title</a> - </h2> - <nav> - <a href="/">Home</a> - </nav> - </header> - <main id="main"> - <div id="content"></div> - <section> - <h2>Latest Posts</h2> - <ul class="h-feed"> - <li class="h-entry"> - <span> - <time class="dt-published" datetime="2000-12-31T12:33:02+02:00"> - 2000-12-31 - </time> - </span> - <a class="p-name u-url" href="/post/lorem-ipsum/">Lorem Ipsum</a> - </li> - </ul> - </section> - <section> - <h2>Elsewhere on the Internet</h2> - <ul class="elsewhere"> - <li> - <a class="u-email" rel="me" href="mailto:user@example.com" - >user@example.com</a - > - </li> - <li> - <a class="u-url" rel="me" href="http://example.com">Example</a> - </li> - </ul> - </section> - </main> - <footer> - Content is - <a rel="license" href="http://creativecommons.org/licenses/by/4.0/" - >CC BY 4.0</a - >. <a href="https://git.alanpearce.eu/website/">Site source code</a> is - <a href="https://opensource.org/licenses/MIT">MIT</a> - </footer> - </body> -</html> diff --git a/templates/homepage.templ b/templates/homepage.templ new file mode 100644 index 0000000..aa61c40 --- /dev/null +++ b/templates/homepage.templ @@ -0,0 +1,42 @@ +package templates + +import ( + "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/content" +) + +templ Homepage(config *config.Config, posts []content.Post, content string) { + @Page(config, PageSettings{ + Title: config.Title, + TitleAttrs: templ.Attributes{ + "class": "p-name u-url", + }, + Path: "/", + BodyAttrs: templ.Attributes{ + "class": "h-card", + }, + }) { + <div id="content"> + @Unsafe(content) + </div> + <section> + <h2>Latest Posts</h2> + @list(posts[0:3]) + </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> + </li> + for _, link := range config.Menus["me"] { + <li> + <a class="u-url" rel="me" href={ templ.SafeURL(link.URL.String()) }>{ link.Name }</a> + </li> + } + </ul> + </section> + } +} diff --git a/templates/list.html b/templates/list.html deleted file mode 100644 index 1c0b32b..0000000 --- a/templates/list.html +++ /dev/null @@ -1,52 +0,0 @@ -<!doctype html> -<html lang="en-GB"> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>Site Title</title> - <link - rel="alternate" - type="application/atom+xml" - title="Site Title" - href="/atom.xml" - /> - <link href="" rel="canonical" /> - <style></style> - </head> - <body> - <a class="skip" href="#content">Skip to main content</a> - <header> - <h2> - <a href="/" class="title">Site Title</a> - </h2> - <nav> - <a href="/">Home</a> - </nav> - </header> - <main id="content"> - <div class="filter"> - <h3 class="filter">Tag</h3> - <small> - <a href="../">Remove filter</a> - </small> - </div> - <ul class="h-feed"> - <li class="h-entry"> - <span> - <time class="dt-published" datetime="2000-12-31T12:33:02+02:00"> - 2000-12-31 - </time> - </span> - <a class="p-name u-url" href="/post/lorem-ipsum/">Lorem Ipsum</a> - </li> - </ul> - </main> - <footer> - Content is - <a rel="license" href="http://creativecommons.org/licenses/by/4.0/" - >CC BY 4.0</a - >. <a href="https://git.alanpearce.eu/website/">Site source code</a> is - <a href="https://opensource.org/licenses/MIT">MIT</a> - </footer> - </body> -</html> diff --git a/templates/list.templ b/templates/list.templ new file mode 100644 index 0000000..fc59677 --- /dev/null +++ b/templates/list.templ @@ -0,0 +1,51 @@ +package templates + +import ( + "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/content" +) + +templ TagPage(config *config.Config, tag string, posts []content.Post, path string) { + @Page(config, PageSettings{ + Title: tag, + Path: path, + TitleAttrs: templ.Attributes{ + "class": "p-author h-card", + "rel": "author", + }, + }) { + <div class="filter"> + <h3 class="filter">#{ tag }</h3> + <small> + <a href="../">Remove filter</a> + </small> + </div> + @list(posts) + } +} + +templ ListPage(config *config.Config, posts []content.Post, path string) { + @Page(config, PageSettings{ + Title: config.Title, + TitleAttrs: templ.Attributes{ + "class": "p-author h-card", + "rel": "author", + }, + Path: path, + }) { + @list(posts) + } +} + +templ list(posts []content.Post) { + <ul class="h-feed"> + for _, post := range posts { + <li class="h-entry"> + <span> + @postDate(post.Date) + </span> + <a class="p-name u-url" href={ templ.SafeURL(post.URL) }>{ post.Title }</a> + </li> + } + </ul> +} diff --git a/templates/page.templ b/templates/page.templ new file mode 100644 index 0000000..39dd263 --- /dev/null +++ b/templates/page.templ @@ -0,0 +1,115 @@ +package templates + +import ( + "io/fs" + + "go.alanpearce.eu/website/internal/config" + "net/url" +) + +var ( + css string +) + +func Setup() { + bytes, err := fs.ReadFile(Files, "style.css") + if err != nil { + panic(err) + } + css = string(bytes) +} + +type PageSettings struct { + Title string + Path string + TitleAttrs templ.Attributes + BodyAttrs templ.Attributes +} + +func extendClasses(cs string, attrs templ.Attributes) string { + if extras, exists := attrs["class"]; exists { + return templ.Classes(cs, extras).String() + } else { + return cs + } +} + +templ menuItem(item config.MenuItem) { + <a + href={ templ.SafeURL(item.URL.String()) } + if item.URL.IsAbs() { + target="_blank" + } + >{ item.Name }</a> +} + +templ Page(site *config.Config, page PageSettings) { + <!DOCTYPE html> + <html lang={ site.DefaultLanguage }> + <head> + <meta charset="utf-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <title>{ page.Title }</title> + <link rel="alternate" type="application/atom+xml" title={ site.Title } href="/atom.xml"/> + @style(css) + </head> + <body { page.BodyAttrs... }> + <a class="skip" href="#main">Skip to main content</a> + <header> + <h2> + <a href="/" class={ extendClasses("title p-name", page.TitleAttrs) } { page.TitleAttrs... }>{ site.Title }</a> + </h2> + <nav> + for _, item := range site.Menus["main"] { + @menuItem(item) + } + </nav> + </header> + <main id="main"> + { children... } + </main> + <footer> + Content is + <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>. + <a href="https://git.alanpearce.eu/website/">Site source code</a> is + <a href="https://opensource.org/licenses/MIT">MIT</a> + </footer> + @counter(site, page.Path, page.Title) + if site.InjectLiveReload { + <script defer> + new EventSource("/_/reload").onmessage = event => { + console.log("got message", event) + window.location.reload() + }; + </script> + } + </body> + </html> +} + +func mkURL(original config.URL, path string, title string) string { + ou := *original.URL + u := config.URL{ + URL: &ou, + } + q := url.Values{} + q.Add("p", path) + q.Add("t", title) + u.RawQuery = q.Encode() + + return u.String() +} + +templ counter(config *config.Config, path string, title string) { + <script data-goatcounter={ config.GoatCounter.String() } async src="https://stats.alanpearce.eu/count.v4.js" crossorigin="anonymous" integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"></script> + <noscript> + <img src={ string(templ.URL(mkURL(config.GoatCounter, path, title))) }/> + </noscript> +} + +func style(css string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) { + _, err = io.WriteString(w, "<style>\n"+css+"\n</style>") + return + }) +} diff --git a/templates/post.html b/templates/post.html deleted file mode 100644 index 3dad16c..0000000 --- a/templates/post.html +++ /dev/null @@ -1,78 +0,0 @@ -<!doctype html> -<html lang="en-GB"> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title></title> - <link - rel="alternate" - type="application/atom+xml" - title="" - href="/atom.xml" - /> - <link href="" rel="canonical" /> - <style></style> - </head> - <body> - <a class="skip" href="#main">Skip to main content</a> - <header> - <h2> - <a href="/" class="title"></a> - </h2> - <nav> - <a href="/">Home</a> - </nav> - </header> - <main id="main"> - <article class="h-entry"> - <h1 class="p-name">Post Title</h1> - <p> - <time class="dt-published">2000-12-31</time> - </p> - <div class="e-content"> - Enim lobortis scelerisque fermentum dui faucibus in ornare quam - viverra. Eget egestas purus viverra accumsan in nisl nisi, scelerisque - eu ultrices vitae, auctor eu augue ut lectus arcu, bibendum at. - - <code>/bin/test</code> - - <pre> - <code class="language-conf"> -foo=bar - </code> - </pre> - - <table> - <thead> - <tr> - <th>One</th> - <th>Two</th> - <th>Three</th> - </tr> - </thead> - <tbody> - <tr> - <td>1</td> - <td>2</td> - <td>3</td> - </tr> - </tbody> - </table> - </div> - <div class="tags"> - Tags: - <ul class="p-categories tags"> - <li><a class="p-category" href="/tags/sample/">#sample</a></li> - </ul> - </div> - </article> - </main> - <footer> - Content is - <a rel="license" href="http://creativecommons.org/licenses/by/4.0/" - >CC BY 4.0</a - >. <a href="https://git.alanpearce.eu/website/">Site source code</a> is - <a href="https://opensource.org/licenses/MIT">MIT</a> - </footer> - </body> -</html> diff --git a/templates/post.templ b/templates/post.templ new file mode 100644 index 0000000..9717b4e --- /dev/null +++ b/templates/post.templ @@ -0,0 +1,56 @@ +package templates + +import ( + "time" + "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/content" +) + +func Unsafe(html string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) { + _, err = io.WriteString(w, html) + return + }) +} + +templ postDate(d time.Time) { + <time class="dt-published" datetime={ d.UTC().Format(time.RFC3339) }> + { d.Format("2006-01-02") } + </time> +} + +templ PostPage(config *config.Config, post content.Post) { + @Page(config, PageSettings{ + Title: post.Title, + TitleAttrs: templ.Attributes{ + "class": "p-author h-card", + "rel": "author", + }, + BodyAttrs: templ.Attributes{ + "class": "h-entry", + }, + Path: post.URL, + }) { + <article> + <h1 class="p-name">{ post.Title }</h1> + <p> + <a class="u-url" href={ templ.SafeURL(post.URL) }> + @postDate(post.Date) + </a> + </p> + <div class="e-content"> + @Unsafe(post.Content) + </div> + <div class="tags"> + Tags: + <ul class="p-categories tags"> + for _, tag := range post.Taxonomies.Tags { + <li> + @tagLink(tag, templ.Attributes{"class": "p-category"}) + </li> + } + </ul> + </div> + </article> + } +} diff --git a/templates/style.css b/templates/style.css index b386843..e9a2955 100644 --- a/templates/style.css +++ b/templates/style.css @@ -188,16 +188,17 @@ ul.h-feed li a:visited { .tags { font-size: small; -} - -.p-categories, -ul.tags { display: inline-block; padding-inline-start: 0; } +.p-categories { + padding-inline-start: 1ex; +} + .tags li { list-style: none; display: inline-block; + margin-inline-end: 1ex; } svg.rss-icon { diff --git a/templates/tags.html b/templates/tags.html deleted file mode 100644 index 1ff18c0..0000000 --- a/templates/tags.html +++ /dev/null @@ -1,42 +0,0 @@ -<!doctype html> -<html lang="en-GB"> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>Site Title</title> - <link - rel="alternate" - type="application/atom+xml" - title="Site title" - href="/atom.xml" - /> - <link href="" rel="canonical" /> - <style></style> - </head> - <body> - <a class="skip" href="#content">Skip to main content</a> - <header> - <h2> - <a href="/" class="title">Site title</a> - </h2> - <nav> - <a href="/">Home</a> - </nav> - </header> - <main id="content"> - <h3 class="filter">Tags</h3> - <ul class="tags"> - <li class="h-feed"> - <a href="/tags/tag">#tag</a> - </li> - </ul> - </main> - <footer> - Content is - <a rel="license" href="http://creativecommons.org/licenses/by/4.0/" - >CC BY 4.0</a - >. <a href="https://git.alanpearce.eu/website/">Site source code</a> is - <a href="https://opensource.org/licenses/MIT">MIT</a> - </footer> - </body> -</html> diff --git a/templates/tags.templ b/templates/tags.templ new file mode 100644 index 0000000..c872a0d --- /dev/null +++ b/templates/tags.templ @@ -0,0 +1,23 @@ +package templates + +import "go.alanpearce.eu/website/internal/config" + +templ tagLink(tag string, attrs templ.Attributes) { + <a { attrs... } href={ templ.SafeURL("/tags/" + tag) }>#{ tag }</a> +} + +templ TagsPage(config *config.Config, title string, tags []string, path string) { + @Page(config, PageSettings{ + Title: title, + Path: path, + }) { + <h3 class="filter">Tags</h3> + <ul class="tags"> + for _, tag := range tags { + <li class="h-feed"> + @tagLink(tag, templ.Attributes{}) + </li> + } + </ul> + } +} |