about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-04-15 22:53:29 +0200
committerAlan Pearce2024-04-16 18:10:17 +0200
commitee0d8aed15902b6b76a14e2612c5ec661b320dc3 (patch)
treec0c66c048d92917aa6a7a7c3d5f78d621c4f4978
parent27448f33dce9141316bb4ea6d905305d8a846cac (diff)
downloadwebsite-ee0d8aed15902b6b76a14e2612c5ec661b320dc3.tar.lz
website-ee0d8aed15902b6b76a14e2612c5ec661b320dc3.tar.zst
website-ee0d8aed15902b6b76a14e2612c5ec661b320dc3.zip
reduce diffs to typescript builder
-rw-r--r--cmd/build/atom.go6
-rw-r--r--cmd/build/main.go64
2 files changed, 34 insertions, 36 deletions
diff --git a/cmd/build/atom.go b/cmd/build/atom.go
index 9116278..e071af9 100644
--- a/cmd/build/atom.go
+++ b/cmd/build/atom.go
@@ -7,7 +7,7 @@ import (
 	. "alanpearce.eu/website/internal/config"
 )
 
-func makeTagURI(config Config, specific string) string {
+func MakeTagURI(config Config, specific string) string {
 	return "tag:" + config.OriginalDomain + "," + config.DomainStartDate + ":" + specific
 }
 
@@ -18,7 +18,7 @@ type Link struct {
 	Href    string   `xml:"href,attr"`
 }
 
-func makeLink(url string) Link {
+func MakeLink(url string) Link {
 	return Link{
 		Rel:  "alternate",
 		Type: "text/html",
@@ -38,6 +38,6 @@ type FeedEntry struct {
 	Id      string      `xml:"id"`
 	Updated time.Time   `xml:"updated"`
 	Summary string      `xml:"summary,omitempty"`
-	Author  string      `xml:"author>name"`
 	Content FeedContent `xml:"content"`
+	Author  string      `xml:"author>name"`
 }
diff --git a/cmd/build/main.go b/cmd/build/main.go
index 6519fa8..6a2f375 100644
--- a/cmd/build/main.go
+++ b/cmd/build/main.go
@@ -7,6 +7,7 @@ import (
 	"io/fs"
 	"log"
 	"log/slog"
+	"net/url"
 	"os"
 	"path"
 	"path/filepath"
@@ -137,7 +138,7 @@ func layout(filename string, config Config, pageTitle string) (*goquery.Document
 	doc.Find("head > link[rel=alternate]").SetAttr("title", config.Title)
 	doc.Find(".title").SetText(config.Title)
 	doc.Find("title").Add(".p-name").SetText(pageTitle)
-	doc.Find("head > style").SetText(string(css))
+	doc.Find("head > style").SetHtml(string(css))
 	nav := doc.Find("nav")
 	navLink := doc.Find("nav a")
 	nav.Empty()
@@ -152,20 +153,20 @@ func renderPost(post Post, config Config) (string, error) {
 	if err != nil {
 		return "", err
 	}
-	doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author")
-	datetime, err := post.PostMatter.Date.MarshalText()
-	if err != nil {
-		return "", err
-	}
-	doc.Find(".h-entry .dt-published").SetAttr("datetime", string(datetime)).SetText(
-		post.PostMatter.Date.Format("2006-01-02"),
-	)
+	doc.Find(".title").AddClass("p-author h-card").SetAttr("rel", "author")
+	doc.Find(".h-entry .dt-published").
+		SetAttr("datetime", post.PostMatter.Date.UTC().Format(time.RFC3339)).
+		SetText(
+			post.PostMatter.Date.Format("2006-01-02"),
+		)
 	doc.Find(".h-entry .e-content").SetHtml(post.Content)
 	categories := doc.Find(".h-entry .p-categories")
-	cat := categories.Find(".p-category").ParentsUntilSelection(categories)
-	cat.Remove()
+	tpl := categories.Find(".p-category").ParentsUntilSelection(categories)
+	tpl.Remove()
 	for _, tag := range post.Taxonomies.Tags {
-		categories.AppendSelection(cat.Clone().Find(".p-category").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)).Parent()
+		cat := tpl.Clone()
+		cat.Find(".p-category").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)
+		categories.AppendSelection(cat)
 	}
 	return doc.Html()
 }
@@ -179,9 +180,9 @@ func renderTags(tags Tags, config Config) (string, error) {
 	tpl := doc.Find(".h-feed")
 	tpl.Remove()
 	for _, tag := range mapset.Sorted(tags) {
-		tagList.AppendSelection(
-			tpl.Clone().SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag),
-		)
+		li := tpl.Clone()
+		li.Find("a").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)
+		tagList.AppendSelection(li)
 	}
 	return doc.Html()
 }
@@ -201,7 +202,7 @@ func renderListPage(tag string, config Config, posts []Post) (string, error) {
 	tpl := feed.Find(".h-entry")
 	tpl.Remove()
 
-	doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author")
+	doc.Find(".title").AddClass("p-author h-card").SetAttr("rel", "author")
 	if tag == "" {
 		doc.Find(".filter").Remove()
 	} else {
@@ -210,13 +211,10 @@ func renderListPage(tag string, config Config, posts []Post) (string, error) {
 
 	for _, post := range posts {
 		entry := tpl.Clone()
-		datetime, err := post.PostMatter.Date.MarshalText()
-		if err != nil {
-			return "", err
-		}
-
 		entry.Find(".p-name").SetText(post.Title).SetAttr("href", post.URL)
-		entry.Find(".dt-published").SetAttr("datetime", string(datetime)).SetText(post.PostMatter.Date.Format("2006-01-02"))
+		entry.Find(".dt-published").
+			SetAttr("datetime", post.PostMatter.Date.UTC().Format(time.RFC3339)).
+			SetText(post.PostMatter.Date.Format("2006-01-02"))
 		feed.AppendSelection(entry)
 	}
 
@@ -246,17 +244,13 @@ func renderHomepage(config Config, posts []Post) (string, error) {
 	tpl := feed.Find(".h-entry")
 	tpl.Remove()
 
-	for _, post := range posts {
+	for _, post := range posts[0:3] {
 		entry := tpl.Clone()
 		entry.Find(".p-name").SetText(post.Title)
 		entry.Find(".u-url").SetAttr("href", post.URL)
-		datetime, err := post.PostMatter.Date.MarshalText()
-		if err != nil {
-			return "", err
-		}
 		entry.
 			Find(".dt-published").
-			SetAttr("datetime", string(datetime)).
+			SetAttr("datetime", post.PostMatter.Date.UTC().Format(time.RFC3339)).
 			SetText(post.PostMatter.Date.Format("2006-01-02"))
 
 		feed.AppendSelection(entry)
@@ -296,18 +290,22 @@ func renderFeed(title string, config Config, posts []Post, specific string) (str
 	feed := doc.SelectElement("feed")
 	feed.SelectElement("title").FirstChild.Data = title
 	feed.SelectElement("link").SetAttr("href", config.BaseURL)
-	feed.SelectElement("id").FirstChild.Data = makeTagURI(config, specific)
-	datetime, err := posts[0].Date.MarshalText()
+	feed.SelectElement("id").FirstChild.Data = MakeTagURI(config, specific)
+	datetime, err := posts[0].Date.UTC().MarshalText()
 	feed.SelectElement("updated").FirstChild.Data = string(datetime)
 	tpl := feed.SelectElement("entry")
 	xmlquery.RemoveFromTree(tpl)
 
 	for _, post := range posts {
+		fullURL, err := url.JoinPath(config.BaseURL, post.URL)
+		if err != nil {
+			return "", err
+		}
 		text, err := xml.MarshalIndent(&FeedEntry{
 			Title:   post.Title,
-			Link:    makeLink(post.URL),
-			Id:      makeTagURI(config, post.Basename),
-			Updated: post.Date,
+			Link:    MakeLink(fullURL),
+			Id:      MakeTagURI(config, post.Basename),
+			Updated: post.Date.UTC(),
 			Summary: post.Description,
 			Author:  config.Title,
 			Content: FeedContent{