diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2023-01-21 18:36:28 +0100 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2023-01-21 18:36:28 +0100 |
commit | bde3751fab0120b6722e5532a97bdc7e12a71406 (patch) | |
tree | 2fb7013786ddc79e5be3ed76d54b68cee74984b5 /src/gmi | |
parent | ffdd9520b9803e141582ba647050682659075760 (diff) |
Convert markdow to gemtext in gmi server
Diffstat (limited to 'src/gmi')
-rw-r--r-- | src/gmi/tpl.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go index 7f41993..9e0bc64 100644 --- a/src/gmi/tpl.go +++ b/src/gmi/tpl.go @@ -16,6 +16,7 @@ import ( "git.sr.ht/~adnano/go-gemini" "github.com/mediocregopher/blog.mediocregopher.com/srv/post" "github.com/mediocregopher/mediocre-go-lib/v2/mctx" + gmnhg "github.com/tdemin/gmnhg" ) //go:embed tpl @@ -120,7 +121,19 @@ func (r renderer) PostBody(p post.StoredPost) (string, error) { return "", fmt.Errorf("preprocessing post body: %w", err) } - return buf.String(), nil + bodyBytes := buf.Bytes() + + if p.Format == post.FormatMarkdown { + + gemtextBodyBytes, err := gmnhg.RenderMarkdown(bodyBytes, 0) + if err != nil { + return "", fmt.Errorf("converting from markdown: %w", err) + } + + bodyBytes = gemtextBodyBytes + } + + return string(bodyBytes), nil } func (r renderer) GetQueryValue(key, def string) string { |