Add directions and fix emdbed

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/1/head
jolheiser 2021-12-25 23:13:57 -06:00
parent 6b485605e6
commit 447c88febe
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
7 changed files with 56 additions and 11 deletions

View File

@ -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)

View File

@ -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 100644
View File

@ -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)
}
}

View File

@ -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)