mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Handle Taxonomy permalinks
Return the correct virtual Section for Taxonomy and TaxonomyTerm. Restrict permalink expansion to only Pages and Taxonomies, but then actually use expanded permalinks even for non-Pages. Fixes #1208.
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
23ba779fab
commit
d9a78b61ad
@@ -77,6 +77,10 @@ tag = "tags"
|
||||
category = "categories"
|
||||
other = "others"
|
||||
empty = "empties"
|
||||
permalinked = "permalinkeds"
|
||||
|
||||
[permalinks]
|
||||
permalinkeds = "/perma/:slug/"
|
||||
`
|
||||
|
||||
pageTemplate := `---
|
||||
@@ -87,6 +91,8 @@ categories:
|
||||
%s
|
||||
others:
|
||||
%s
|
||||
permalinkeds:
|
||||
%s
|
||||
---
|
||||
# Doc
|
||||
`
|
||||
@@ -99,15 +105,15 @@ others:
|
||||
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)
|
||||
@@ -146,10 +152,11 @@ others:
|
||||
// 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 {
|
||||
@@ -170,6 +177,14 @@ others:
|
||||
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")
|
||||
|
Reference in New Issue
Block a user