Browse Source

Add PostsDir & change MD parser

master
arnaucube 3 years ago
parent
commit
b0f913c15c
5 changed files with 24 additions and 14 deletions
  1. BIN
      blogo
  2. +1
    -2
      go.mod
  3. +3
    -4
      go.sum
  4. +16
    -8
      main.go
  5. +4
    -0
      readConfig.go

BIN
blogo


+ 1
- 2
go.mod

@ -4,6 +4,5 @@ go 1.12
require (
github.com/fatih/color v1.9.0
github.com/russross/blackfriday v2.0.0+incompatible
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7
)

+ 3
- 4
go.sum

@ -1,14 +1,13 @@
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/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/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.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
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=
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/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

+ 16
- 8
main.go

@ -5,31 +5,38 @@ import (
"os"
"strings"
// blackfriday "gopkg.in/russross/blackfriday.v2"
"github.com/russross/blackfriday"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/parser"
)
const version = "v0_20210717"
const directory = "blogo-input"
const outputDir = "public"
func main() {
fmt.Println("Blogo version:", version)
readConfig(directory + "/blogo.json")
fmt.Println(config)
_ = 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
indexTemplate := readFile(directory + "/" + config.IndexTemplate)
indexPostTemplate := readFile(directory + "/" + config.PostThumbTemplate)
var blogoIndex string
blogoIndex = ""
for _, post := range config.Posts {
mdpostthumb := readFile(directory + "/" + post.Thumb)
htmlpostthumb := string(blackfriday.Run([]byte(mdpostthumb)))
mdpostthumb := readFile(directory + "/" + config.PostsDir + post.Thumb)
mdParser := parser.NewWithExtensions(mdExtensions)
htmlpostthumb := markdown.ToHTML([]byte(mdpostthumb), mdParser, nil)
//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]"] = string(htmlpostthumb)
r := putHTMLToTemplate(indexPostTemplate, m)
filename := strings.Split(post.Md, ".")[0]
r = "<a href='" + config.RelativePath + "/" + filename + ".html'>" + r + "</a>"
@ -48,8 +55,9 @@ func main() {
// generate posts pages
for _, post := range config.Posts {
mdcontent := readFile(directory + "/" + post.Md)
htmlcontent := string(blackfriday.Run([]byte(mdcontent)))
mdcontent := readFile(directory + "/" + config.PostsDir + post.Md)
mdParser := parser.NewWithExtensions(mdExtensions)
htmlcontent := markdown.ToHTML([]byte(mdcontent), mdParser, nil)
firstline := strings.Split(mdcontent, "\n")[0]
title := strings.Replace(firstline, "# ", "", -1)
@ -58,7 +66,7 @@ func main() {
m := make(map[string]string)
m["[blogo-title]"] = title + " - " + config.Title
m["[blogo-content]"] = htmlcontent
m["[blogo-content]"] = string(htmlcontent)
m["[blogo-summary]"] = post.MetaDescr
m["[blogo-link]"] = config.AbsoluteUrl + "/" + filename + ".html"
m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg

+ 4
- 0
readConfig.go

@ -19,6 +19,7 @@ type Config struct {
MetaImg string `json:"metaimg"`
MetaDescr string `json:"metadescr"`
RelativePath string `json:"relativePath"`
PostsDir string `json:"postsDir"`
AbsoluteUrl string `json:"absoluteUrl"`
IndexTemplate string `json:"indexTemplate"`
PostThumbTemplate string `json:"postThumbTemplate"`
@ -33,4 +34,7 @@ func readConfig(path string) {
check(err)
content := string(file)
json.Unmarshal([]byte(content), &config)
if config.PostsDir != "" {
config.PostsDir += "/"
}
}

Loading…
Cancel
Save