diff --git a/.gitignore b/.gitignore index 116a0dc..76168b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.html -input +blogo-input css js diff --git a/README.md b/README.md index f34bf52..2a25d01 100644 --- a/README.md +++ b/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 @@ Example of input files: -[blogo-index] +[blogo-content] ``` -- indexPostTemplate.html +- postThumbTemplate.html ```html
@@ -64,18 +68,25 @@ Example of input files: ``` -- postTemplate.html +- post01_thumb.md -```html - - - - [blogo-post-title] - - +``` +# Post 01 thumb +This is the description of the Post 01. This will appear on the main page, as the post description. +``` -[blogo-post-content] +- 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. +``` + + +Types of blogo tags: + +``` +[blogo-title] +[blogo-content] +[blogo-index-post-template] ``` diff --git a/blogo b/blogo index 3e8f7b6..f3ef090 100755 Binary files a/blogo and b/blogo differ diff --git a/files.go b/files.go index 550cd1e..23fd5b5 100644 --- a/files.go +++ b/files.go @@ -39,7 +39,7 @@ func concatStringsWithJumps(lines []string) string { } 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) } diff --git a/main.go b/main.go index dbd0a5a..747282b 100644 --- a/main.go +++ b/main.go @@ -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 = "" + r + "" 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 } } diff --git a/readConfig.go b/readConfig.go index 6cf275b..7fdc9a6 100755 --- a/readConfig.go +++ b/readConfig.go @@ -5,17 +5,18 @@ import ( "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"` }