mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 06:19:00 +01:00
Posts obey config.permalink
This commit is contained in:
parent
1d02fe4fbe
commit
6451139756
@ -93,6 +93,6 @@ func (c *Collection) ToLiquid() interface{} {
|
||||
|
||||
// PermalinkPattern returns the default permalink pattern for this collection.
|
||||
func (c *Collection) PermalinkPattern() string {
|
||||
pattern := c.strategy().defaultPermalinkPattern()
|
||||
pattern := c.strategy().defaultPermalinkPattern(c.cfg)
|
||||
return templates.VariableMap(c.Metadata).String("permalink", pattern)
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func TestPermalinkPattern(t *testing.T) {
|
||||
require.Equal(t, "out", c2.PermalinkPattern())
|
||||
|
||||
c3 := New(site, "posts", map[string]interface{}{})
|
||||
require.Contains(t, c3.PermalinkPattern(), "/:year/:month/:day/:title")
|
||||
require.Contains(t, c3.PermalinkPattern(), "date")
|
||||
}
|
||||
|
||||
func Test_ReadPages(t *testing.T) {
|
||||
|
@ -68,8 +68,8 @@ func (c *Collection) scanDirectory(dirname string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Collection) readPost(abs string, rel string) error {
|
||||
siteRel := utils.MustRel(c.cfg.Source, abs)
|
||||
func (c *Collection) readPost(path string, rel string) error {
|
||||
siteRel := utils.MustRel(c.cfg.Source, path)
|
||||
strategy := c.strategy()
|
||||
switch {
|
||||
case !strategy.isCollectible(rel):
|
||||
@ -77,13 +77,12 @@ func (c *Collection) readPost(abs string, rel string) error {
|
||||
case strategy.isFuture(rel) && !c.cfg.Future:
|
||||
return nil
|
||||
}
|
||||
pageDefaults := frontmatter.FrontMatter{
|
||||
fm := frontmatter.FrontMatter{
|
||||
"collection": c.Name,
|
||||
"permalink": c.PermalinkPattern(),
|
||||
}
|
||||
fm := pageDefaults.Merged(c.cfg.GetFrontMatterDefaults(c.Name, siteRel))
|
||||
}.Merged(c.cfg.GetFrontMatterDefaults(c.Name, siteRel))
|
||||
strategy.parseFilename(rel, fm)
|
||||
f, err := pages.NewFile(c.site, abs, filepath.ToSlash(rel), fm)
|
||||
f, err := pages.NewFile(c.site, path, filepath.ToSlash(rel), fm)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
|
@ -3,13 +3,14 @@ package collection
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/osteele/gojekyll/config"
|
||||
"github.com/osteele/gojekyll/utils"
|
||||
)
|
||||
|
||||
// A collectionStrategy encapsulates behavior differences between the `_post`
|
||||
// collection and other collections.
|
||||
type collectionStrategy interface {
|
||||
defaultPermalinkPattern() string
|
||||
defaultPermalinkPattern(*config.Config) string
|
||||
isCollectible(filename string) bool
|
||||
isFuture(filename string) bool
|
||||
parseFilename(string, map[string]interface{})
|
||||
@ -58,10 +59,13 @@ const DefaultCollectionPermalinkPattern = "/:collection/:path:output_ext"
|
||||
// DefaultPostsCollectionPermalinkPattern is the default collection permalink pattern
|
||||
const DefaultPostsCollectionPermalinkPattern = "/:categories/:year/:month/:day/:title.html"
|
||||
|
||||
func (s defaultStrategy) defaultPermalinkPattern() string {
|
||||
func (s defaultStrategy) defaultPermalinkPattern(*config.Config) string {
|
||||
return DefaultCollectionPermalinkPattern
|
||||
}
|
||||
|
||||
func (s postsStrategy) defaultPermalinkPattern() string {
|
||||
func (s postsStrategy) defaultPermalinkPattern(cfg *config.Config) string {
|
||||
if s, ok := cfg.String("permalink"); ok {
|
||||
return s
|
||||
}
|
||||
return DefaultPostsCollectionPermalinkPattern
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user