preparing for multiple sites, removed notes from home
This commit is contained in:
parent
166658eba6
commit
941b1dfbbf
|
@ -25,7 +25,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize site
|
// initialize site
|
||||||
s, err := site.New(*resources)
|
config, err := site.NewSiteConfig(site.SITE_EWNL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
s, err := site.New(config, *resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package site
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrUnknownSiteID = errors.New("unknown site id")
|
||||||
|
)
|
||||||
|
|
||||||
|
type SiteID string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SITE_EWNL = SiteID("ewnl")
|
||||||
|
SITE_VKVNL = SiteID("vkvnl")
|
||||||
|
)
|
||||||
|
|
||||||
|
type TemplateConfig struct {
|
||||||
|
Name string
|
||||||
|
TemplateNames []string
|
||||||
|
TemplateExt string
|
||||||
|
Template *template.Template
|
||||||
|
Render func(targetPath string, tpl *template.Template, posts Posts, staticPages []*StaticPage) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type SiteConfig struct {
|
||||||
|
ID SiteID
|
||||||
|
BaseURL string
|
||||||
|
TemplateConfigs []*TemplateConfig
|
||||||
|
RSS bool
|
||||||
|
StaticPages []*StaticPage
|
||||||
|
KindMap map[adoc.Kind]Kind
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSiteConfig(id SiteID) (*SiteConfig, error) {
|
||||||
|
var config *SiteConfig
|
||||||
|
|
||||||
|
switch id {
|
||||||
|
case SITE_EWNL:
|
||||||
|
config = SITE_CONFIG_EWNL
|
||||||
|
case SITE_VKVNL:
|
||||||
|
config = SITE_CONFIG_VKVNL
|
||||||
|
default:
|
||||||
|
return &SiteConfig{}, ErrUnknownSiteID
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *SiteConfig) ParseTemplates(tplPath string) error {
|
||||||
|
for _, tplConf := range sc.TemplateConfigs {
|
||||||
|
for _, tName := range tplConf.TemplateNames {
|
||||||
|
var tFiles []string
|
||||||
|
tFiles = append(tFiles, filepath.Join(tplPath, fmt.Sprintf("%s.%s", tName, tplConf.TemplateExt)))
|
||||||
|
tpl, err := template.ParseFiles(tFiles...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tplConf.Template = tpl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *SiteConfig) MapKind(docKind adoc.Kind) Kind {
|
||||||
|
siteKind, ok := sc.KindMap[docKind]
|
||||||
|
if !ok {
|
||||||
|
return KIND_INVALID
|
||||||
|
}
|
||||||
|
|
||||||
|
return siteKind
|
||||||
|
}
|
|
@ -13,24 +13,6 @@ const (
|
||||||
|
|
||||||
type Kind string
|
type Kind string
|
||||||
|
|
||||||
func NewKind(kind adoc.Kind) Kind {
|
|
||||||
switch kind {
|
|
||||||
case adoc.KIND_NOTE:
|
|
||||||
return KIND_NOTE
|
|
||||||
case adoc.KIND_VKV:
|
|
||||||
return KIND_STORY
|
|
||||||
case adoc.KIND_ESSAY:
|
|
||||||
fallthrough
|
|
||||||
case adoc.KIND_ARTICLE:
|
|
||||||
fallthrough
|
|
||||||
case adoc.KIND_TUTORIAL:
|
|
||||||
return KIND_ARTICLE
|
|
||||||
default:
|
|
||||||
return KIND_INVALID
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LANGUAGE_EN = Language("en")
|
LANGUAGE_EN = Language("en")
|
||||||
LANGUAGE_NL = Language("nl")
|
LANGUAGE_NL = Language("nl")
|
||||||
|
|
|
@ -8,53 +8,6 @@ import (
|
||||||
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewKind(t *testing.T) {
|
|
||||||
for _, tc := range []struct {
|
|
||||||
name string
|
|
||||||
input adoc.Kind
|
|
||||||
exp site.Kind
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "empty",
|
|
||||||
exp: site.KIND_INVALID,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "note",
|
|
||||||
input: adoc.KIND_NOTE,
|
|
||||||
exp: site.KIND_NOTE,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "work",
|
|
||||||
input: adoc.KIND_WORK,
|
|
||||||
exp: site.KIND_INVALID,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "vkv",
|
|
||||||
input: adoc.KIND_VKV,
|
|
||||||
exp: site.KIND_STORY,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "essay",
|
|
||||||
input: adoc.KIND_ESSAY,
|
|
||||||
exp: site.KIND_ARTICLE,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "article",
|
|
||||||
input: adoc.KIND_ARTICLE,
|
|
||||||
exp: site.KIND_ARTICLE,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "tutorial",
|
|
||||||
input: adoc.KIND_TUTORIAL,
|
|
||||||
exp: site.KIND_ARTICLE,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
test.Equals(t, tc.exp, site.NewKind(tc.input))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewLanguage(t *testing.T) {
|
func TestNewLanguage(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Post struct {
|
||||||
Tags []Tag
|
Tags []Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPost(doc *adoc.ADoc) *Post {
|
func NewPost(config *SiteConfig, doc *adoc.ADoc) *Post {
|
||||||
var tags []Tag
|
var tags []Tag
|
||||||
for _, t := range doc.Tags {
|
for _, t := range doc.Tags {
|
||||||
tags = append(tags, Tag(t))
|
tags = append(tags, Tag(t))
|
||||||
|
@ -39,7 +39,7 @@ func NewPost(doc *adoc.ADoc) *Post {
|
||||||
return &Post{
|
return &Post{
|
||||||
doc: doc,
|
doc: doc,
|
||||||
Date: doc.Date,
|
Date: doc.Date,
|
||||||
Kind: NewKind(doc.Kind),
|
Kind: config.MapKind(doc.Kind),
|
||||||
Language: Language(doc.Language),
|
Language: Language(doc.Language),
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,19 +10,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPost(t *testing.T) {
|
func TestPost(t *testing.T) {
|
||||||
|
docKind := adoc.KIND_NOTE
|
||||||
|
siteKind := site.Kind(docKind)
|
||||||
|
config := &site.SiteConfig{
|
||||||
|
KindMap: map[adoc.Kind]site.Kind{
|
||||||
|
docKind: siteKind,
|
||||||
|
},
|
||||||
|
}
|
||||||
title := "title thing"
|
title := "title thing"
|
||||||
author := "author"
|
author := "author"
|
||||||
kind := adoc.KIND_NOTE
|
|
||||||
language := adoc.LANGUAGE_EN
|
language := adoc.LANGUAGE_EN
|
||||||
path := "/path"
|
path := "/path"
|
||||||
date := time.Date(2020, 12, 28, 7, 23, 45, 0, time.UTC)
|
date := time.Date(2020, 12, 28, 7, 23, 45, 0, time.UTC)
|
||||||
tag1, tag2 := adoc.Tag("tag1"), adoc.Tag("tag2")
|
tag1, tag2 := adoc.Tag("tag1"), adoc.Tag("tag2")
|
||||||
par1 := adoc.Paragraph{adoc.PlainText("one")}
|
par1 := adoc.Paragraph{adoc.PlainText("one")}
|
||||||
par2 := adoc.Paragraph{adoc.PlainText("two")}
|
par2 := adoc.Paragraph{adoc.PlainText("two")}
|
||||||
post := site.NewPost(&adoc.ADoc{
|
post := site.NewPost(config, &adoc.ADoc{
|
||||||
Title: title,
|
Title: title,
|
||||||
Author: author,
|
Author: author,
|
||||||
Kind: kind,
|
Kind: docKind,
|
||||||
Language: language,
|
Language: language,
|
||||||
Path: path,
|
Path: path,
|
||||||
Date: date,
|
Date: date,
|
||||||
|
@ -32,7 +38,7 @@ func TestPost(t *testing.T) {
|
||||||
|
|
||||||
t.Run("new", func(t *testing.T) {
|
t.Run("new", func(t *testing.T) {
|
||||||
test.Equals(t, date, post.Date)
|
test.Equals(t, date, post.Date)
|
||||||
test.Equals(t, site.Kind(kind), post.Kind)
|
test.Equals(t, siteKind, post.Kind)
|
||||||
test.Equals(t, site.Language(language), post.Language)
|
test.Equals(t, site.Language(language), post.Language)
|
||||||
test.Equals(t, []site.Tag{site.Tag(tag1), site.Tag(tag2)}, post.Tags)
|
test.Equals(t, []site.Tag{site.Tag(tag1), site.Tag(tag2)}, post.Tags)
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (p Posts) Sort() Posts {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Posts) FilterByKind(wanted Kind) Posts {
|
func (p Posts) SelectKind(wanted Kind) Posts {
|
||||||
pList := Posts{}
|
pList := Posts{}
|
||||||
for _, post := range p {
|
for _, post := range p {
|
||||||
if post.Kind == wanted {
|
if post.Kind == wanted {
|
||||||
|
@ -26,7 +26,7 @@ func (p Posts) FilterByKind(wanted Kind) Posts {
|
||||||
return pList
|
return pList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Posts) FilterByYear(year string) Posts {
|
func (p Posts) SelectYear(year string) Posts {
|
||||||
pList := Posts{}
|
pList := Posts{}
|
||||||
for _, post := range p {
|
for _, post := range p {
|
||||||
if post.Year() == year {
|
if post.Year() == year {
|
||||||
|
@ -37,7 +37,7 @@ func (p Posts) FilterByYear(year string) Posts {
|
||||||
return pList
|
return pList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Posts) FilterByTag(wanted Tag) Posts {
|
func (p Posts) SelectTag(wanted Tag) Posts {
|
||||||
pList := Posts{}
|
pList := Posts{}
|
||||||
|
|
||||||
POSTS:
|
POSTS:
|
||||||
|
@ -54,6 +54,18 @@ POSTS:
|
||||||
return pList
|
return pList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Posts) RemoveKind(kind Kind) Posts {
|
||||||
|
pList := Posts{}
|
||||||
|
for _, post := range p {
|
||||||
|
if post.Kind == kind {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pList = append(pList, post)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pList
|
||||||
|
}
|
||||||
|
|
||||||
func (p Posts) Limit(limit int) Posts {
|
func (p Posts) Limit(limit int) Posts {
|
||||||
if len(p) <= limit {
|
if len(p) <= limit {
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -51,16 +51,20 @@ func TestPosts(t *testing.T) {
|
||||||
|
|
||||||
posts := site.Posts{post1, post2, post3}
|
posts := site.Posts{post1, post2, post3}
|
||||||
|
|
||||||
t.Run("filter kind", func(t *testing.T) {
|
t.Run("select kind", func(t *testing.T) {
|
||||||
test.Equals(t, site.Posts{post1, post3}, posts.FilterByKind(kind1))
|
test.Equals(t, site.Posts{post1, post3}, posts.SelectKind(kind1))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("filter year", func(t *testing.T) {
|
t.Run("select year", func(t *testing.T) {
|
||||||
test.Equals(t, site.Posts{post2}, posts.FilterByYear("2019"))
|
test.Equals(t, site.Posts{post2}, posts.SelectYear("2019"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("tilter tag", func(t *testing.T) {
|
t.Run("select tag", func(t *testing.T) {
|
||||||
test.Equals(t, site.Posts{post2, post3}, posts.FilterByTag(tag2))
|
test.Equals(t, site.Posts{post2, post3}, posts.SelectTag(tag2))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("remove kind", func(t *testing.T) {
|
||||||
|
test.Equals(t, site.Posts{post2}, posts.RemoveKind(kind1))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("limit", func(t *testing.T) {
|
t.Run("limit", func(t *testing.T) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ func moveResources(targetPath, resourcesPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderStaticPages(targetPath string, tpl *template.Template, statics []*StaticPage) error {
|
func renderStaticPages(targetPath string, tpl *template.Template, _ Posts, statics []*StaticPage) error {
|
||||||
for _, static := range statics {
|
for _, static := range statics {
|
||||||
destPath := filepath.Join(targetPath, static.Name)
|
destPath := filepath.Join(targetPath, static.Name)
|
||||||
if err := os.MkdirAll(destPath, dirMode); err != nil {
|
if err := os.MkdirAll(destPath, dirMode); err != nil {
|
||||||
|
@ -68,9 +68,9 @@ func renderStaticPages(targetPath string, tpl *template.Template, statics []*Sta
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderHome(targetPath string, tpl *template.Template, posts Posts) error {
|
func renderHome(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
|
||||||
var summaries []*HTMLSummary
|
var summaries []*HTMLSummary
|
||||||
for _, p := range posts {
|
for _, p := range posts.RemoveKind(KIND_NOTE).Limit(10) {
|
||||||
summaries = append(summaries, p.HTMLSummary())
|
summaries = append(summaries, p.HTMLSummary())
|
||||||
}
|
}
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -91,7 +91,7 @@ func renderHome(targetPath string, tpl *template.Template, posts Posts) error {
|
||||||
return tpl.Execute(homeFile, data)
|
return tpl.Execute(homeFile, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderArchive(targetPath string, tpl *template.Template, title string, posts Posts) error {
|
func renderArchive(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
|
||||||
archPath := filepath.Join(targetPath, "archive")
|
archPath := filepath.Join(targetPath, "archive")
|
||||||
if err := os.MkdirAll(archPath, dirMode); err != nil {
|
if err := os.MkdirAll(archPath, dirMode); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -120,7 +120,7 @@ func renderArchive(targetPath string, tpl *template.Template, title string, post
|
||||||
KIND_STORY: {},
|
KIND_STORY: {},
|
||||||
}
|
}
|
||||||
for kind := range yearLinks {
|
for kind := range yearLinks {
|
||||||
for _, year := range posts.FilterByKind(kind).YearList() {
|
for _, year := range posts.SelectKind(kind).YearList() {
|
||||||
yearLinks[kind] = append(yearLinks[kind], link{
|
yearLinks[kind] = append(yearLinks[kind], link{
|
||||||
Name: year,
|
Name: year,
|
||||||
Link: fmt.Sprintf("%s/", path.Join("/", pluralKind[kind], year)),
|
Link: fmt.Sprintf("%s/", path.Join("/", pluralKind[kind], year)),
|
||||||
|
@ -135,7 +135,7 @@ func renderArchive(targetPath string, tpl *template.Template, title string, post
|
||||||
NoteYears []link
|
NoteYears []link
|
||||||
StoryYears []link
|
StoryYears []link
|
||||||
}{
|
}{
|
||||||
Title: title,
|
Title: "Archive",
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
ArticleYears: yearLinks[KIND_ARTICLE],
|
ArticleYears: yearLinks[KIND_ARTICLE],
|
||||||
NoteYears: yearLinks[KIND_NOTE],
|
NoteYears: yearLinks[KIND_NOTE],
|
||||||
|
@ -145,11 +145,11 @@ func renderArchive(targetPath string, tpl *template.Template, title string, post
|
||||||
return tpl.Execute(archFile, data)
|
return tpl.Execute(archFile, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderListings(targetPath string, tpl *template.Template, posts Posts) error {
|
func renderListings(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
|
||||||
for _, kind := range []Kind{KIND_NOTE, KIND_STORY, KIND_ARTICLE} {
|
for _, kind := range []Kind{KIND_NOTE, KIND_STORY, KIND_ARTICLE} {
|
||||||
for _, year := range posts.FilterByKind(kind).YearList() {
|
for _, year := range posts.SelectKind(kind).YearList() {
|
||||||
title := fmt.Sprintf("%s in %s", strings.Title(pluralKind[kind]), year)
|
title := fmt.Sprintf("%s in %s", strings.Title(pluralKind[kind]), year)
|
||||||
kyposts := posts.FilterByKind(kind).FilterByYear(year)
|
kyposts := posts.SelectKind(kind).SelectYear(year)
|
||||||
var summaries []*HTMLSummary
|
var summaries []*HTMLSummary
|
||||||
for _, p := range kyposts {
|
for _, p := range kyposts {
|
||||||
summaries = append(summaries, p.HTMLSummary())
|
summaries = append(summaries, p.HTMLSummary())
|
||||||
|
@ -163,7 +163,7 @@ func renderListings(targetPath string, tpl *template.Template, posts Posts) erro
|
||||||
|
|
||||||
for _, tag := range posts.TagList() {
|
for _, tag := range posts.TagList() {
|
||||||
title := fmt.Sprintf("Posts Tagged with \"%s\"", tag)
|
title := fmt.Sprintf("Posts Tagged with \"%s\"", tag)
|
||||||
tposts := posts.FilterByTag(Tag(tag))
|
tposts := posts.SelectTag(Tag(tag))
|
||||||
var summaries []*HTMLSummary
|
var summaries []*HTMLSummary
|
||||||
for _, p := range tposts {
|
for _, p := range tposts {
|
||||||
summaries = append(summaries, p.HTMLSummary())
|
summaries = append(summaries, p.HTMLSummary())
|
||||||
|
@ -198,7 +198,7 @@ func renderListing(path string, tpl *template.Template, title string, summaries
|
||||||
return tpl.Execute(f, data)
|
return tpl.Execute(f, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderPosts(targetPath string, tpl *template.Template, posts Posts) error {
|
func renderPosts(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
|
||||||
for _, post := range posts {
|
for _, post := range posts {
|
||||||
data := post.HTMLPost()
|
data := post.HTMLPost()
|
||||||
if data.Slug == "" {
|
if data.Slug == "" {
|
||||||
|
@ -225,7 +225,7 @@ func renderPosts(targetPath string, tpl *template.Template, posts Posts) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderRSS(targetPath string, tpl *template.Template, posts Posts) error {
|
func renderRSS(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
|
||||||
rssPath := filepath.Join(targetPath, "index.xml")
|
rssPath := filepath.Join(targetPath, "index.xml")
|
||||||
rssFile, err := os.Create(rssPath)
|
rssFile, err := os.Create(rssPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package site
|
package site
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
||||||
)
|
)
|
||||||
|
@ -16,20 +14,19 @@ type StaticPage struct {
|
||||||
|
|
||||||
type Site struct {
|
type Site struct {
|
||||||
resourcesPath string
|
resourcesPath string
|
||||||
templates map[string]*template.Template
|
config *SiteConfig
|
||||||
posts Posts
|
posts Posts
|
||||||
staticPages []*StaticPage
|
staticPages []*StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(resourcesPath string) (*Site, error) {
|
func New(config *SiteConfig, resourcesPath string) (*Site, error) {
|
||||||
templates, err := parseTemplates(resourcesPath)
|
if err := config.ParseTemplates(filepath.Join(resourcesPath, "template")); err != nil {
|
||||||
if err != nil {
|
|
||||||
return &Site{}, err
|
return &Site{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Site{
|
return &Site{
|
||||||
resourcesPath: resourcesPath,
|
resourcesPath: resourcesPath,
|
||||||
templates: templates,
|
config: config,
|
||||||
posts: Posts{},
|
posts: Posts{},
|
||||||
staticPages: []*StaticPage{},
|
staticPages: []*StaticPage{},
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -47,7 +44,7 @@ func (s *Site) AddFilePost(fPath string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
post := NewPost(adoc.New(string(content)))
|
post := NewPost(s.config, adoc.New(string(content)))
|
||||||
if post.Kind != KIND_INVALID {
|
if post.Kind != KIND_INVALID {
|
||||||
s.posts = append(s.posts, post)
|
s.posts = append(s.posts, post)
|
||||||
}
|
}
|
||||||
|
@ -64,52 +61,12 @@ func (s *Site) RenderHTML(targetPath string) error {
|
||||||
if err := moveResources(targetPath, s.resourcesPath); err != nil {
|
if err := moveResources(targetPath, s.resourcesPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := renderStaticPages(targetPath, s.templates["static"], s.staticPages); err != nil {
|
|
||||||
|
for _, tplConf := range s.config.TemplateConfigs {
|
||||||
|
if err := tplConf.Render(targetPath, tplConf.Template, posts, s.staticPages); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := renderArchive(targetPath, s.templates["archive"], "Archive", posts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := renderHome(targetPath, s.templates["list"], posts.Limit(10)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := renderListings(targetPath, s.templates["list"], posts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := renderPosts(targetPath, s.templates["post"], posts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := renderRSS(targetPath, s.templates["rss"], posts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTemplates(resourcesPath string) (map[string]*template.Template, error) {
|
|
||||||
templates := map[string]*template.Template{}
|
|
||||||
tPath := filepath.Join(resourcesPath, "template")
|
|
||||||
for _, tName := range []string{"post", "list", "archive", "static"} {
|
|
||||||
var tFiles []string
|
|
||||||
for _, tf := range []string{tName, "head", "menu"} {
|
|
||||||
tFiles = append(tFiles, filepath.Join(tPath, fmt.Sprintf("%s.gohtml", tf)))
|
|
||||||
}
|
|
||||||
tpl, err := template.ParseFiles(tFiles...)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]*template.Template{}, err
|
|
||||||
}
|
|
||||||
templates[tName] = tpl
|
|
||||||
}
|
|
||||||
|
|
||||||
rss, err := template.ParseFiles(filepath.Join(tPath, "rss.goxml"))
|
|
||||||
if err != nil {
|
|
||||||
return map[string]*template.Template{}, err
|
|
||||||
}
|
|
||||||
templates["rss"] = rss
|
|
||||||
|
|
||||||
return templates, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package site
|
||||||
|
|
||||||
|
import "git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
||||||
|
|
||||||
|
var (
|
||||||
|
SITE_CONFIG_EWNL = &SiteConfig{
|
||||||
|
ID: SITE_EWNL,
|
||||||
|
BaseURL: "https://erikwinter.nl",
|
||||||
|
TemplateConfigs: []*TemplateConfig{
|
||||||
|
{
|
||||||
|
Name: "home",
|
||||||
|
TemplateNames: []string{"list", "head", "menu"},
|
||||||
|
TemplateExt: "gohtml",
|
||||||
|
Render: renderHome,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "listings",
|
||||||
|
TemplateNames: []string{"list", "head", "menu"},
|
||||||
|
TemplateExt: "gohtml",
|
||||||
|
Render: renderListings,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "archive",
|
||||||
|
TemplateNames: []string{"archive", "head", "menu"},
|
||||||
|
TemplateExt: "gohtml",
|
||||||
|
Render: renderArchive,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "static",
|
||||||
|
TemplateNames: []string{"static", "head", "menu"},
|
||||||
|
TemplateExt: "gohtml",
|
||||||
|
Render: renderStaticPages,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "posts",
|
||||||
|
TemplateNames: []string{"post", "head", "menu"},
|
||||||
|
TemplateExt: "gohtml",
|
||||||
|
Render: renderPosts,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "rss",
|
||||||
|
TemplateNames: []string{"rss"},
|
||||||
|
TemplateExt: "goxml",
|
||||||
|
Render: renderRSS,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
KindMap: map[adoc.Kind]Kind{
|
||||||
|
adoc.KIND_NOTE: KIND_NOTE,
|
||||||
|
adoc.KIND_VKV: KIND_STORY,
|
||||||
|
adoc.KIND_ESSAY: KIND_ARTICLE,
|
||||||
|
adoc.KIND_TUTORIAL: KIND_ARTICLE,
|
||||||
|
adoc.KIND_ARTICLE: KIND_ARTICLE,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
SITE_CONFIG_VKVNL = &SiteConfig{}
|
||||||
|
)
|
Loading…
Reference in New Issue