parent
abcf07c673
commit
6b485605e6
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello,", "blog!")
|
||||
}
|
|
@ -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!")
|
||||
}
|
||||
```
|
||||
<!-- emdbed: test.go -->
|
||||
<!--/emdbed -->
|
||||
|
||||
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';
|
||||
```
|
||||
<!-- emdbed: test.sql L2 -->
|
||||
<!--/emdbed -->
|
|
@ -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';
|
|
@ -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';
|
||||
```
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goyek/goyek"
|
||||
)
|
||||
|
||||
|
|
2
go.mod
2
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 (
|
||||
|
|
7
go.sum
7
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=
|
||||
|
|
|
@ -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
|
||||
|
|
14
post/post.go
14
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") {
|
||||
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
|
||||
}
|
||||
apn := filepath.Join(basePath, ent.Name())
|
||||
} else {
|
||||
if !strings.HasSuffix(ent.Name(), ".md") {
|
||||
continue
|
||||
}
|
||||
apn = filepath.Join(basePath, ent.Name())
|
||||
}
|
||||
|
||||
fi, err := os.Open(apn)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not open file")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
{{range .Blog.SortedPosts}}
|
||||
<h5>
|
||||
<a href="{{.Slug}}"><strong>{{.Title}}</strong></a><br/>
|
||||
<small>@{{.Author}}</small><span class="right">{{.Date.Format "Jan 2, 2006"}}</span><br/>
|
||||
{{if .Author}}<small>@{{.Author}}</small>{{end}}<span class="right">{{.Date.Format "Jan 2, 2006"}}</span><br/>
|
||||
{{range .Tags}}<code class="tag">{{.}}</code> {{end}}
|
||||
</h5>
|
||||
<hr/>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<link rel="stylesheet" href="sakura.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a style="position: absolute; left: 1em;" href="../">Index</a>
|
||||
{{.Content}}
|
||||
</body>
|
||||
<script>
|
||||
|
|
Loading…
Reference in New Issue