Implemented a sane system for articles that now are in markdown.
This commit is contained in:
parent
6987070d68
commit
0823166ec9
39
web/web.go
39
web/web.go
@ -4,6 +4,9 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.arav.top/Arav/dwelling-home/pkg/article"
|
||||||
|
"github.com/gomarkdown/markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
// To install a Jade compiler: go install github.com/Joker/jade/cmd/jade@latest
|
// To install a Jade compiler: go install github.com/Joker/jade/cmd/jade@latest
|
||||||
@ -11,11 +14,8 @@ import (
|
|||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer index.pug stuff.pug mindflow.pug about.pug
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer index.pug stuff.pug mindflow.pug about.pug
|
||||||
// guestbook.pug
|
// guestbook.pug
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer rss.pug
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer rss.pug
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer articles/hardening_mikrotik.pug
|
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer articles/nginx_recipes_and_tips.pug
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer article.pug
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer articles/rpi_root_on_external_drive.pug
|
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer articles/setting_up_a_mail_server.pug
|
|
||||||
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer articles/setting_up_a_tor_proxy_relay_hiddenserv.pug
|
|
||||||
|
|
||||||
//go:embed assets
|
//go:embed assets
|
||||||
var assetsDir embed.FS
|
var assetsDir embed.FS
|
||||||
@ -28,3 +28,32 @@ func Assets() http.FileSystem {
|
|||||||
func AssetsGetFile(path string) ([]byte, error) {
|
func AssetsGetFile(path string) ([]byte, error) {
|
||||||
return assetsDir.ReadFile("assets/" + path)
|
return assetsDir.ReadFile("assets/" + path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed articles
|
||||||
|
var articlesFS embed.FS
|
||||||
|
var articles map[string]article.Article = make(map[string]article.Article)
|
||||||
|
|
||||||
|
func GetArticle(name string) (*article.Article, error) {
|
||||||
|
if artcl, ok := articles[name]; ok {
|
||||||
|
return &artcl, nil
|
||||||
|
} else {
|
||||||
|
meta, err := articlesFS.ReadFile("articles/" + name + ".meta")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
md, err := articlesFS.ReadFile("articles/" + name + ".md")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
artcl := article.Article{
|
||||||
|
Body: markdown.ToHTML(md, nil, nil)}
|
||||||
|
|
||||||
|
artcl.ParseMetadata(meta)
|
||||||
|
|
||||||
|
articles[name] = artcl
|
||||||
|
|
||||||
|
return &artcl, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user