arnaucube
arnaucube/blogoPublic Self-hosted repository
working
arnaucode arnaucode@gmail.com
Sun, 24 Dec 2017 19:31:30 +0100
commit

5ad6c1f8757af349d8afd995b184fd55b3aaffb7

parent

3907116171b7605a2d86558334ff4a3dffb0b10b

6 files changed, 65 insertions(+), 50 deletions(-)

jump to
M .gitignore → .gitignore

@@ -1,4 +1,4 @@

*.html -input +blogo-input css js
M README.md → README.md

@@ -1,40 +1,44 @@

-# Blogo +# Blogo [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucode/blogo)](https://goreportcard.com/report/github.com/arnaucode/blogo) Static blog generator, templating engine from markdown and html templates -Types of blogo tags: -- index.html + +## Use +Directory structure: + ``` -[blogo-title] -[blogo-index] +/ +----blogo +----/blogo-input +--------all the html, js, css files and folders ``` -- postTemplate.html + +To execute: ``` -[blogo-post-title] -[blogo-post-md] +./blogo ``` +Example of blogo.json: -Example of config.json: ```json { "title": "my blog", "indexTemplate": "index.html", - "indexPostTemplate": "indexPostTemplate.html", - "postTemplate": "postTemplate.html", + "postThumbTemplate": "postThumbTemplate.html", "posts": [ { - "title": "Post 01", - "thumb": "post01thumb.md", + "thumb": "post01_thumb.md", "md": "post01.md" }, { - "title": "Post 02", - "thumb": "post02thumb.md", + "thumb": "post02_thumb.md", "md": "post02.md" } + ], + "copyRaw": [ + "css", + "js" ] } - ```

@@ -49,13 +53,13 @@ <title>[blogo-title]</title>

</head> <body> -[blogo-index] +[blogo-content] </body> </html> ``` -- indexPostTemplate.html +- postThumbTemplate.html ```html <div class="col-md-3">

@@ -64,18 +68,25 @@ </div>

``` -- postTemplate.html +- post01_thumb.md -```html -<!DOCTYPE html> -<html> -<head> - <title>[blogo-post-title]</title> -</head> -<body> +``` +# Post 01 thumb +This is the description of the Post 01. This will appear on the main page, as the post description. +``` + +- post01.md + +``` +# Post 01 +This is the content of the Post 01. This content will appear when the Post 01 from the main page is clicked. +``` + -[blogo-post-content] +Types of blogo tags: -</body> -</html> +``` +[blogo-title] +[blogo-content] +[blogo-index-post-template] ```
M files.go → files.go

@@ -39,7 +39,7 @@ return r

} func copyRaw(original string, destination string) { - color.Green(destination) - _, err := exec.Command("cp", "-r", original, destination).Output() + color.Green(original + " --> to --> " + destination) + _, err := exec.Command("cp", "-rf", original, destination).Output() check(err) }
M main.go → main.go

@@ -7,15 +7,15 @@

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 @@ htmlpostthumb := string(blackfriday.Run([]byte(mdpostthumb)))

//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 @@

//copy raw fmt.Println("copying raw:") for _, dir := range config.CopyRaw { - copyRaw(directory+"/"+dir, dir) + copyRaw(directory+"/"+dir, ".") } }

@@ -67,7 +68,9 @@ for _, line := range lines {

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 } }
M readConfig.go → readConfig.go

@@ -5,17 +5,18 @@ "encoding/json"

"io/ioutil" ) +//Post is the struct for each post of the blog type Post struct { - Title string `json:"title"` Thumb string `json:"thumb"` Md string `json:"md"` } + +//Config gets the config.json file into struct type Config struct { - Title string `json:"title"` - IndexTemplate string `json:"indexTemplate"` - IndexPostTemplate string `json:"indexPostTemplate"` - PostTemplate string `json:"postTemplate"` - Posts []Post `json:"posts"` + Title string `json:"title"` + IndexTemplate string `json:"indexTemplate"` + PostThumbTemplate string `json:"postThumbTemplate"` + Posts []Post `json:"posts"` CopyRaw []string `json:"copyRaw"` }