Browse Source

Add directions and fix emdbed

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 4 weeks ago
parent
commit
447c88febe
Signed by: jolheiser GPG Key ID: B853ADA5DA7BBF7A
  1. 14
      README.md
  2. 0
      _example/test/index.md
  3. 0
      _example/test/test.go
  4. 0
      _example/test/test.sql
  5. 13
      markdown/markdown.go
  6. 20
      readme.go
  7. 20
      router/router.go

14
README.md

@ -2,6 +2,20 @@
A simple blog tool.
Supports [emdbed](https://git.jojodev.com/jolheiser/emdbed).
Point `blog` at a directory with blog post markdown files. Each markdown file (or directory with an `index.md` inside) will be converted to a blog post.
Each post must contain some TOML metadata as follows:
<!-- emdbed: _example/test/index.md ~toml L2 L4 -->
```toml
title = "Test"
date = 2021-10-01
tags = ["test", "example"]
```
<!-- /emdbed -->
## License
[MIT](LICENSE)

0
_example/test.md → _example/test/index.md

0
_example/test.go → _example/test/test.go

0
_example/test.sql → _example/test/test.sql

13
markdown/markdown.go

@ -3,9 +3,6 @@ package markdown
import (
"bytes"
"io"
"strings"
"go.jolheiser.com/emdbed"
chromahtml "github.com/alecthomas/chroma/formatters/html"
"github.com/yuin/goldmark"
@ -38,17 +35,13 @@ var gm = goldmark.New(
)
// Convert transforms a markdown document into HTML
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))
func Convert(r io.Reader) (string, error) {
content, err := io.ReadAll(r)
if err != nil {
return "", err
}
var buf bytes.Buffer
if err := gm.Convert([]byte(content), &buf); err != nil {
if err := gm.Convert(content, &buf); err != nil {
return "", err
}
return buf.String(), nil

20
readme.go

@ -0,0 +1,20 @@
//go:build generate
package main
import (
"os"
"go.jolheiser.com/emdbed"
)
//go:generate go run readme.go
func main() {
convert, err := emdbed.ConvertFile("README.md")
if err != nil {
panic(err)
}
if err := os.WriteFile("README.md", []byte(convert), os.ModePerm); err != nil {
panic(err)
}
}

20
router/router.go

@ -4,6 +4,10 @@ import (
"html/template"
"net/http"
"os"
"path/filepath"
"strings"
"go.jolheiser.com/emdbed"
"go.jolheiser.com/blog/markdown"
"go.jolheiser.com/blog/post"
@ -53,7 +57,21 @@ func fileHandler(blog *post.Blog) http.HandlerFunc {
}
defer fi.Close()
md, err := markdown.Convert(blog.Path, fi)
mdContent, err := markdown.Content(fi)
if err != nil {
log.Error().Err(err).Msg("could not get content")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
emdbedContent, err := emdbed.Convert(filepath.Dir(p.Path), strings.NewReader(mdContent))
if err != nil {
log.Error().Err(err).Msg("could not emdbed")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
md, err := markdown.Convert(strings.NewReader(emdbedContent))
if err != nil {
log.Error().Err(err).Msg("could not convert")
http.Error(w, err.Error(), http.StatusInternalServerError)

Loading…
Cancel
Save