-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
121 lines (103 loc) · 2.72 KB
/
main.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2013 Joshua Marsh. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in
// the LICENSE file.
package main
import (
"fmt"
"github.com/icub3d/goblog/archives"
"github.com/icub3d/goblog/blogs"
"github.com/icub3d/goblog/fs"
"github.com/icub3d/goblog/rss"
"github.com/icub3d/goblog/tags"
"github.com/icub3d/goblog/templates"
flag "github.com/ogier/pflag"
"os"
)
func main() {
// Parse the flags.
flag.Parse()
SetupDirectories()
// First load the templates.
tmplts, err := templates.LoadTemplates(TemplateDir)
if err != nil {
fmt.Println("loading templates:", err)
os.Exit(1)
}
// Next, let's clear out the OutputDir if requested.
if EmptyOutputDir {
err = os.RemoveAll(OutputDir)
if err != nil {
fmt.Println("cleaning output dir:", err)
os.Exit(1)
}
}
// Make the output dir.
err = fs.MakeDirIfNotExists(OutputDir)
if err != nil {
fmt.Println("making output dir:", err)
os.Exit(1)
}
// Now, move the static files over.
err = fs.CopyFilesRecursively(OutputDir, StaticDir)
if err != nil {
fmt.Println("making output dir:", err)
os.Exit(1)
}
// Get a list of files from the BlogDir.
entries, err := blogs.GetBlogFiles(BlogDir)
if err != nil {
fmt.Println("getting blog file list:", err)
os.Exit(1)
}
// Iteratively Parse each blog for it's useful data and generate a
// page for each blog.
for _, blog := range entries {
contents, err := blog.Parse()
if err != nil {
fmt.Println("parsing blog", blog, ":", err)
os.Exit(1)
}
err = tmplts.MakeBlogEntry(OutputDir, blog, contents)
if err != nil {
fmt.Println("generating blog html", blog, ":", err)
os.Exit(1)
}
}
// Generate the about page.
err = tmplts.MakeAbout(OutputDir)
if err != nil {
fmt.Println("generating about.html:", err)
os.Exit(1)
}
// Get a sorted list of tags.
tagentries := tags.ParseBlogs(entries)
t := tagentries.Slice()
// Generate the tags page.
err = tmplts.MakeTags(OutputDir, t)
if err != nil {
fmt.Println("generating tags.html:", err)
os.Exit(1)
}
// Get a sort list of archives.
dateentries := archives.ParseBlogs(entries)
a := dateentries.Slice()
// Generate the archive page.
err = tmplts.MakeArchive(OutputDir, a)
if err != nil {
fmt.Println("generating archive.html:", err)
os.Exit(1)
}
// Generate the index page.
mostRecent := archives.GetMostRecent(a, MaxIndexEntries)
err = tmplts.MakeIndex(OutputDir, mostRecent)
if err != nil {
fmt.Println("generating index.html:", err)
os.Exit(1)
}
// Generate the RSS feed.
err = rss.MakeRss(archives.GetMostRecent(a, 10), URL, TemplateDir, OutputDir)
if err != nil {
fmt.Println("generating feed.rss:", err)
fmt.Println("no rss will be available")
}
}