Part of GetArticle() for loading an article from a file was moved out to init() func.
This commit is contained in:
parent
72b09218f8
commit
48e7a86312
@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -47,24 +48,11 @@ func GetArticleMetadata() (meta []ArticleMetadata) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArticle(name string) (*article.Article, error) {
|
func GetArticle(name string) *article.Article {
|
||||||
if artcl, ok := articles[name]; ok {
|
if artcl, ok := articles[name]; ok {
|
||||||
return artcl, nil
|
return artcl
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
meta, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
md, err := articlesFS.ReadFile("articles/" + name + articleFileExtension)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
articles[name], err = article.New(markdown.ToHTML(md, nil, nil), meta)
|
|
||||||
|
|
||||||
return articles[name], err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -72,7 +60,22 @@ func init() {
|
|||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if strings.HasSuffix(entry.Name(), articleFileExtension) {
|
if strings.HasSuffix(entry.Name(), articleFileExtension) {
|
||||||
GetArticle(strings.TrimSuffix(entry.Name(), articleFileExtension))
|
name := strings.TrimSuffix(entry.Name(), articleFileExtension)
|
||||||
|
|
||||||
|
meta, err := articlesFS.ReadFile("articles/" + entry.Name())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("an article \"", name, "\" cannot be read:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
md, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("a metadata for an article \"", name, "\" cannot be read:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
articles[name], err = article.New(markdown.ToHTML(md, nil, nil), meta)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("an article \"", name, "\" cannot be parsed:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user