about summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAlan Pearce2024-04-17 20:31:14 +0200
committerAlan Pearce2024-04-17 20:53:45 +0200
commit4dfd72e68c385a6f02370e38831f33e644276055 (patch)
tree6536fa38d96e27207baf062bc992af6654e44ccd /cmd
parent347d0cd1a73921a8cbc43798a7fbe2095791bbe9 (diff)
downloadwebsite-4dfd72e68c385a6f02370e38831f33e644276055.tar.lz
website-4dfd72e68c385a6f02370e38831f33e644276055.tar.zst
website-4dfd72e68c385a6f02370e38831f33e644276055.zip
use internal imports correctly
Diffstat (limited to 'cmd')
-rw-r--r--cmd/build/atom.go43
-rw-r--r--cmd/build/build.go29
2 files changed, 15 insertions, 57 deletions
diff --git a/cmd/build/atom.go b/cmd/build/atom.go
deleted file mode 100644
index bf8d318..0000000
--- a/cmd/build/atom.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package main
-
-import (
-	"encoding/xml"
-	"time"
-
-	. "website/internal/config"
-)
-
-func MakeTagURI(config Config, specific string) string {
-	return "tag:" + config.OriginalDomain + "," + config.DomainStartDate + ":" + specific
-}
-
-type Link struct {
-	XMLName xml.Name `xml:"link"`
-	Rel     string   `xml:"rel,attr"`
-	Type    string   `xml:"type,attr"`
-	Href    string   `xml:"href,attr"`
-}
-
-func MakeLink(url string) Link {
-	return Link{
-		Rel:  "alternate",
-		Type: "text/html",
-		Href: url,
-	}
-}
-
-type FeedContent struct {
-	Content string `xml:",innerxml"`
-	Type    string `xml:"type,attr"`
-}
-
-type FeedEntry struct {
-	XMLName xml.Name    `xml:"entry"`
-	Title   string      `xml:"title"`
-	Link    Link        `xml:"link"`
-	Id      string      `xml:"id"`
-	Updated time.Time   `xml:"updated"`
-	Summary string      `xml:"summary,omitempty"`
-	Content FeedContent `xml:"content"`
-	Author  string      `xml:"author>name"`
-}
diff --git a/cmd/build/build.go b/cmd/build/build.go
index ddc7a6b..7d54fd1 100644
--- a/cmd/build/build.go
+++ b/cmd/build/build.go
@@ -16,7 +16,8 @@ import (
 	"strings"
 	"time"
 
-	. "website/internal/config"
+	"website/internal/atom"
+	"website/internal/config"
 
 	"github.com/BurntSushi/toml"
 	"github.com/PuerkitoBio/goquery"
@@ -123,7 +124,7 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, er
 	return posts, tags, nil
 }
 
-func layout(filename string, config Config, pageTitle string) (*goquery.Document, error) {
+func layout(filename string, config config.Config, pageTitle string) (*goquery.Document, error) {
 	html, err := os.Open(filename)
 	if err != nil {
 		return nil, err
@@ -160,7 +161,7 @@ func renderHTML(doc *goquery.Document) io.Reader {
 	return r
 }
 
-func renderPost(post Post, config Config) (r io.Reader, err error) {
+func renderPost(post Post, config config.Config) (r io.Reader, err error) {
 	doc, err := layout("templates/post.html", config, post.PostMatter.Title)
 	if err != nil {
 		return nil, err
@@ -184,7 +185,7 @@ func renderPost(post Post, config Config) (r io.Reader, err error) {
 	return renderHTML(doc), nil
 }
 
-func renderTags(tags Tags, config Config) (io.Reader, error) {
+func renderTags(tags Tags, config config.Config) (io.Reader, error) {
 	doc, err := layout("templates/tags.html", config, config.Title)
 	if err != nil {
 		return nil, err
@@ -200,7 +201,7 @@ func renderTags(tags Tags, config Config) (io.Reader, error) {
 	return renderHTML(doc), nil
 }
 
-func renderListPage(tag string, config Config, posts []Post) (io.Reader, error) {
+func renderListPage(tag string, config config.Config, posts []Post) (io.Reader, error) {
 	var title string
 	if len(tag) > 0 {
 		title = tag
@@ -234,7 +235,7 @@ func renderListPage(tag string, config Config, posts []Post) (io.Reader, error)
 	return renderHTML(doc), nil
 }
 
-func renderHomepage(config Config, posts []Post) (io.Reader, error) {
+func renderHomepage(config config.Config, posts []Post) (io.Reader, error) {
 	_, index, err := getPost("content/_index.md")
 	if err != nil {
 		return nil, err
@@ -285,7 +286,7 @@ func renderHomepage(config Config, posts []Post) (io.Reader, error) {
 	return renderHTML(doc), nil
 }
 
-func render404(config Config) (io.Reader, error) {
+func render404(config config.Config) (io.Reader, error) {
 	doc, err := layout("templates/404.html", config, "404 Not Found")
 	if err != nil {
 		return nil, err
@@ -293,7 +294,7 @@ func render404(config Config) (io.Reader, error) {
 	return renderHTML(doc), nil
 }
 
-func renderFeed(title string, config Config, posts []Post, specific string) (io.Reader, error) {
+func renderFeed(title string, config config.Config, posts []Post, specific string) (io.Reader, error) {
 	reader, err := os.Open("templates/feed.xml")
 	if err != nil {
 		return nil, err
@@ -303,7 +304,7 @@ func renderFeed(title string, config Config, posts []Post, specific string) (io.
 	feed := doc.SelectElement("feed")
 	feed.SelectElement("title").FirstChild.Data = title
 	feed.SelectElement("link").SetAttr("href", config.BaseURL.String())
-	feed.SelectElement("id").FirstChild.Data = MakeTagURI(config, specific)
+	feed.SelectElement("id").FirstChild.Data = atom.MakeTagURI(config, specific)
 	datetime, err := posts[0].Date.UTC().MarshalText()
 	feed.SelectElement("updated").FirstChild.Data = string(datetime)
 	tpl := feed.SelectElement("entry")
@@ -314,14 +315,14 @@ func renderFeed(title string, config Config, posts []Post, specific string) (io.
 		if err != nil {
 			return nil, err
 		}
-		text, err := xml.MarshalIndent(&FeedEntry{
+		text, err := xml.MarshalIndent(&atom.FeedEntry{
 			Title:   post.Title,
-			Link:    MakeLink(fullURL),
-			Id:      MakeTagURI(config, post.Basename),
+			Link:    atom.MakeLink(fullURL),
+			Id:      atom.MakeTagURI(config, post.Basename),
 			Updated: post.Date.UTC(),
 			Summary: post.Description,
 			Author:  config.Title,
-			Content: FeedContent{
+			Content: atom.FeedContent{
 				Content: post.Content,
 				Type:    "html",
 			},
@@ -391,7 +392,7 @@ func outputToFile(output io.Reader, filename ...string) error {
 }
 
 func build() error {
-	config, err := GetConfig()
+	config, err := config.GetConfig()
 	if err != nil {
 		return err
 	}