In web/articles.go made use of a constructor. Also, since a constructor returns a pointer, map also now stores a pointer to Article.
This commit is contained in:
parent
7f17ebd2c5
commit
72b09218f8
@ -17,7 +17,7 @@ const (
|
|||||||
|
|
||||||
//go:embed articles
|
//go:embed articles
|
||||||
var articlesFS embed.FS
|
var articlesFS embed.FS
|
||||||
var articles map[string]article.Article = make(map[string]article.Article)
|
var articles map[string]*article.Article = make(map[string]*article.Article)
|
||||||
|
|
||||||
// ArticleMetadata holds date, title and URL of an article used in articles list
|
// ArticleMetadata holds date, title and URL of an article used in articles list
|
||||||
// on the Stuff page.
|
// on the Stuff page.
|
||||||
@ -49,7 +49,7 @@ func GetArticleMetadata() (meta []ArticleMetadata) {
|
|||||||
|
|
||||||
func GetArticle(name string) (*article.Article, error) {
|
func GetArticle(name string) (*article.Article, error) {
|
||||||
if artcl, ok := articles[name]; ok {
|
if artcl, ok := articles[name]; ok {
|
||||||
return &artcl, nil
|
return artcl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
meta, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
meta, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
||||||
@ -62,14 +62,9 @@ func GetArticle(name string) (*article.Article, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
artcl := article.Article{
|
articles[name], err = article.New(markdown.ToHTML(md, nil, nil), meta)
|
||||||
Body: markdown.ToHTML(md, nil, nil)}
|
|
||||||
|
|
||||||
artcl.ParseMetadata(meta)
|
return articles[name], err
|
||||||
|
|
||||||
articles[name] = artcl
|
|
||||||
|
|
||||||
return &artcl, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user