mirror of
https://github.com/arnaucube/blogo.git
synced 2026-02-06 19:36:39 +01:00
working
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
*.html
|
||||
input
|
||||
blogo-input
|
||||
css
|
||||
js
|
||||
|
||||
77
README.md
77
README.md
@@ -1,40 +1,44 @@
|
||||
# Blogo
|
||||
# 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]
|
||||
```
|
||||
- postTemplate.html
|
||||
```
|
||||
[blogo-post-title]
|
||||
[blogo-post-md]
|
||||
/
|
||||
----blogo
|
||||
----/blogo-input
|
||||
--------all the html, js, css files and folders
|
||||
```
|
||||
|
||||
To execute:
|
||||
```
|
||||
./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:
|
||||
</head>
|
||||
<body>
|
||||
|
||||
[blogo-index]
|
||||
[blogo-content]
|
||||
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
- indexPostTemplate.html
|
||||
- postThumbTemplate.html
|
||||
|
||||
```html
|
||||
<div class="col-md-3">
|
||||
@@ -64,18 +68,25 @@ Example of input files:
|
||||
|
||||
```
|
||||
|
||||
- postTemplate.html
|
||||
- post01_thumb.md
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>[blogo-post-title]</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
[blogo-post-content]
|
||||
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
# 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.
|
||||
```
|
||||
|
||||
|
||||
Types of blogo tags:
|
||||
|
||||
```
|
||||
[blogo-title]
|
||||
[blogo-content]
|
||||
[blogo-index-post-template]
|
||||
```
|
||||
|
||||
4
files.go
4
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)
|
||||
}
|
||||
|
||||
27
main.go
27
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 = "<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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user