1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-22 15:51:22 +01:00

Read title from frontmatter

This commit is contained in:
Oliver Steele 2017-07-14 11:30:39 -04:00
parent 02981b719b
commit 2f3ed9a9d1
3 changed files with 8 additions and 7 deletions

View File

@ -50,13 +50,13 @@ func (c *Collection) scanDirectory(dirname string) error {
case c.site.Exclude(siteRel):
return nil
default:
return c.readFile(filename, utils.MustRel(dir, filename))
return c.readPost(filename, utils.MustRel(dir, filename))
}
}
return filepath.Walk(dir, walkFn)
}
func (c *Collection) readFile(abs string, rel string) error {
func (c *Collection) readPost(abs string, rel string) error {
siteRel := utils.MustRel(c.config.Source, abs)
strategy := c.strategy()
switch {
@ -78,7 +78,7 @@ func (c *Collection) readFile(abs string, rel string) error {
case f.Static():
return nil
case f.Published() || c.config.Unpublished:
p := f.(pages.Page)
p := f.(pages.Page) // f.Static() guarantees this
c.pages = append(c.pages, p)
}
return nil

View File

@ -59,7 +59,7 @@ func (p *page) permalinkVariables() map[string]string {
"name": utils.Slugify(name),
"path": "/" + root, // TODO are we removing and then adding this?
"slug": slug,
"title": slug,
"title": utils.Slugify(bindings.String("title", name)),
// The following aren't documented, but are evident
"output_ext": p.OutputExt(),
"y_day": strconv.Itoa(p.fileModTime.YearDay()),

View File

@ -2,6 +2,7 @@ package utils
import (
"regexp"
"strings"
)
// LeftPad left-pads s with spaces to n wide. It's an alternative to http://left-pad.io.
@ -45,13 +46,13 @@ var nonAlphanumericSequenceMatcher = regexp.MustCompile(`[^[:alnum:]]+`)
// Slugify replaces each sequence of non-alphanumerics by a single hyphen
func Slugify(s string) string {
return nonAlphanumericSequenceMatcher.ReplaceAllString(s, "-")
return strings.ToLower(nonAlphanumericSequenceMatcher.ReplaceAllString(s, "-"))
}
// StringArrayToMap creates a map for use as a set.
func StringArrayToMap(strings []string) map[string]bool {
func StringArrayToMap(a []string) map[string]bool {
stringMap := map[string]bool{}
for _, s := range strings {
for _, s := range a {
stringMap[s] = true
}
return stringMap