Skip to content

Commit

Permalink
Use "tags" and "categories" from frontmatter for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ringmaster committed Nov 9, 2024
1 parent 4347a70 commit d982b24
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions sn/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,25 @@ func loadItem(repoName string, repoPath string, filename string) (Item, error) {
item.Html, _ = replaceImgSrc(item.Html)

// Get Categories from frontmatter
var categories []string
categories := make([]string, 0)
if _, ok := f["categories"]; ok {
arr := f["categories"].([]interface{})
categories = make([]string, len(arr))
for i, v := range arr {
categories[i] = fmt.Sprint(v)
for _, v := range arr {
categories = append(categories, fmt.Sprint(v))
}
}

// Get Categories from frontmatter tags
if _, ok := f["tags"]; ok {
switch f["tags"].(type) {
case string:
categories = append(categories, f["tags"].(string))
case []interface{}:
for _, v := range f["tags"].([]interface{}) {
categories = append(categories, fmt.Sprint(v))
}
case nil:
}
}

Expand Down Expand Up @@ -659,6 +672,7 @@ func ItemsFromOutvals(outVariableParams map[string]interface{}, context map[stri
setQryValue(&qry.Slug, params, "slug")
setQryValue(&qry.Repo, params, "repo")
setQryValue(&qry.Category, params, "category")
setQryValue(&qry.Category, params, "tag")
setQryValue(&qry.Author, params, "author")
setQryValue(&qry.Search, params, "search")
setQryValue(&qry.OrderBy, params, "order_by")
Expand Down

0 comments on commit d982b24

Please sign in to comment.