~ewintr/shitty-ssg

bc2be9d337d523caa48d5bd23b709df5fa547e6e — Erik Winter a month ago 7d1f86e
removed vkvnl
6 files changed, 4 insertions(+), 179 deletions(-)

M cmd/ssg/main.go
D cmd/ssg/resources/vkvnl/template/post.gohtml
D cmd/ssg/resources/vkvnl/template/rss.goxml
M cmd/ssg/site/config.go
D cmd/ssg/site/rendervkvnl.go
M cmd/ssg/site/sites.go
M cmd/ssg/main.go => cmd/ssg/main.go +3 -15
@@ 1,7 1,6 @@
package main

import (
	"errors"
	"flag"
	"io/ioutil"
	"log"


@@ 13,8 12,7 @@ import (
)

var (
	siteName  = flag.String("site", "ewnl", "site id, either 'ewnl' or 'vkvnl'")
	resources = flag.String("resources", "./resources", "folder with templates and other resources")
	resources = flag.String("resources", "./resources/ewnl", "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")


@@ 22,22 20,12 @@ var (

func main() {
	flag.Parse()
	if *siteName == "" || *resources == "" || *content == "" || *public == "" || *statics == "" {
	if *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(siteId)
	config, err := site.NewSiteConfig(site.SITE_EWNL)
	if err != nil {
		log.Fatal(err)
	}

D cmd/ssg/resources/vkvnl/template/post.gohtml => cmd/ssg/resources/vkvnl/template/post.gohtml +0 -29
@@ 1,29 0,0 @@
<!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>

D cmd/ssg/resources/vkvnl/template/rss.goxml => cmd/ssg/resources/vkvnl/template/rss.goxml +0 -20
@@ 1,20 0,0 @@
<?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>

M cmd/ssg/site/config.go => cmd/ssg/site/config.go +1 -4
@@ 16,8 16,7 @@ var (
type SiteID string

const (
	SITE_EWNL  = SiteID("ewnl")
	SITE_VKVNL = SiteID("vkvnl")
	SITE_EWNL = SiteID("ewnl")
)

type TemplateConfig struct {


@@ 43,8 42,6 @@ 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
	}

D cmd/ssg/site/rendervkvnl.go => cmd/ssg/site/rendervkvnl.go +0 -88
@@ 1,88 0,0 @@
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)
}

M cmd/ssg/site/sites.go => cmd/ssg/site/sites.go +0 -23
@@ 53,27 53,4 @@ 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,
		},
	}
)