From 56b0df9e6c84bbcdaffbde50632e7fdd992791e5 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 15 Apr 2024 08:55:53 +0200 Subject: wip: render feeds --- cmd/build/atom.go | 43 +++++++ cmd/build/main.go | 294 ++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 4 + go.sum | 9 ++ internal/config/config.go | 37 ++++++ src/build.go | 245 -------------------------------------- src/config.go | 38 ------ 7 files changed, 387 insertions(+), 283 deletions(-) create mode 100644 cmd/build/atom.go create mode 100644 cmd/build/main.go create mode 100644 internal/config/config.go delete mode 100644 src/build.go delete mode 100644 src/config.go diff --git a/cmd/build/atom.go b/cmd/build/atom.go new file mode 100644 index 0000000..9116278 --- /dev/null +++ b/cmd/build/atom.go @@ -0,0 +1,43 @@ +package main + +import ( + "encoding/xml" + "time" + + . "alanpearce.eu/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"` + Author string `xml:"author>name"` + Content FeedContent `xml:"content"` +} diff --git a/cmd/build/main.go b/cmd/build/main.go new file mode 100644 index 0000000..48c9739 --- /dev/null +++ b/cmd/build/main.go @@ -0,0 +1,294 @@ +package main + +import ( + "bytes" + "encoding/xml" + "fmt" + "log" + "os" + "path" + "path/filepath" + "slices" + "strings" + "time" + + . "alanpearce.eu/website/internal/config" + + "github.com/PuerkitoBio/goquery" + "github.com/adrg/frontmatter" + "github.com/antchfx/xmlquery" + mapset "github.com/deckarep/golang-set/v2" + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" +) + +type PostMatter struct { + Date time.Time `toml:"date"` + Description string `toml:"description"` + Title string `toml:"title"` + Taxonomies struct { + Tags []string `toml:"tags"` + } `toml:"taxonomies"` +} + +type Post struct { + Input string + Output string + Basename string + URL string + Content string + PostMatter +} + +type Tags mapset.Set[string] + +func check(err error) { + if err != nil { + log.Panic(err) + } +} + +func getPost(filename string) (PostMatter, []byte) { + matter := PostMatter{} + content, err := os.Open(filename) + check(err) + rest, err := frontmatter.Parse(content, &matter) + check(err) + + return matter, rest +} + +func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags) { + tags := mapset.NewSet[string]() + posts := []Post{} + subdir := filepath.Join(root, inputDir) + files, err := os.ReadDir(subdir) + outputReplacer := strings.NewReplacer(root, outputDir, ".md", "/index.html") + urlReplacer := strings.NewReplacer(root, "", ".md", "/") + check(err) + md := goldmark.New( + goldmark.WithExtensions( + extension.GFM, + extension.Footnote, + extension.Typographer, + ), + ) + for _, f := range files { + pathFromRoot := filepath.Join(subdir, f.Name()) + check(err) + if !f.IsDir() && path.Ext(pathFromRoot) == ".md" { + output := outputReplacer.Replace(pathFromRoot) + url := urlReplacer.Replace(pathFromRoot) + matter, content := getPost(pathFromRoot) + + for _, tag := range matter.Taxonomies.Tags { + tags.Add(strings.ToLower(tag)) + } + + var buf bytes.Buffer + err := md.Convert(content, &buf) + check(err) + post := Post{ + Input: pathFromRoot, + Output: output, + Basename: filepath.Base(url), + URL: url, + PostMatter: matter, + Content: buf.String(), + } + + posts = append(posts, post) + } + } + slices.SortFunc(posts, func(a, b Post) int { + return b.Date.Compare(a.Date) + }) + return posts, tags +} + +func layout(html string, config Config, pageTitle string) *goquery.Document { + css, err := os.ReadFile("templates/style.css") + check(err) + doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)) + check(err) + doc.Find("html").SetAttr("lang", config.DefaultLanguage) + doc.Find("head > link[rel=alternate]").Add(".title").SetAttr("title", config.Title) + doc.Find("title").Add(".p-name").SetText(pageTitle) + doc.Find("head > style").SetText(string(css)) + nav := doc.Find("nav") + navLink := doc.Find("nav a") + nav.Empty() + for _, link := range config.Menus["main"] { + nav.AppendSelection(navLink.Clone().SetAttr("href", link.URL).SetText(link.Name)) + } + return doc +} + +func renderPost(post Post, config Config) string { + tbytes, err := os.ReadFile("templates/post.html") + check(err) + doc := layout(string(tbytes), config, post.PostMatter.Title) + doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author") + datetime, err := post.PostMatter.Date.MarshalText() + check(err) + doc.Find(".h-entry .dt-published").SetAttr("datetime", string(datetime)).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() + for _, tag := range post.Taxonomies.Tags { + categories.AppendSelection(cat.Clone().Find(".p-category").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)).Parent() + } + html, err := doc.Html() + check(err) + return html +} + +func renderTags(tags Tags, config Config) string { + tbytes, err := os.ReadFile("templates/tags.html") + check(err) + + doc := layout(string(tbytes), config, config.Title) + tagList := doc.Find(".tags") + 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), + ) + } + html, err := doc.Html() + check(err) + return html +} + +func renderListPage(tag string, config Config, posts []Post) string { + tbytes, err := os.ReadFile("templates/list.html") + check(err) + var title string + if len(tag) > 0 { + title = tag + } else { + title = config.Title + } + doc := layout(string(tbytes), config, title) + feed := doc.Find(".h-feed") + tpl := feed.Find(".h-entry") + tpl.Remove() + + doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author") + if tag == "" { + doc.Find(".filter").Remove() + } else { + doc.Find(".filter").Find("h3").SetText("#" + tag) + } + + for _, post := range posts { + entry := tpl.Clone() + datetime, err := post.PostMatter.Date.MarshalText() + check(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")) + feed.AppendSelection(entry) + } + + html, err := doc.Html() + check(err) + return html +} + +func renderFeed(title string, config Config, posts []Post, specific string) string { + reader, err := os.Open("templates/feed.xml") + check(err) + doc, err := xmlquery.Parse(reader) + 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("updated").FirstChild.Data = string(datetime) + tpl := feed.SelectElement("entry") + xmlquery.RemoveFromTree(tpl) + + for _, post := range posts { + text, err := xml.MarshalIndent(&FeedEntry{ + Title: post.Title, + Link: makeLink(post.URL), + Id: makeTagURI(config, post.Basename), + Updated: post.Date, + Summary: post.Description, + Author: config.Title, + Content: FeedContent{ + Content: post.Content, + Type: "html", + }, + }, " ", " ") + check(err) + entry, err := xmlquery.ParseWithOptions(strings.NewReader(string(text)), xmlquery.ParserOptions{ + Decoder: &xmlquery.DecoderOptions{ + Strict: false, + AutoClose: xml.HTMLAutoClose, + Entity: xml.HTMLEntity, + }, + }) + check(err) + xmlquery.AddChild(feed, entry.SelectElement("entry")) + } + + return doc.OutputXML(true) +} + +func main() { + err, config := GetConfig() + check(err) + err = os.MkdirAll("public/post", 0755) + check(err) + log.Print("Generating site...") + posts, tags := readPosts("content", "post", "public") + for _, post := range posts { + err := os.MkdirAll(path.Join("public", "post", post.Basename), 0755) + check(err) + // output := renderPost(post, config) + // err = os.WriteFile(post.Output, []byte(output), 0755) + // check(err) + } + err = os.MkdirAll("public/tags", 0755) + check(err) + // fmt.Printf("%+v\n", renderTags(tags, config)) + // err = os.WriteFile("public/tags/index.html", []byte(renderTags(tags, config)), 0755) + // check(err) + for _, tag := range tags.ToSlice() { + matchingPosts := []Post{} + for _, post := range posts { + if slices.Contains(post.Taxonomies.Tags, tag) { + matchingPosts = append(matchingPosts, post) + } + } + err := os.MkdirAll(path.Join("public", "tags", tag), 0755) + check(err) + // tagPage := renderListPage(tag, config, matchingPosts) + // fmt.Printf("%+v\n", tagPage) + // err = os.WriteFile(path.Join("public", "tags", tag, "index.html"), []byte(tagPage), 0755) + // check(err) + + // TODO: tag atom + // fmt.Printf("%+v\n", renderFeed(fmt.Sprintf("%s - %s", config.Title, tag), config, matchingPosts, tag)) + + // fmt.Printf("%+v\n", renderListPage("", config, posts)) + + // TODO: atom + // fmt.Printf("%+v\n", renderFeed(config.Title, config, posts, "feed")) + + // TODO: renderFeedStyles + + // TODO: renderHomepage + + // TODO: render404Page + } + + fmt.Printf("%+v\n", tags) + fmt.Println() +} diff --git a/go.mod b/go.mod index da450e0..dbebe7b 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,14 @@ require ( github.com/PuerkitoBio/goquery v1.9.1 // indirect github.com/adrg/frontmatter v0.2.0 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect + github.com/antchfx/xmlquery v1.4.0 // indirect + github.com/antchfx/xpath v1.3.0 // indirect github.com/deckarep/golang-set/v2 v2.6.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/yuin/goldmark v1.7.1 // indirect go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect golang.org/x/net v0.21.0 // indirect + golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0a9eadb..de84a45 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,14 @@ github.com/adrg/frontmatter v0.2.0 h1:/DgnNe82o03riBd1S+ZDjd43wAmC6W35q67NHeLkPd github.com/adrg/frontmatter v0.2.0/go.mod h1:93rQCj3z3ZlwyxxpQioRKC1wDLto4aXHrbqIsnH9wmE= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= +github.com/antchfx/xmlquery v1.4.0 h1:xg2HkfcRK2TeTbdb0m1jxCYnvsPaGY/oeZWTGqX/0hA= +github.com/antchfx/xmlquery v1.4.0/go.mod h1:Ax2aeaeDjfIw3CwXKDQ0GkwZ6QlxoChlIBP+mGnDFjI= +github.com/antchfx/xpath v1.3.0 h1:nTMlzGAK3IJ0bPpME2urTuFL76o4A96iYvoKFHRXJgc= +github.com/antchfx/xpath v1.3.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= @@ -22,6 +28,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= @@ -44,6 +51,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..aa46e6a --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,37 @@ +package config + +import ( + "github.com/BurntSushi/toml" +) + +type Taxonomy struct { + Name string + Feed bool +} + +type MenuItem struct { + Name string + URL string `toml:"url"` +} + +type Config struct { + DefaultLanguage string `toml:"default_language"` + BaseURL string `toml:"base_url"` + RedirectOtherHostnames bool `toml:"redirect_other_hostnames"` + Title string + Email string + Description string + DomainStartDate string `toml:"domain_start_date"` + OriginalDomain string `toml:"original_domain"` + Taxonomies []Taxonomy + Extra struct { + Headers map[string]string + } + Menus map[string][]MenuItem +} + +func GetConfig() (error, Config) { + config := Config{} + _, err := toml.DecodeFile("config.toml", &config) + return err, config +} diff --git a/src/build.go b/src/build.go deleted file mode 100644 index 3c2dfd5..0000000 --- a/src/build.go +++ /dev/null @@ -1,245 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "log" - "os" - "path" - "path/filepath" - "slices" - "strings" - "time" - - "github.com/PuerkitoBio/goquery" - "github.com/adrg/frontmatter" - mapset "github.com/deckarep/golang-set/v2" - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/extension" -) - -type PostMatter struct { - Date time.Time `toml:"date"` - Description string `toml:"description"` - Title string `toml:"title"` - Taxonomies struct { - Tags []string `toml:"tags"` - } `toml:"taxonomies"` -} - -type Post struct { - Input string - Output string - Basename string - URL string - Content string - PostMatter -} - -type Tags mapset.Set[string] - -func check(err error) { - if err != nil { - log.Panic(err) - } -} - -func getPost(filename string) (PostMatter, []byte) { - matter := PostMatter{} - content, err := os.Open(filename) - check(err) - rest, err := frontmatter.Parse(content, &matter) - check(err) - - return matter, rest -} - -func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags) { - tags := mapset.NewSet[string]() - posts := []Post{} - subdir := filepath.Join(root, inputDir) - files, err := os.ReadDir(subdir) - outputReplacer := strings.NewReplacer(root, outputDir, ".md", "/index.html") - urlReplacer := strings.NewReplacer(root, "", ".md", "/") - check(err) - md := goldmark.New( - goldmark.WithExtensions( - extension.GFM, - extension.Footnote, - extension.Typographer, - ), - ) - for _, f := range files { - pathFromRoot := filepath.Join(subdir, f.Name()) - check(err) - if !f.IsDir() && path.Ext(pathFromRoot) == ".md" { - output := outputReplacer.Replace(pathFromRoot) - url := urlReplacer.Replace(pathFromRoot) - matter, content := getPost(pathFromRoot) - - for _, tag := range matter.Taxonomies.Tags { - tags.Add(strings.ToLower(tag)) - } - - var buf bytes.Buffer - err := md.Convert(content, &buf) - check(err) - post := Post{ - Input: pathFromRoot, - Output: output, - Basename: filepath.Base(url), - URL: url, - PostMatter: matter, - Content: buf.String(), - } - - posts = append(posts, post) - } - } - slices.SortFunc(posts, func(a, b Post) int { - return b.Date.Compare(a.Date) - }) - return posts, tags -} - -func layout(html string, config Config, pageTitle string) *goquery.Document { - css, err := os.ReadFile("templates/style.css") - check(err) - doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)) - check(err) - doc.Find("html").SetAttr("lang", config.DefaultLanguage) - doc.Find("head > link[rel=alternate]").Add(".title").SetAttr("title", config.Title) - doc.Find("title").Add(".p-name").SetText(pageTitle) - doc.Find("head > style").SetText(string(css)) - nav := doc.Find("nav") - navLink := doc.Find("nav a") - nav.Empty() - for _, link := range config.Menus["main"] { - nav.AppendSelection(navLink.Clone().SetAttr("href", link.URL).SetText(link.Name)) - } - return doc -} - -func renderPost(post Post, config Config) string { - tbytes, err := os.ReadFile("templates/post.html") - check(err) - doc := layout(string(tbytes), config, post.PostMatter.Title) - doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author") - datetime, err := post.PostMatter.Date.MarshalText() - check(err) - doc.Find(".h-entry .dt-published").SetAttr("datetime", string(datetime)).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() - for _, tag := range post.Taxonomies.Tags { - categories.AppendSelection(cat.Clone().Find(".p-category").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)).Parent() - } - html, err := doc.Html() - check(err) - return html -} - -func renderTags(tags Tags, config Config) string { - tbytes, err := os.ReadFile("templates/tags.html") - check(err) - - doc := layout(string(tbytes), config, config.Title) - tagList := doc.Find(".tags") - 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), - ) - } - html, err := doc.Html() - check(err) - return html -} - -func renderListPage(tag string, config Config, posts []Post) string { - tbytes, err := os.ReadFile("templates/list.html") - check(err) - var title string - if len(tag) > 0 { - title = tag - } else { - title = config.Title - } - doc := layout(string(tbytes), config, title) - feed := doc.Find(".h-feed") - tpl := feed.Find(".h-entry") - tpl.Remove() - - doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author") - if tag == "" { - doc.Find(".filter").Remove() - } else { - doc.Find(".filter").Find("h3").SetText("#" + tag) - } - - for _, post := range posts { - entry := tpl.Clone() - datetime, err := post.PostMatter.Date.MarshalText() - check(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")) - feed.AppendSelection(entry) - } - - html, err := doc.Html() - check(err) - return html -} - -func main() { - config := getConfig() - err := os.MkdirAll("public/post", 0755) - check(err) - log.Print("Generating site...") - posts, tags := readPosts("content", "post", "public") - for _, post := range posts { - err := os.MkdirAll(path.Join("public", "post", post.Basename), 0755) - check(err) - // output := renderPost(post, config) - // err = os.WriteFile(post.Output, []byte(output), 0755) - // check(err) - } - err = os.MkdirAll("public/tags", 0755) - check(err) - // fmt.Printf("%+v\n", renderTags(tags, config)) - // err = os.WriteFile("public/tags/index.html", []byte(renderTags(tags, config)), 0755) - // check(err) - for _, tag := range tags.ToSlice() { - matchingPosts := []Post{} - for _, post := range posts { - if slices.Contains(post.Taxonomies.Tags, tag) { - matchingPosts = append(matchingPosts, post) - } - } - err := os.MkdirAll(path.Join("public", "tags", tag), 0755) - check(err) - // tagPage := renderListPage(tag, config, matchingPosts) - // fmt.Printf("%+v\n", tagPage) - // err = os.WriteFile(path.Join("public", "tags", tag, "index.html"), []byte(tagPage), 0755) - // check(err) - - // TODO: tag atom - - fmt.Printf("%+v\n", renderListPage("", config, posts)) - - // TODO: atom - - // TODO: renderFeedStyles - - // TODO: renderHomepage - - // TODO: render404Page - } - - fmt.Printf("%+v\n", tags) -} diff --git a/src/config.go b/src/config.go deleted file mode 100644 index bfa3052..0000000 --- a/src/config.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "github.com/BurntSushi/toml" -) - -type Taxonomy struct { - Name string - Feed bool -} - -type MenuItem struct { - Name string - URL string `toml:"url"` -} - -type Config struct { - DefaultLanguage string `toml:"default_language"` - BaseURL string `toml:"base_url"` - RedirectOtherHostnames bool `toml:"redirect_other_hostnames"` - Title string - Email string - Description string - DomainStartDate string `toml:"domain_start_date"` - OriginalDomain string `toml:"original_domain"` - Taxonomies []Taxonomy - Extra struct { - Headers map[string]string - } - Menus map[string][]MenuItem -} - -func getConfig() Config { - config := Config{} - _, err := toml.DecodeFile("config.toml", &config) - check(err) - return config -} -- cgit 1.4.1