From 6b485605e6fda5c84b4020611b2d1a76c221cf49 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Sat, 25 Dec 2021 22:56:32 -0600 Subject: [PATCH] Update and and emdbed Signed-off-by: jolheiser --- _example/test.go | 7 ++++++ _example/test.md | 26 ++++----------------- _example/test.sql | 9 ++++++++ _example/test2.md | 54 -------------------------------------------- build/build.go | 1 + go.mod | 2 ++ go.sum | 7 ++++++ markdown/markdown.go | 11 ++++++++- post/post.go | 16 ++++++++++--- router/router.go | 2 +- static/index.tmpl | 2 +- static/post.tmpl | 1 + 12 files changed, 57 insertions(+), 81 deletions(-) create mode 100644 _example/test.go create mode 100644 _example/test.sql diff --git a/_example/test.go b/_example/test.go new file mode 100644 index 0000000..2723306 --- /dev/null +++ b/_example/test.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello,", "blog!") +} diff --git a/_example/test.md b/_example/test.md index d4197e0..1dda168 100644 --- a/_example/test.md +++ b/_example/test.md @@ -1,6 +1,5 @@ --- title = "Test" -author = "jolheiser" date = 2021-10-01 tags = ["test", "example"] --- @@ -12,7 +11,7 @@ tags = ["test", "example"] ##### H5 ###### H6 -This is a test, and all the ways I learned to test. +This is a test, and all the ways I learned to test. :slightly_smiling_face: * Foo * Bar @@ -21,15 +20,8 @@ This is a test, and all the ways I learned to test. [Link Home](/) -```go -package main - -import "fmt" - -func main() { - fmt.Println("Hello, blog!") -} -``` + + Some **more** text! @@ -47,13 +39,5 @@ func main() { _This_ time ~~we~~ I am going to **test** some emphasis. -```sql -SELECT - username, - age, - email -FROM - users -WHERE - email = 'john.olheiser@gmail.com'; -``` \ No newline at end of file + + \ No newline at end of file diff --git a/_example/test.sql b/_example/test.sql new file mode 100644 index 0000000..7fa9b5c --- /dev/null +++ b/_example/test.sql @@ -0,0 +1,9 @@ +-- This is a comment we are going to ignore... +SELECT + username, + age, + email +FROM + users +WHERE + email = 'john.olheiser@gmail.com'; diff --git a/_example/test2.md b/_example/test2.md index a459b2b..641482a 100644 --- a/_example/test2.md +++ b/_example/test2.md @@ -1,59 +1,5 @@ --- title = "Testing" -author = "jolheiser" date = 2021-08-19 tags = ["foo", "bar"] --- - -# H1 -## H2 -### H3 -#### H4 -##### H5 -###### H6 - -This is a test, and all the ways I learned to test. - -* Foo -* Bar - * Baz -* Banana - -[Link Home](/) - -```go -package main - -import "fmt" - -func main() { - fmt.Println("Hello, blog!") -} -``` - -Some **more** text! - -```go -package main - -import "fmt" - -func main() { - fmt.Println("Hello,", "blog!") -} -``` - -## Okay, moving on - -_This_ time ~~we~~ I am going to **test** some emphasis. - -```sql -SELECT - username, - age, - email -FROM - users -WHERE - email = 'john.olheiser@gmail.com'; -``` \ No newline at end of file diff --git a/build/build.go b/build/build.go index aee7408..02e8cff 100644 --- a/build/build.go +++ b/build/build.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/goyek/goyek" ) diff --git a/go.mod b/go.mod index 5dd383e..b51efb0 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,9 @@ require ( github.com/peterbourgon/ff/v3 v3.1.0 github.com/rs/zerolog v1.24.0 github.com/yuin/goldmark v1.4.0 + github.com/yuin/goldmark-emoji v1.0.1 github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01 + go.jolheiser.com/emdbed v0.0.2 ) require ( diff --git a/go.sum b/go.sum index 362b04d..47003aa 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/go-chi/chi/v5 v5.0.4/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITL github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/goyek/goyek v0.6.0 h1:2YQ4V3X7q+zFF98IBWMc1WRwfzs0TQ8jrwOKY3XRQRk= github.com/goyek/goyek v0.6.0/go.mod h1:UGjZz3juJL2l2eMqRbxQYjG8ieyKb7WMYPv0KB0KVxA= +github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= +github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -46,12 +48,17 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU= github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.3.6/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0 h1:OtISOGfH6sOWa1/qXqqAiOIAO6Z5J3AEAE18WAq6BiQ= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18Wa1os= +github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ= github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01 h1:0SJnXjE4jDClMW6grE0xpNhwpqbPwkBTn8zpVw5C0SI= github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01/go.mod h1:TwKQPa5XkCCRC2GRZ5wtfNUTQ2+9/i19mGRijFeJ4BE= +go.jolheiser.com/emdbed v0.0.2 h1:nFxYD7VOlsp9Mv0nKnWe8Zj9n43yLJU5Yge/Va7my1E= +go.jolheiser.com/emdbed v0.0.2/go.mod h1:8ReMCKEDv6UT89SqYZ+wzbPTGs3xNuX8q2RAsmSSG1M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= diff --git a/markdown/markdown.go b/markdown/markdown.go index 62bd952..fbd7b99 100644 --- a/markdown/markdown.go +++ b/markdown/markdown.go @@ -3,9 +3,13 @@ package markdown import ( "bytes" "io" + "strings" + + "go.jolheiser.com/emdbed" chromahtml "github.com/alecthomas/chroma/formatters/html" "github.com/yuin/goldmark" + emoji "github.com/yuin/goldmark-emoji" highlighting "github.com/yuin/goldmark-highlighting" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" @@ -23,6 +27,7 @@ var gm = goldmark.New( chromahtml.LineNumbersInTable(true), ), ), + emoji.Emoji, ), goldmark.WithParserOptions( parser.WithAutoHeadingID(), @@ -33,11 +38,15 @@ var gm = goldmark.New( ) // Convert transforms a markdown document into HTML -func Convert(r io.Reader) (string, error) { +func Convert(baseDir string, r io.Reader) (string, error) { content, err := Content(r) if err != nil { return "", err } + content, err = emdbed.Convert(baseDir, strings.NewReader(content)) + if err != nil { + return "", err + } var buf bytes.Buffer if err := gm.Convert([]byte(content), &buf); err != nil { return "", err diff --git a/post/post.go b/post/post.go index 797fca6..273448c 100644 --- a/post/post.go +++ b/post/post.go @@ -30,10 +30,20 @@ func Scan(basePath string) (map[string]*Post, error) { return nil, err } for _, ent := range ents { - if ent.IsDir() || !strings.HasSuffix(ent.Name(), ".md") { - continue + var apn string + if ent.IsDir() { + apn = filepath.Join(basePath, ent.Name(), "index.md") + if _, err := os.Stat(apn); err != nil { + log.Error().Err(err).Msgf("could not parse %s", ent.Name()) + continue + } + } else { + if !strings.HasSuffix(ent.Name(), ".md") { + continue + } + apn = filepath.Join(basePath, ent.Name()) } - apn := filepath.Join(basePath, ent.Name()) + fi, err := os.Open(apn) if err != nil { log.Error().Err(err).Msg("could not open file") diff --git a/router/router.go b/router/router.go index 99d63e4..a7facc0 100644 --- a/router/router.go +++ b/router/router.go @@ -53,7 +53,7 @@ func fileHandler(blog *post.Blog) http.HandlerFunc { } defer fi.Close() - md, err := markdown.Convert(fi) + md, err := markdown.Convert(blog.Path, fi) if err != nil { log.Error().Err(err).Msg("could not convert") http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/static/index.tmpl b/static/index.tmpl index ed4e484..5f51d48 100644 --- a/static/index.tmpl +++ b/static/index.tmpl @@ -23,7 +23,7 @@ {{range .Blog.SortedPosts}}
{{.Title}}
- @{{.Author}}{{.Date.Format "Jan 2, 2006"}}
+ {{if .Author}}@{{.Author}}{{end}}{{.Date.Format "Jan 2, 2006"}}
{{range .Tags}}{{.}} {{end}}

diff --git a/static/post.tmpl b/static/post.tmpl index 98e3d5d..88566ea 100644 --- a/static/post.tmpl +++ b/static/post.tmpl @@ -7,6 +7,7 @@ + Index {{.Content}}