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
|
package main
import (
"io/ioutil"
"os"
"path/filepath"
)
type siteData struct {
name string
rawName string
baseUrl string
sourcePath string
pages map[string]page
nav []navItem
}
func getSites(cfg config) (sites []siteData) {
files, err := ioutil.ReadDir(cfg.DocsRoot)
if err != nil {
panic(err)
}
for _, f := range files {
if f.IsDir() && f.Name() != ".git" {
newSite := siteData{
name: nameify(f.Name()),
rawName: f.Name(),
baseUrl: cfg.BaseUrl + "/" + f.Name(),
sourcePath: filepath.Join(cfg.DocsRoot, f.Name())}
sites = append(sites, newSite)
}
}
return
}
func generateSite(site siteData, cfg config, outputDir string) {
template := loadTemplate(cfg)
templData := templateData{SiteTitle: site.name,
StylesheetUrl: cfg.BaseUrl + "/style.css",
Nav: site.nav}
for k, v := range site.pages {
templData.Content = v.content
err := applyTemplate(filepath.Join(outputDir, site.rawName, k), templData, template)
if err != nil {
panic(err)
}
}
// link assets to generation directory
err := os.Symlink(filepath.Join(site.sourcePath, "assets"), filepath.Join(outputDir, site.rawName, "assets"))
if err != nil {
panic(err)
}
}
|