2023-01-16 05:24:07 +04:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
2023-02-05 04:43:09 +04:00
|
|
|
|
|
|
|
"git.arav.top/Arav/dwelling-home/pkg/article"
|
|
|
|
"github.com/gomarkdown/markdown"
|
2023-01-16 05:24:07 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// To install a Jade compiler: go install github.com/Joker/jade/cmd/jade@latest
|
2023-02-05 00:55:22 +04:00
|
|
|
//
|
2023-02-05 21:12:23 +04:00
|
|
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer index.pug stuff.pug mindflow.pug
|
|
|
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer about.pug guestbook.pug rss.pug
|
2023-02-06 02:00:20 +04:00
|
|
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer guestbook_admin.pug
|
2023-02-05 04:43:09 +04:00
|
|
|
|
|
|
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer article.pug
|
2023-01-16 05:24:07 +04:00
|
|
|
|
2023-02-05 23:23:55 +04:00
|
|
|
//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer error403.pug error404.pug error500.pug
|
2023-02-05 05:25:20 +04:00
|
|
|
|
2023-01-16 05:24:07 +04:00
|
|
|
//go:embed assets
|
|
|
|
var assetsDir embed.FS
|
|
|
|
|
|
|
|
func Assets() http.FileSystem {
|
|
|
|
f, _ := fs.Sub(assetsDir, "assets")
|
|
|
|
return http.FS(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AssetsGetFile(path string) ([]byte, error) {
|
|
|
|
return assetsDir.ReadFile("assets/" + path)
|
|
|
|
}
|
2023-02-05 04:43:09 +04:00
|
|
|
|
|
|
|
//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
|
|
|
|
}
|
|
|
|
}
|