Skip to content

Commit

Permalink
fix: broken links and customFields in frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaklog committed Jul 2, 2024
1 parent 8eeeb06 commit bdfbbe0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
36 changes: 23 additions & 13 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -36,18 +37,19 @@ type LayoutConfig struct {
}

type Frontmatter struct {
Title string `yaml:"title"`
Date string `yaml:"date"`
Draft bool `yaml:"draft"`
JSFiles []string `yaml:"scripts"`
Type string `yaml:"type"`
Description string `yaml:"description"`
PreviewImage string `yaml:"previewimage"`
Tags []string `yaml:"tags"`
TOC bool `yaml:"toc"`
Authors []string `yaml:"authors"`
Collections []string `yaml:"collections"`
Layout string `yaml:"layout"`
Title string `yaml:"title"`
Date string `yaml:"date"`
Draft bool `yaml:"draft"`
JSFiles []string `yaml:"scripts"`
Type string `yaml:"type"`
Description string `yaml:"description"`
PreviewImage string `yaml:"previewimage"`
Tags []string `yaml:"tags"`
TOC bool `yaml:"toc"`
Authors []string `yaml:"authors"`
Collections []string `yaml:"collections"`
Layout string `yaml:"layout"`
CustomFields []map[string]string `yaml:"customFields"`

// Head is specifically used for
// mentioning the head of the notes
Expand Down Expand Up @@ -400,7 +402,15 @@ func (p *Parser) collectionsParser(page TemplateData) {
}
collectionKey += ".html"

p.CollectionsMap[template.URL(collectionKey)] = append(p.CollectionsMap[template.URL(collectionKey)], page)
var found bool
for _, map_page := range p.CollectionsMap[template.URL(collectionKey)] {
if reflect.DeepEqual(map_page, page) {
found = true
}
}
if !found {
p.CollectionsMap[template.URL(collectionKey)] = append(p.CollectionsMap[template.URL(collectionKey)], page)
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion site/layout/all-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<article>
<section class="posts">
{{range $Post := index .DeepDataMerge.CollectionsMap .PageURL}}
<a class="post-card" href="{{$Post.CompleteURL}}">
<a class="post-card" href="/{{$Post.CompleteURL}}">
<div class="post-card-div">
<h3>{{$Post.Frontmatter.Title}}</h3>
<p>{{$Post.Frontmatter.Description}}</p>
Expand Down
2 changes: 1 addition & 1 deletion test/engine/json_index_test/want_index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"docs.md":{"CompleteURL":"docs.html","Frontmatter":{"Title":"Anna Documentation","Date":"","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"TOC":false,"Authors":null,"Collections":null,"Layout":"","Head":false},"Tags":null}}
{"docs.md":{"CompleteURL":"docs.html","Frontmatter":{"Title":"Anna Documentation","Date":"","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"TOC":false,"Authors":null,"Collections":null,"Layout":"","CustomFields":null,"Head":false},"Tags":null}}

0 comments on commit bdfbbe0

Please sign in to comment.