index — crispy-website @ aa9b5732db83de378307c89d25f935bd3e7f141a

My personal homepage (very crispy)

cmd/server/genrss.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
package main

import (
	"fmt"
	"os"
	"text/template"
)

type (
	rssItem struct {
		Title string
		Link  string
	}
)

func genRSSBlog(blogDataSlice []blogData) {
	var rssItemSlice []rssItem
	for _, post := range blogDataSlice {
		rssItemSlice = append(rssItemSlice, rssItem{
			Title: post.Title,
			Link:  post.URL,
		})
	}

	tpl, err := template.ParseFiles("templates/rss.xml.gotmpl")
	if err != nil {
		fmt.Printf("ERROR creating template: %s\n", err)
	}

	f, err := os.Create("html/en/blog/rss.xml.html")
	if err != nil {
		fmt.Printf("ERROR creating xml: %s\n", err)
		panic(1)
	}

	err = tpl.ExecuteTemplate(f, "rss.xml.gotmpl", rssItemSlice)
	if err != nil {
		fmt.Printf("ERROR executing template: %s\n", err)
	}
}

func genRSSBlogRecs(recList []blogRec) {
	tpl, err := template.ParseFiles("templates/blogrecs.xml.gotmpl")
	if err != nil {
		fmt.Printf("ERROR creating template: %s\n", err)
	}

	f, err := os.Create("html/en/blogrecs.xml.html")
	if err != nil {
		fmt.Printf("ERROR creating xml: %s\n", err)
		panic(1)
	}

	err = tpl.ExecuteTemplate(f, "blogrecs.xml.gotmpl", recList)
	if err != nil {
		fmt.Printf("ERROR executing template: %s\n", err)
	}
}