mirror of
https://github.com/arnaucube/blogo.git
synced 2026-02-06 19:36:39 +01:00
Add PostsDir & change MD parser
This commit is contained in:
3
go.mod
3
go.mod
@@ -4,6 +4,5 @@ go 1.12
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/color v1.9.0
|
github.com/fatih/color v1.9.0
|
||||||
github.com/russross/blackfriday v2.0.0+incompatible
|
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
7
go.sum
7
go.sum
@@ -1,14 +1,13 @@
|
|||||||
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
|
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
|
||||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7 h1:oKYOfNR7Hp6XpZ4JqolL5u642Js5Z0n7psPVl+S5heo=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
|
||||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||||
github.com/russross/blackfriday v2.0.0+incompatible h1:cBXrhZNUf9C+La9/YpS+UHpUT8YD6Td9ZMSU9APFcsk=
|
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
|
||||||
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|||||||
24
main.go
24
main.go
@@ -5,31 +5,38 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
// blackfriday "gopkg.in/russross/blackfriday.v2"
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/gomarkdown/markdown/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const version = "v0_20210717"
|
||||||
const directory = "blogo-input"
|
const directory = "blogo-input"
|
||||||
const outputDir = "public"
|
const outputDir = "public"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fmt.Println("Blogo version:", version)
|
||||||
readConfig(directory + "/blogo.json")
|
readConfig(directory + "/blogo.json")
|
||||||
fmt.Println(config)
|
fmt.Println(config)
|
||||||
|
|
||||||
_ = os.Mkdir(outputDir, os.ModePerm)
|
_ = os.Mkdir(outputDir, os.ModePerm)
|
||||||
|
|
||||||
|
mdExtensions := parser.NoIntraEmphasis | parser.Tables | parser.FencedCode |
|
||||||
|
parser.Autolink | parser.Strikethrough | parser.SpaceHeadings | parser.HeadingIDs |
|
||||||
|
parser.BackslashLineBreak | parser.DefinitionLists
|
||||||
|
|
||||||
// generate index page
|
// generate index page
|
||||||
indexTemplate := readFile(directory + "/" + config.IndexTemplate)
|
indexTemplate := readFile(directory + "/" + config.IndexTemplate)
|
||||||
indexPostTemplate := readFile(directory + "/" + config.PostThumbTemplate)
|
indexPostTemplate := readFile(directory + "/" + config.PostThumbTemplate)
|
||||||
var blogoIndex string
|
var blogoIndex string
|
||||||
blogoIndex = ""
|
blogoIndex = ""
|
||||||
for _, post := range config.Posts {
|
for _, post := range config.Posts {
|
||||||
mdpostthumb := readFile(directory + "/" + post.Thumb)
|
mdpostthumb := readFile(directory + "/" + config.PostsDir + post.Thumb)
|
||||||
htmlpostthumb := string(blackfriday.Run([]byte(mdpostthumb)))
|
mdParser := parser.NewWithExtensions(mdExtensions)
|
||||||
|
htmlpostthumb := markdown.ToHTML([]byte(mdpostthumb), mdParser, nil)
|
||||||
|
|
||||||
//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]"] = string(htmlpostthumb)
|
||||||
r := putHTMLToTemplate(indexPostTemplate, m)
|
r := putHTMLToTemplate(indexPostTemplate, m)
|
||||||
filename := strings.Split(post.Md, ".")[0]
|
filename := strings.Split(post.Md, ".")[0]
|
||||||
r = "<a href='" + config.RelativePath + "/" + filename + ".html'>" + r + "</a>"
|
r = "<a href='" + config.RelativePath + "/" + filename + ".html'>" + r + "</a>"
|
||||||
@@ -48,8 +55,9 @@ func main() {
|
|||||||
// generate posts pages
|
// generate posts pages
|
||||||
|
|
||||||
for _, post := range config.Posts {
|
for _, post := range config.Posts {
|
||||||
mdcontent := readFile(directory + "/" + post.Md)
|
mdcontent := readFile(directory + "/" + config.PostsDir + post.Md)
|
||||||
htmlcontent := string(blackfriday.Run([]byte(mdcontent)))
|
mdParser := parser.NewWithExtensions(mdExtensions)
|
||||||
|
htmlcontent := markdown.ToHTML([]byte(mdcontent), mdParser, nil)
|
||||||
|
|
||||||
firstline := strings.Split(mdcontent, "\n")[0]
|
firstline := strings.Split(mdcontent, "\n")[0]
|
||||||
title := strings.Replace(firstline, "# ", "", -1)
|
title := strings.Replace(firstline, "# ", "", -1)
|
||||||
@@ -58,7 +66,7 @@ func main() {
|
|||||||
|
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["[blogo-title]"] = title + " - " + config.Title
|
m["[blogo-title]"] = title + " - " + config.Title
|
||||||
m["[blogo-content]"] = htmlcontent
|
m["[blogo-content]"] = string(htmlcontent)
|
||||||
m["[blogo-summary]"] = post.MetaDescr
|
m["[blogo-summary]"] = post.MetaDescr
|
||||||
m["[blogo-link]"] = config.AbsoluteUrl + "/" + filename + ".html"
|
m["[blogo-link]"] = config.AbsoluteUrl + "/" + filename + ".html"
|
||||||
m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg
|
m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ type Config struct {
|
|||||||
MetaImg string `json:"metaimg"`
|
MetaImg string `json:"metaimg"`
|
||||||
MetaDescr string `json:"metadescr"`
|
MetaDescr string `json:"metadescr"`
|
||||||
RelativePath string `json:"relativePath"`
|
RelativePath string `json:"relativePath"`
|
||||||
|
PostsDir string `json:"postsDir"`
|
||||||
AbsoluteUrl string `json:"absoluteUrl"`
|
AbsoluteUrl string `json:"absoluteUrl"`
|
||||||
IndexTemplate string `json:"indexTemplate"`
|
IndexTemplate string `json:"indexTemplate"`
|
||||||
PostThumbTemplate string `json:"postThumbTemplate"`
|
PostThumbTemplate string `json:"postThumbTemplate"`
|
||||||
@@ -33,4 +34,7 @@ func readConfig(path string) {
|
|||||||
check(err)
|
check(err)
|
||||||
content := string(file)
|
content := string(file)
|
||||||
json.Unmarshal([]byte(content), &config)
|
json.Unmarshal([]byte(content), &config)
|
||||||
|
if config.PostsDir != "" {
|
||||||
|
config.PostsDir += "/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user