Fill Metadata slice in init(). Removed GetArticleMetadata. A slice instead was made public.
This commit is contained in:
parent
9e33fa359b
commit
948715d8eb
@ -29,24 +29,7 @@ type ArticleMetadata struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
// GetArticleMetadata returns a slice of metadata that is sorted by ID
|
||||
func GetArticleMetadata() (meta []ArticleMetadata) {
|
||||
for urlid, article := range articles {
|
||||
|
||||
meta = append(meta,
|
||||
ArticleMetadata{
|
||||
ID: article.ID,
|
||||
Date: article.Date,
|
||||
Title: article.Title,
|
||||
URL: "stuff/article/" + urlid})
|
||||
}
|
||||
|
||||
sort.Slice(meta, func(i, j int) bool {
|
||||
return meta[i].ID > meta[j].ID
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
var Metadata []ArticleMetadata
|
||||
|
||||
func GetArticle(name string) *article.Article {
|
||||
if artcl, ok := articles[name]; ok {
|
||||
@ -56,18 +39,21 @@ func GetArticle(name string) *article.Article {
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
//// Load articles
|
||||
|
||||
entries, _ := articlesFS.ReadDir("articles")
|
||||
|
||||
for _, entry := range entries {
|
||||
if strings.HasSuffix(entry.Name(), articleFileExtension) {
|
||||
name := strings.TrimSuffix(entry.Name(), articleFileExtension)
|
||||
|
||||
meta, err := articlesFS.ReadFile("articles/" + entry.Name())
|
||||
meta, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
||||
if err != nil {
|
||||
log.Fatalln("an article \"", name, "\" cannot be read:", err)
|
||||
}
|
||||
|
||||
md, err := articlesFS.ReadFile("articles/" + name + articleMetaExtension)
|
||||
md, err := articlesFS.ReadFile("articles/" + entry.Name())
|
||||
if err != nil {
|
||||
log.Fatalln("a metadata for an article \"", name, "\" cannot be read:", err)
|
||||
}
|
||||
@ -78,4 +64,21 @@ func init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//// Fill and sort metadata slice
|
||||
|
||||
for urlid, article := range articles {
|
||||
Metadata = append(Metadata,
|
||||
ArticleMetadata{
|
||||
ID: article.ID,
|
||||
Date: article.Date,
|
||||
Title: article.Title,
|
||||
URL: "stuff/article/" + urlid})
|
||||
}
|
||||
|
||||
sort.Slice(Metadata, func(i, j int) bool {
|
||||
return Metadata[i].ID > Metadata[j].ID
|
||||
})
|
||||
|
||||
articlesFS = embed.FS{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user