mirror of
https://github.com/danog/gojekyll.git
synced 2025-01-22 18:01:15 +01:00
Default permalink honors md, scss output extensions
This commit is contained in:
parent
15cff8988a
commit
6a4b048a09
7
page.go
7
page.go
@ -54,6 +54,8 @@ func (p *pageFields) Published() bool {
|
||||
return p.frontMatter.Bool("published", true)
|
||||
}
|
||||
|
||||
// The permalink is computed once instead of on demand, so that subsequent
|
||||
// access needn't check for an error.
|
||||
func (p *pageFields) setPermalink(permalink string) {
|
||||
p.permalink = permalink
|
||||
}
|
||||
@ -77,13 +79,12 @@ func ReadPage(path string, defaults VariableMap) (p Page, err error) {
|
||||
}
|
||||
if p != nil {
|
||||
// Compute this after creating the page, to pick up the the front matter.
|
||||
// The permalink is computed once instead of on demand, so that subsequent
|
||||
// access needn't check for an error.
|
||||
pattern := data.frontMatter.String("permalink", ":path")
|
||||
pattern := data.frontMatter.String("permalink", ":path:output_ext")
|
||||
permalink, err := expandPermalinkPattern(pattern, data.path, data.frontMatter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
println(path, pattern, permalink)
|
||||
p.setPermalink(permalink)
|
||||
}
|
||||
return
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -43,18 +44,25 @@ func permalinkTemplateVariables(path string, frontMatter VariableMap) map[string
|
||||
name = filepath.Base(root)
|
||||
title = frontMatter.String("title", name)
|
||||
)
|
||||
if isMarkdown(path) {
|
||||
switch {
|
||||
case isMarkdown(path):
|
||||
outputExt = ".html"
|
||||
case ext == ".scss":
|
||||
outputExt = ".html"
|
||||
}
|
||||
if val, found := frontMatter["collection"]; found {
|
||||
collectionName = val.(string)
|
||||
prefix := "_" + collectionName + "/"
|
||||
if !strings.HasPrefix(localPath, prefix) {
|
||||
panic(fmt.Errorf("Expected %s to start with %s", localPath, prefix))
|
||||
}
|
||||
localPath = localPath[len(prefix):]
|
||||
root = root[len(prefix):]
|
||||
}
|
||||
vs := map[string]string{
|
||||
"collection": collectionName,
|
||||
"name": name,
|
||||
"path": "/" + localPath,
|
||||
"name": Slugify(name),
|
||||
"path": "/" + root,
|
||||
"title": title,
|
||||
"slug": Slugify(name),
|
||||
// TODO categories
|
||||
|
@ -28,7 +28,7 @@ func TestExpandPermalinkPattern(t *testing.T) {
|
||||
})
|
||||
t.Run(":path", func(t *testing.T) {
|
||||
p, _ := expandPermalinkPattern("/prefix:path/post", path, d)
|
||||
assert.Equal(t, "/prefix/a/b/base.html/post", p)
|
||||
assert.Equal(t, "/prefix/a/b/base/post", p)
|
||||
})
|
||||
t.Run(":title", func(t *testing.T) {
|
||||
p, _ := expandPermalinkPattern("/title/:title.html", path, d)
|
||||
@ -40,9 +40,9 @@ func TestExpandPermalinkPattern(t *testing.T) {
|
||||
})
|
||||
|
||||
d["collection"] = "c"
|
||||
path = "/_c/a/b/c.d"
|
||||
path = "_c/a/b/c.d"
|
||||
t.Run(":path", func(t *testing.T) {
|
||||
p, _ := expandPermalinkPattern("/prefix:path/post", path, d)
|
||||
assert.Equal(t, "/prefix/a/b/c.d/post", p)
|
||||
assert.Equal(t, "/prefix/a/b/c/post", p)
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user