parent
f12035df9c
commit
310a032195
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -12,7 +13,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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")
|
content = flag.String("content", "./content,/projectx", "comma separated list of folders search for content")
|
||||||
statics = flag.String("statics", "./statics", "folder with static content")
|
statics = flag.String("statics", "./statics", "folder with static content")
|
||||||
public = flag.String("public", "./public", "target folder for generated site")
|
public = flag.String("public", "./public", "target folder for generated site")
|
||||||
|
@ -20,12 +22,22 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *resources == "" || *content == "" || *public == "" || *statics == "" {
|
if *siteName == "" || *resources == "" || *content == "" || *public == "" || *statics == "" {
|
||||||
log.Fatal("missing parameter")
|
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
|
// initialize site
|
||||||
config, err := site.NewSiteConfig(site.SITE_EWNL)
|
config, err := site.NewSiteConfig(siteId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="alternate" type="application/rss+xml" title="vrijkorteverhalen.nl" href="/index.xml"/>
|
||||||
|
<title>{{ .Title }}</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body { margin: 40px auto; max-width: 650px; line-height: 1.6; font-size: 18px; color: #000; padding:0 10px; }
|
||||||
|
h1, h2, h3 { line-height:1.2; }
|
||||||
|
a { color: #000; }
|
||||||
|
#footer { margin-top: 25px; text-align: center; }
|
||||||
|
</style>
|
||||||
|
<script data-goatcounter="https://vkv.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<article>
|
||||||
|
<h1>{{ .Title }}</h1>
|
||||||
|
<a rel="author" href="https://erikwinter.nl/about">Erik Winter</a> -
|
||||||
|
<time pubdate="" datetime="{{ .DateShort }}">{{ .DateLong }}</time>.
|
||||||
|
{{ .Content }}
|
||||||
|
<p id="footer">
|
||||||
|
{{ if ne "" .PreviousLink -}}<a href="{{ .PreviousLink }}">Vorige</a>{{ end }}
|
||||||
|
{{ if ne "" .NextLink }}<a href="{{ .NextLink }}">Volgende</a>{{ end }}
|
||||||
|
</p>
|
||||||
|
</article>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||||
|
<channel>
|
||||||
|
<title>VrijKorteVerhalen.nl</title>
|
||||||
|
<link>https://vrijkorteverhalen.nl/</link>
|
||||||
|
<description>VKV's op VrijKorteVerhalen.nl</description>
|
||||||
|
<language>nl-nl</language>
|
||||||
|
<lastBuildDate>{{ .DateFormal }}</lastBuildDate>
|
||||||
|
<atom:link href="https://vrijkorteverhalen.nl/index.xml" rel="self" type="application/rss+xml" />
|
||||||
|
{{- range .Posts -}}
|
||||||
|
<item>
|
||||||
|
<title>{{ .Title }}</title>
|
||||||
|
<link>{{ .Link }}</link>
|
||||||
|
<pubDate>{{ .DateFormal }}</pubDate>
|
||||||
|
<guid>{{ .Link }}</guid>
|
||||||
|
<description>{{ .Content }}</description>
|
||||||
|
</item>
|
||||||
|
{{- end -}}
|
||||||
|
</channel>
|
||||||
|
</rss>
|
|
@ -16,7 +16,8 @@ var (
|
||||||
type SiteID string
|
type SiteID string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SITE_EWNL = SiteID("ewnl")
|
SITE_EWNL = SiteID("ewnl")
|
||||||
|
SITE_VKVNL = SiteID("vkvnl")
|
||||||
)
|
)
|
||||||
|
|
||||||
type TemplateConfig struct {
|
type TemplateConfig struct {
|
||||||
|
@ -42,6 +43,8 @@ func NewSiteConfig(id SiteID) (*SiteConfig, error) {
|
||||||
switch id {
|
switch id {
|
||||||
case SITE_EWNL:
|
case SITE_EWNL:
|
||||||
config = SITE_CONFIG_EWNL
|
config = SITE_CONFIG_EWNL
|
||||||
|
case SITE_VKVNL:
|
||||||
|
config = SITE_CONFIG_VKVNL
|
||||||
default:
|
default:
|
||||||
return &SiteConfig{}, ErrUnknownSiteID
|
return &SiteConfig{}, ErrUnknownSiteID
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -53,4 +53,27 @@ var (
|
||||||
adoc.KIND_ARTICLE: KIND_ARTICLE,
|
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,
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue