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
|
||||
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
|
||||
// on the Stuff page.
|
||||
@ -49,7 +49,7 @@ func GetArticleMetadata() (meta []ArticleMetadata) {
|
||||
|
||||
func GetArticle(name string) (*article.Article, error) {
|
||||
if artcl, ok := articles[name]; ok {
|
||||
return &artcl, nil
|
||||
return artcl, nil
|
||||
}
|
||||
|
||||
meta, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
||||
@ -62,14 +62,9 @@ func GetArticle(name string) (*article.Article, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
artcl := article.Article{
|
||||
Body: markdown.ToHTML(md, nil, nil)}
|
||||
articles[name], err = article.New(markdown.ToHTML(md, nil, nil), meta)
|
||||
|
||||
artcl.ParseMetadata(meta)
|
||||
|
||||
articles[name] = artcl
|
||||
|
||||
return &artcl, nil
|
||||
return articles[name], err
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Loading…
Reference in New Issue
Block a user