1
0
Fork 0

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:
Alexander Andreev 2023-09-24 19:05:22 +04:00
parent 7f17ebd2c5
commit 72b09218f8
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 4 additions and 9 deletions

View File

@ -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() {