diff --git a/cmd/ssg/main.go b/cmd/ssg/main.go
index 4ac526e..ea850ab 100644
--- a/cmd/ssg/main.go
+++ b/cmd/ssg/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"flag"
"io/ioutil"
"log"
@@ -12,7 +13,8 @@ import (
)
var (
- resources = flag.String("resources", "./resources/ewnl", "folder with templates and other resources")
+ siteName = flag.String("site", "ewnl", "site id, either 'ewnl' or 'vkvnl'")
+ resources = flag.String("resources", "./resources", "folder with templates and other resources")
content = flag.String("content", "./content,/projectx", "comma separated list of folders search for content")
statics = flag.String("statics", "./statics", "folder with static content")
public = flag.String("public", "./public", "target folder for generated site")
@@ -20,12 +22,22 @@ var (
func main() {
flag.Parse()
- if *resources == "" || *content == "" || *public == "" || *statics == "" {
+ if *siteName == "" || *resources == "" || *content == "" || *public == "" || *statics == "" {
log.Fatal("missing parameter")
}
+ var siteId site.SiteID
+ switch *siteName {
+ case "ewnl":
+ siteId = site.SITE_EWNL
+ case "vkvnl":
+ siteId = site.SITE_VKVNL
+ default:
+ log.Fatal(errors.New("unknown site"))
+ }
+
// initialize site
- config, err := site.NewSiteConfig(site.SITE_EWNL)
+ config, err := site.NewSiteConfig(siteId)
if err != nil {
log.Fatal(err)
}
diff --git a/cmd/ssg/resources/vkvnl/template/post.gohtml b/cmd/ssg/resources/vkvnl/template/post.gohtml
new file mode 100644
index 0000000..d735ca3
--- /dev/null
+++ b/cmd/ssg/resources/vkvnl/template/post.gohtml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+ {{ .Title }}
+
+
+
+
+
+ {{ .Title }}
+ Erik Winter -
+ .
+ {{ .Content }}
+
+
+
+
diff --git a/cmd/ssg/resources/vkvnl/template/rss.goxml b/cmd/ssg/resources/vkvnl/template/rss.goxml
new file mode 100644
index 0000000..c8fc7be
--- /dev/null
+++ b/cmd/ssg/resources/vkvnl/template/rss.goxml
@@ -0,0 +1,20 @@
+
+
+
+ VrijKorteVerhalen.nl
+ https://vrijkorteverhalen.nl/
+ VKV's op VrijKorteVerhalen.nl
+ nl-nl
+ {{ .DateFormal }}
+
+ {{- range .Posts -}}
+ -
+ {{ .Title }}
+ {{ .Link }}
+ {{ .DateFormal }}
+ {{ .Link }}
+ {{ .Content }}
+
+ {{- end -}}
+
+
diff --git a/cmd/ssg/site/config.go b/cmd/ssg/site/config.go
index 96bac38..7f52c4f 100644
--- a/cmd/ssg/site/config.go
+++ b/cmd/ssg/site/config.go
@@ -16,7 +16,8 @@ var (
type SiteID string
const (
- SITE_EWNL = SiteID("ewnl")
+ SITE_EWNL = SiteID("ewnl")
+ SITE_VKVNL = SiteID("vkvnl")
)
type TemplateConfig struct {
@@ -42,6 +43,8 @@ func NewSiteConfig(id SiteID) (*SiteConfig, error) {
switch id {
case SITE_EWNL:
config = SITE_CONFIG_EWNL
+ case SITE_VKVNL:
+ config = SITE_CONFIG_VKVNL
default:
return &SiteConfig{}, ErrUnknownSiteID
}
diff --git a/cmd/ssg/site/rendervkvnl.go b/cmd/ssg/site/rendervkvnl.go
new file mode 100644
index 0000000..9b658b9
--- /dev/null
+++ b/cmd/ssg/site/rendervkvnl.go
@@ -0,0 +1,88 @@
+package site
+
+import (
+ "os"
+ "path/filepath"
+ "text/template"
+ "time"
+)
+
+func renderVKVNLPosts(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
+ last, first := 0, len(posts)-1 // posts are sorted in reverse order
+ for i, post := range posts {
+ pData := post.HTMLPost()
+ if pData.Slug == "" {
+ return ErrInvalidPost
+ }
+
+ data := struct {
+ Slug string
+ Title string
+ DateLong string
+ DateShort string
+ Content string
+ PreviousLink string
+ NextLink string
+ }{
+ Slug: pData.Slug,
+ Title: pData.Title,
+ DateLong: pData.DateLong,
+ DateShort: pData.DateShort,
+ Content: pData.Content,
+ }
+
+ path := targetPath
+ if i != first {
+ data.PreviousLink = posts[i+1].Link()
+ }
+ if i != last {
+ data.NextLink = posts[i-1].Link()
+ if i == last+1 {
+ data.NextLink = "/"
+ }
+ path = filepath.Join(targetPath, post.Year(), data.Slug)
+ }
+ if i == last-1 {
+ }
+
+ if err := os.MkdirAll(path, dirMode); err != nil {
+ return err
+ }
+
+ nPath := filepath.Join(path, "index.html")
+ f, err := os.Create(nPath)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ if err := tpl.Execute(f, data); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func renderVKVNLRSS(targetPath string, tpl *template.Template, posts Posts, _ []*StaticPage) error {
+ rssPath := filepath.Join(targetPath, "index.xml")
+ rssFile, err := os.Create(rssPath)
+ if err != nil {
+ return err
+ }
+ defer rssFile.Close()
+
+ var xmlPosts []*XMLPost
+ for _, p := range posts.RemoveKind(KIND_NOTE).Limit(10) {
+ xmlPosts = append(xmlPosts, p.XMLPost())
+ }
+
+ data := struct {
+ DateFormal string
+ Posts []*XMLPost
+ }{
+ DateFormal: time.Now().Format(time.RFC1123Z),
+ Posts: xmlPosts,
+ }
+ return tpl.Execute(rssFile, data)
+}
diff --git a/cmd/ssg/site/sites.go b/cmd/ssg/site/sites.go
index 98a17bc..f4941b7 100644
--- a/cmd/ssg/site/sites.go
+++ b/cmd/ssg/site/sites.go
@@ -53,4 +53,27 @@ var (
adoc.KIND_ARTICLE: KIND_ARTICLE,
},
}
+
+ SITE_CONFIG_VKVNL = &SiteConfig{
+ ID: SITE_VKVNL,
+ BaseURL: "https://vrijkorteverhalen.nl",
+ PathsWithKind: false,
+ TemplateConfigs: []*TemplateConfig{
+ {
+ Name: "post",
+ TemplateNames: []string{"post"},
+ TemplateExt: "gohtml",
+ Render: renderVKVNLPosts,
+ },
+ {
+ Name: "rss",
+ TemplateNames: []string{"rss"},
+ TemplateExt: "goxml",
+ Render: renderVKVNLRSS,
+ },
+ },
+ KindMap: map[adoc.Kind]Kind{
+ adoc.KIND_VKV: KIND_STORY,
+ },
+ }
)