d.LangPrefix = p.Lang()
}
- if override, ok := p.Site.Permalinks[p.Section()]; ok {
- opath, err := override.Expand(p)
- if err != nil {
- return err
- }
+ // Expand only KindPage and KindTaxonomy; don't expand other Kinds of Pages
+ // like KindSection or KindTaxonomyTerm because they are "shallower" and
+ // the permalink configuration values are likely to be redundant, e.g.
+ // naively expanding /category/:slug/ would give /category/categories/ for
+ // the "categories" KindTaxonomyTerm.
+ if p.Kind == KindPage || p.Kind == KindTaxonomy {
+ if override, ok := p.Site.Permalinks[p.Section()]; ok {
+ opath, err := override.Expand(p)
+ if err != nil {
+ return err
+ }
- opath, _ = url.QueryUnescape(opath)
- opath = filepath.FromSlash(opath)
- d.ExpandedPermalink = opath
+ opath, _ = url.QueryUnescape(opath)
+ opath = filepath.FromSlash(opath)
+ d.ExpandedPermalink = opath
+ }
}
p.targetPathDescriptorPrototype = d
}
if d.Kind != KindPage && len(d.Sections) > 0 {
- pagePath = filepath.Join(d.Sections...)
+ if d.ExpandedPermalink != "" {
+ pagePath = filepath.Join(pagePath, d.ExpandedPermalink)
+ } else {
+ pagePath = filepath.Join(d.Sections...)
+ }
needsBase = false
}
category = "categories"
other = "others"
empty = "empties"
+permalinked = "permalinkeds"
+
+[permalinks]
+permalinkeds = "/perma/:slug/"
`
pageTemplate := `---
%s
others:
%s
+permalinkeds:
+%s
---
# Doc
`
fs := th.Fs
if preserveTaxonomyNames {
- writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- tag1", "- cat1", "- o1"))
+ writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- tag1", "- cat1", "- o1", "- pl1"))
} else {
// Check lower-casing of tags
- writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- Tag1", "- cAt1", "- o1"))
+ writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- Tag1", "- cAt1", "- o1", "- pl1"))
}
- writeSource(t, fs, "content/p2.md", fmt.Sprintf(pageTemplate, "t2/c1", "- tag2", "- cat1", "- o1"))
- writeSource(t, fs, "content/p3.md", fmt.Sprintf(pageTemplate, "t2/c12", "- tag2", "- cat2", "- o1"))
- writeSource(t, fs, "content/p4.md", fmt.Sprintf(pageTemplate, "Hello World", "", "", "- \"Hello Hugo world\""))
+ writeSource(t, fs, "content/p2.md", fmt.Sprintf(pageTemplate, "t2/c1", "- tag2", "- cat1", "- o1", "- pl1"))
+ writeSource(t, fs, "content/p3.md", fmt.Sprintf(pageTemplate, "t2/c12", "- tag2", "- cat2", "- o1", "- pl1"))
+ writeSource(t, fs, "content/p4.md", fmt.Sprintf(pageTemplate, "Hello World", "", "", "- \"Hello Hugo world\"", "- pl1"))
writeNewContentFile(t, fs, "Category Terms", "2017-01-01", "content/categories/_index.md", 10)
writeNewContentFile(t, fs, "Tag1 List", "2017-01-01", "content/tags/tag1/_index.md", 10)
// Make sure that each KindTaxonomyTerm page has an appropriate number
// of KindTaxonomy pages in its Pages slice.
taxonomyTermPageCounts := map[string]int{
- "tags": 2,
- "categories": 2,
- "others": 2,
- "empties": 0,
+ "tags": 2,
+ "categories": 2,
+ "others": 2,
+ "empties": 0,
+ "permalinkeds": 1,
}
for taxonomy, count := range taxonomyTermPageCounts {
require.Equal(t, "/blog/categories/cat1/", cat1.RelPermalink())
}
+ pl1 := s.getPage(KindTaxonomy, "permalinkeds", "pl1")
+ require.NotNil(t, pl1)
+ if uglyURLs {
+ require.Equal(t, "/blog/perma/pl1.html", pl1.RelPermalink())
+ } else {
+ require.Equal(t, "/blog/perma/pl1/", pl1.RelPermalink())
+ }
+
// Issue #3070 preserveTaxonomyNames
if preserveTaxonomyNames {
helloWorld := s.getPage(KindTaxonomy, "others", "Hello Hugo world")