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
|
*.html
|
||||||
input
|
blogo-input
|
||||||
css
|
css
|
||||||
js
|
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
|
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
|
||||||
- postTemplate.html
|
--------all the html, js, css files and folders
|
||||||
```
|
|
||||||
[blogo-post-title]
|
|
||||||
[blogo-post-md]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To execute:
|
||||||
|
```
|
||||||
|
./blogo
|
||||||
|
```
|
||||||
|
|
||||||
|
Example of blogo.json:
|
||||||
|
|
||||||
Example of config.json:
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"title": "my blog",
|
"title": "my blog",
|
||||||
"indexTemplate": "index.html",
|
"indexTemplate": "index.html",
|
||||||
"indexPostTemplate": "indexPostTemplate.html",
|
"postThumbTemplate": "postThumbTemplate.html",
|
||||||
"postTemplate": "postTemplate.html",
|
|
||||||
"posts": [
|
"posts": [
|
||||||
{
|
{
|
||||||
"title": "Post 01",
|
"thumb": "post01_thumb.md",
|
||||||
"thumb": "post01thumb.md",
|
|
||||||
"md": "post01.md"
|
"md": "post01.md"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Post 02",
|
"thumb": "post02_thumb.md",
|
||||||
"thumb": "post02thumb.md",
|
|
||||||
"md": "post02.md"
|
"md": "post02.md"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"copyRaw": [
|
||||||
|
"css",
|
||||||
|
"js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -49,13 +53,13 @@ Example of input files:
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
[blogo-index]
|
[blogo-content]
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
```
|
```
|
||||||
|
|
||||||
- indexPostTemplate.html
|
- postThumbTemplate.html
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
@@ -64,18 +68,25 @@ Example of input files:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- postTemplate.html
|
- post01_thumb.md
|
||||||
|
|
||||||
```html
|
```
|
||||||
<!DOCTYPE html>
|
# Post 01 thumb
|
||||||
<html>
|
This is the description of the Post 01. This will appear on the main page, as the post description.
|
||||||
<head>
|
```
|
||||||
<title>[blogo-post-title]</title>
|
|
||||||
</head>
|
- post01.md
|
||||||
<body>
|
|
||||||
|
```
|
||||||
[blogo-post-content]
|
# Post 01
|
||||||
|
This is the content of the Post 01. This content will appear when the Post 01 from the main page is clicked.
|
||||||
</body>
|
```
|
||||||
</html>
|
|
||||||
|
|
||||||
|
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) {
|
func copyRaw(original string, destination string) {
|
||||||
color.Green(destination)
|
color.Green(original + " --> to --> " + destination)
|
||||||
_, err := exec.Command("cp", "-r", original, destination).Output()
|
_, err := exec.Command("cp", "-rf", original, destination).Output()
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
|||||||
27
main.go
27
main.go
@@ -7,15 +7,15 @@ import (
|
|||||||
blackfriday "gopkg.in/russross/blackfriday.v2"
|
blackfriday "gopkg.in/russross/blackfriday.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const directory = "input"
|
const directory = "blogo-input"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
readConfig("input/config.json")
|
readConfig(directory + "/blogo.json")
|
||||||
fmt.Println(config)
|
fmt.Println(config)
|
||||||
|
|
||||||
// generate index page
|
// generate index page
|
||||||
indexTemplate := readFile(directory + "/" + config.IndexTemplate)
|
indexTemplate := readFile(directory + "/" + config.IndexTemplate)
|
||||||
indexPostTemplate := readFile(directory + "/" + config.IndexPostTemplate)
|
indexPostTemplate := readFile(directory + "/" + config.PostThumbTemplate)
|
||||||
var blogoIndex string
|
var blogoIndex string
|
||||||
blogoIndex = ""
|
blogoIndex = ""
|
||||||
for _, post := range config.Posts {
|
for _, post := range config.Posts {
|
||||||
@@ -24,29 +24,30 @@ func main() {
|
|||||||
|
|
||||||
//put the htmlpostthumb in the blogo-index-post-template
|
//put the htmlpostthumb in the blogo-index-post-template
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["blogo-index-post-template"] = htmlpostthumb
|
m["[blogo-index-post-template]"] = htmlpostthumb
|
||||||
r := putHTMLToTemplate(indexPostTemplate, m)
|
r := putHTMLToTemplate(indexPostTemplate, m)
|
||||||
|
filename := strings.Split(post.Md, ".")[0]
|
||||||
|
r = "<a href='" + filename + ".html'>" + r + "</a>"
|
||||||
blogoIndex = blogoIndex + r
|
blogoIndex = blogoIndex + r
|
||||||
}
|
}
|
||||||
//put the blogoIndex in the index.html
|
//put the blogoIndex in the index.html
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["blogo-title"] = config.Title
|
m["[blogo-title]"] = config.Title
|
||||||
m["blogo-index"] = blogoIndex
|
m["[blogo-content]"] = blogoIndex
|
||||||
r := putHTMLToTemplate(indexTemplate, m)
|
r := putHTMLToTemplate(indexTemplate, m)
|
||||||
writeFile("index.html", r)
|
writeFile("index.html", r)
|
||||||
|
|
||||||
// generate posts pages
|
// generate posts pages
|
||||||
postTemplate := readFile(directory + "/" + config.PostTemplate)
|
|
||||||
|
|
||||||
for _, post := range config.Posts {
|
for _, post := range config.Posts {
|
||||||
mdcontent := readFile(directory + "/" + post.Md)
|
mdcontent := readFile(directory + "/" + post.Md)
|
||||||
htmlcontent := string(blackfriday.Run([]byte(mdcontent)))
|
htmlcontent := string(blackfriday.Run([]byte(mdcontent)))
|
||||||
|
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["blogo-post-title"] = post.Title
|
m["[blogo-title]"] = config.Title
|
||||||
m["blogo-post-content"] = htmlcontent
|
m["[blogo-content]"] = htmlcontent
|
||||||
|
|
||||||
r := putHTMLToTemplate(postTemplate, m)
|
r := putHTMLToTemplate(indexTemplate, m)
|
||||||
//fmt.Println(r)
|
//fmt.Println(r)
|
||||||
|
|
||||||
filename := strings.Split(post.Md, ".")[0]
|
filename := strings.Split(post.Md, ".")[0]
|
||||||
@@ -56,7 +57,7 @@ func main() {
|
|||||||
//copy raw
|
//copy raw
|
||||||
fmt.Println("copying raw:")
|
fmt.Println("copying raw:")
|
||||||
for _, dir := range config.CopyRaw {
|
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
|
inserted := false
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
if strings.Contains(line, k) {
|
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
|
inserted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Post is the struct for each post of the blog
|
||||||
type Post struct {
|
type Post struct {
|
||||||
Title string `json:"title"`
|
|
||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Md string `json:"md"`
|
Md string `json:"md"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Config gets the config.json file into struct
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
IndexTemplate string `json:"indexTemplate"`
|
IndexTemplate string `json:"indexTemplate"`
|
||||||
IndexPostTemplate string `json:"indexPostTemplate"`
|
PostThumbTemplate string `json:"postThumbTemplate"`
|
||||||
PostTemplate string `json:"postTemplate"`
|
|
||||||
Posts []Post `json:"posts"`
|
Posts []Post `json:"posts"`
|
||||||
CopyRaw []string `json:"copyRaw"`
|
CopyRaw []string `json:"copyRaw"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user