diff --git a/web/articles.go b/web/articles.go index 5c4b49f..baff513 100644 --- a/web/articles.go +++ b/web/articles.go @@ -2,6 +2,7 @@ package web import ( "embed" + "log" "sort" "strings" "time" @@ -47,24 +48,11 @@ func GetArticleMetadata() (meta []ArticleMetadata) { return } -func GetArticle(name string) (*article.Article, error) { +func GetArticle(name string) *article.Article { if artcl, ok := articles[name]; ok { - return artcl, nil + return artcl } - - 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 + return nil } func init() { @@ -72,7 +60,22 @@ func init() { for _, entry := range entries { 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) + } } } }