|
|
@ -7,15 +7,15 @@ import ( |
|
|
|
blackfriday "gopkg.in/russross/blackfriday.v2" |
|
|
|
) |
|
|
|
|
|
|
|
const directory = "input" |
|
|
|
const directory = "blogo-input" |
|
|
|
|
|
|
|
func main() { |
|
|
|
readConfig("input/config.json") |
|
|
|
readConfig(directory + "/blogo.json") |
|
|
|
fmt.Println(config) |
|
|
|
|
|
|
|
// generate index page
|
|
|
|
indexTemplate := readFile(directory + "/" + config.IndexTemplate) |
|
|
|
indexPostTemplate := readFile(directory + "/" + config.IndexPostTemplate) |
|
|
|
indexPostTemplate := readFile(directory + "/" + config.PostThumbTemplate) |
|
|
|
var blogoIndex string |
|
|
|
blogoIndex = "" |
|
|
|
for _, post := range config.Posts { |
|
|
@ -24,29 +24,30 @@ func main() { |
|
|
|
|
|
|
|
//put the htmlpostthumb in the blogo-index-post-template
|
|
|
|
m := make(map[string]string) |
|
|
|
m["blogo-index-post-template"] = htmlpostthumb |
|
|
|
m["[blogo-index-post-template]"] = htmlpostthumb |
|
|
|
r := putHTMLToTemplate(indexPostTemplate, m) |
|
|
|
filename := strings.Split(post.Md, ".")[0] |
|
|
|
r = "<a href='" + filename + ".html'>" + r + "</a>" |
|
|
|
blogoIndex = blogoIndex + r |
|
|
|
} |
|
|
|
//put the blogoIndex in the index.html
|
|
|
|
m := make(map[string]string) |
|
|
|
m["blogo-title"] = config.Title |
|
|
|
m["blogo-index"] = blogoIndex |
|
|
|
m["[blogo-title]"] = config.Title |
|
|
|
m["[blogo-content]"] = blogoIndex |
|
|
|
r := putHTMLToTemplate(indexTemplate, m) |
|
|
|
writeFile("index.html", r) |
|
|
|
|
|
|
|
// generate posts pages
|
|
|
|
postTemplate := readFile(directory + "/" + config.PostTemplate) |
|
|
|
|
|
|
|
for _, post := range config.Posts { |
|
|
|
mdcontent := readFile(directory + "/" + post.Md) |
|
|
|
htmlcontent := string(blackfriday.Run([]byte(mdcontent))) |
|
|
|
|
|
|
|
m := make(map[string]string) |
|
|
|
m["blogo-post-title"] = post.Title |
|
|
|
m["blogo-post-content"] = htmlcontent |
|
|
|
m["[blogo-title]"] = config.Title |
|
|
|
m["[blogo-content]"] = htmlcontent |
|
|
|
|
|
|
|
r := putHTMLToTemplate(postTemplate, m) |
|
|
|
r := putHTMLToTemplate(indexTemplate, m) |
|
|
|
//fmt.Println(r)
|
|
|
|
|
|
|
|
filename := strings.Split(post.Md, ".")[0] |
|
|
@ -56,7 +57,7 @@ func main() { |
|
|
|
//copy raw
|
|
|
|
fmt.Println("copying raw:") |
|
|
|
for _, dir := range config.CopyRaw { |
|
|
|
copyRaw(directory+"/"+dir, dir) |
|
|
|
copyRaw(directory+"/"+dir, ".") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -67,7 +68,9 @@ func putHTMLToTemplate(template string, m map[string]string) string { |
|
|
|
inserted := false |
|
|
|
for k, v := range m { |
|
|
|
if strings.Contains(line, k) { |
|
|
|
resultL = append(resultL, v) |
|
|
|
//in the line, change [tag] with the content
|
|
|
|
lineReplaced := strings.Replace(line, k, v, -1) |
|
|
|
resultL = append(resultL, lineReplaced) |
|
|
|
inserted = true |
|
|
|
} |
|
|
|
} |
|
|
|