1
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

View File

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