Working markdown in blog

This commit is contained in:
cyber-dream 2023-06-07 02:17:29 +03:00
parent 81af984d96
commit b0c7b6a690
6 changed files with 47 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package blogviewer
import "html/template"
type BlogFileData struct {
Header string `bson:"header"`
Blocks []*Block `bson:"blocks"`
@ -9,3 +11,8 @@ type Block struct {
Type string `bson:"type"`
Data []string `bson:"data"`
}
type RenderedBlock struct {
Type string `bson:"type"`
Data []template.HTML `bson:"data"`
}

View File

@ -229,25 +229,27 @@ func (b *BlogViewerApplication) Render(filePath string, appCtx appCtx.AppContext
return nil, err
}
newData := []RenderedBlock{}
for _, block := range data.Blocks {
newData := []string{}
newBlock := RenderedBlock{}
switch block.Type {
case "image":
for _, image := range block.Data {
newData = append(newData, b.fs.RelativeToAbsolute(appCtx, image))
}
// for _, image := range block.Data {
// newData = append(newData, b.fs.RelativeToAbsolute(appCtx, image))
// }
case "markdown":
for _, data := range block.Data {
str := b.mLib.Render([]byte(data))
newData = append(newData, str)
renderedMD := b.mLib.Render([]byte(data))
newBlock.Data = append(newBlock.Data, renderedMD)
}
newData = append(newData, newBlock)
}
block.Data = newData
// block.Data = newData
}
return gin.H{
"header": data.Header,
"blocks": data.Blocks,
"blocks": newData,
// "html": html,
}, nil
}

1
go.mod
View File

@ -37,6 +37,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/russross/blackfriday v1.6.0
github.com/russross/blackfriday/v2 v2.1.0
github.com/thinkerou/favicon v0.2.0
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

2
go.sum
View File

@ -91,6 +91,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -1,6 +1,8 @@
package libs
import (
"html/template"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday/v2"
)
@ -8,10 +10,17 @@ import (
type MarkdownLib struct {
}
func (ml *MarkdownLib) Render(s []byte) string {
func (ml *MarkdownLib) Render(s []byte) template.HTML {
output := blackfriday.Run(s)
_ = output
html := bluemonday.UGCPolicy().SanitizeBytes(output)
// println(string(html))
return string(html)
kek := template.HTML(html)
return kek
}
// func (ml MarkdownLib) MarkDowner(args ...interface{}) template.HTML {
// s := blackfriday.MarkdownCommon([]byte(fmt.Sprintf("%s", args...)))
// return template.HTML(s)
// }

View File

@ -32,22 +32,27 @@ func PrivateRoutes(port string, webfs *webfilesystem.WebFileSystem, webde *wde.W
router.MaxMultipartMemory = 8 << 20 // 8 MiB
router.GET("/", func(ctx *gin.Context) {
// appString := AppString{
// AppPath: "/Applications/Finder.app",
// Args: []string{"/home/user"},
// }
appString := AppString{
AppPath: "/Applications/Finder.app",
Args: []string{"/home/user"},
AppPath: "/Applications/BlogViewer.app",
Args: []string{"/home/user/Blogs/blog1.blog"},
}
aboutMe := AppString{
AppPath: "/Applications/AboutMe.app",
Args: []string{},
}
// aboutMe := AppString{
// AppPath: "/Applications/AboutMe.app",
// Args: []string{},
// }
appString2 := AppString{
AppPath: "/Applications/Finder.app",
Args: []string{"/home/user/", "--desktop", "desktop-layer"},
}
// appString2 := AppString{
// AppPath: "/Applications/Finder.app",
// Args: []string{"/home/user/", "--desktop", "desktop-layer"},
// }
autostart := []AppString{appString2, appString, aboutMe}
autostart := []AppString{appString}
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{
"autostart": autostart,
})