summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-10 10:20:08 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-10 18:23:41 +0100
commitf0eecc6a4f541838e9930c98bc982546f65c7a4f (patch)
treec5d1b91d9a6201857bb20a6226a85aac09596db2 /hugolib
parent768ec5df9fa8f91610ee80a9e6194f94a7dbe117 (diff)
Fix non-ASCII path handling for Page resources
Fixes #4241
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go8
-rw-r--r--hugolib/page_bundler_capture_test.go1
-rw-r--r--hugolib/page_bundler_handlers.go2
-rw-r--r--hugolib/page_bundler_test.go23
-rw-r--r--hugolib/page_paths.go15
5 files changed, 38 insertions, 11 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 437170f42..8181de953 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -228,9 +228,9 @@ type Page struct {
permalink string
relPermalink string
- // relPermalink without extension and any base path element from the baseURL.
+ // relative target path without extension and any base path element from the baseURL.
// This is used to construct paths in the page resources.
- relPermalinkBase string
+ relTargetPathBase string
layoutDescriptor output.LayoutDescriptor
@@ -989,8 +989,8 @@ func (p *Page) RelPermalink() string {
return p.relPermalink
}
-func (p *Page) subResourceLinkFactory(base string) string {
- return path.Join(p.relPermalinkBase, base)
+func (p *Page) subResourceTargetPathFactory(base string) string {
+ return path.Join(p.relTargetPathBase, base)
}
func (p *Page) prepareForRender(cfg *BuildCfg) error {
diff --git a/hugolib/page_bundler_capture_test.go b/hugolib/page_bundler_capture_test.go
index c7715491e..93cf739c0 100644
--- a/hugolib/page_bundler_capture_test.go
+++ b/hugolib/page_bundler_capture_test.go
@@ -144,6 +144,7 @@ D:
__bundle/en/work/base/_index.md/resources/en/work/base/_1.png
__bundle/en/work/base/a/b/index.md/resources/en/work/base/a/b/ab1.md
__bundle/en/work/base/b/index.md/resources/en/work/base/b/1.md|en/work/base/b/2.md|en/work/base/b/c/logo.png|en/work/base/b/custom-mime.bep|en/work/base/b/sunset1.jpg|en/work/base/b/sunset2.jpg
+__bundle/en/work/base/c/index.md/resources/en/work/base/c/logo-은행.png
C:
/work/base/assets/pic1.png
/work/base/assets/pic2.png
diff --git a/hugolib/page_bundler_handlers.go b/hugolib/page_bundler_handlers.go
index 7054f0b79..8696959dc 100644
--- a/hugolib/page_bundler_handlers.go
+++ b/hugolib/page_bundler_handlers.go
@@ -319,7 +319,7 @@ func (c *contentHandlers) createResource() contentHandler {
}
resource, err := c.s.resourceSpec.NewResourceFromFilename(
- ctx.parentPage.subResourceLinkFactory,
+ ctx.parentPage.subResourceTargetPathFactory,
c.s.absPublishDir(),
ctx.source.Filename(), ctx.target)
diff --git a/hugolib/page_bundler_test.go b/hugolib/page_bundler_test.go
index d3f3df209..f43766fb8 100644
--- a/hugolib/page_bundler_test.go
+++ b/hugolib/page_bundler_test.go
@@ -51,6 +51,7 @@ func TestPageBundlerSite(t *testing.T) {
cfg.Set("permalinks", map[string]string{
"a": ":sections/:filename",
"b": ":year/:slug/",
+ "c": ":sections/:slug",
})
cfg.Set("outputFormats", map[string]interface{}{
@@ -74,7 +75,7 @@ func TestPageBundlerSite(t *testing.T) {
th := testHelper{s.Cfg, s.Fs, t}
// Singles (2), Below home (1), Bundle (1)
- assert.Len(s.RegularPages, 6)
+ assert.Len(s.RegularPages, 7)
singlePage := s.getPage(KindPage, "a/1.md")
@@ -99,6 +100,8 @@ func TestPageBundlerSite(t *testing.T) {
assert.NotNil(leafBundle1)
leafBundle2 := s.getPage(KindPage, "a/b/index.md")
assert.NotNil(leafBundle2)
+ unicodeBundle := s.getPage(KindPage, "c/index.md")
+ assert.NotNil(unicodeBundle)
pageResources := leafBundle1.Resources.ByType(pageResourceType)
assert.Len(pageResources, 2)
@@ -136,12 +139,18 @@ func TestPageBundlerSite(t *testing.T) {
assert.Equal("/a/b.html", leafBundle2.RelPermalink())
+ // 은행
+ assert.Equal("/c/%EC%9D%80%ED%96%89.html", unicodeBundle.RelPermalink())
+ th.assertFileContent(filepath.FromSlash("/work/public/c/은행.html"), "Content for 은행")
+ th.assertFileContent(filepath.FromSlash("/work/public/c/은행/logo-은행.png"), "은행 PNG")
+
} else {
assert.Equal("/2017/pageslug/", leafBundle1.RelPermalink())
th.assertFileContent(filepath.FromSlash("/work/public/2017/pageslug/index.html"), "TheContent")
th.assertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug/cindex.html"), "TheContent")
assert.Equal("/a/b/", leafBundle2.RelPermalink())
+
}
})
@@ -261,6 +270,18 @@ Short Thumb Width: {{ $thumb.Width }}
writeSource(t, fs, filepath.Join(workDir, "base", "b", "custom-mime.bep"), "bepsays")
writeSource(t, fs, filepath.Join(workDir, "base", "b", "c", "logo.png"), "content")
+ // Bundle with 은행 slug
+ // See https://github.com/gohugoio/hugo/issues/4241
+ writeSource(t, fs, filepath.Join(workDir, "base", "c", "index.md"), `---
+title: "은행 은행"
+slug: 은행
+date: 2017-10-09
+---
+
+Content for 은행.
+`)
+ writeSource(t, fs, filepath.Join(workDir, "base", "c", "logo-은행.png"), "은행 PNG")
+
// Write a real image into one of the bundle above.
src, err := os.Open("testdata/sunset.jpg")
assert.NoError(err)
diff --git a/hugolib/page_paths.go b/hugolib/page_paths.go
index 287678c61..4033ba4b3 100644
--- a/hugolib/page_paths.go
+++ b/hugolib/page_paths.go
@@ -129,7 +129,8 @@ func (p *Page) initURLs() error {
if len(p.outputFormats) == 0 {
p.outputFormats = p.s.outputFormats[p.Kind]
}
- rel := p.createRelativePermalink()
+ target := filepath.ToSlash(p.createRelativeTargetPath())
+ rel := p.s.PathSpec.URLizeFilename(target)
var err error
f := p.outputFormats[0]
@@ -138,7 +139,7 @@ func (p *Page) initURLs() error {
return err
}
- p.relPermalinkBase = strings.TrimSuffix(rel, f.MediaType.FullSuffix())
+ p.relTargetPathBase = strings.TrimSuffix(target, f.MediaType.FullSuffix())
p.relPermalink = p.s.PathSpec.PrependBasePath(rel)
p.layoutDescriptor = p.createLayoutDescriptor()
return nil
@@ -267,7 +268,7 @@ func createTargetPath(d targetPathDescriptor) string {
return d.PathSpec.MakePathSanitized(pagePath)
}
-func (p *Page) createRelativePermalink() string {
+func (p *Page) createRelativeTargetPath() string {
if len(p.outputFormats) == 0 {
if p.Kind == kindUnknown {
@@ -279,11 +280,15 @@ func (p *Page) createRelativePermalink() string {
// Choose the main output format. In most cases, this will be HTML.
f := p.outputFormats[0]
- return p.createRelativePermalinkForOutputFormat(f)
+ return p.createRelativeTargetPathForOutputFormat(f)
}
func (p *Page) createRelativePermalinkForOutputFormat(f output.Format) string {
+ return p.s.PathSpec.URLizeFilename(p.createRelativeTargetPathForOutputFormat(f))
+}
+
+func (p *Page) createRelativeTargetPathForOutputFormat(f output.Format) string {
tp, err := p.createTargetPath(f, p.s.owner.IsMultihost())
if err != nil {
@@ -296,7 +301,7 @@ func (p *Page) createRelativePermalinkForOutputFormat(f output.Format) string {
tp = strings.TrimSuffix(tp, f.BaseFilename())
}
- return p.s.PathSpec.URLizeFilename(tp)
+ return tp
}
func (p *Page) TargetPath() (outfile string) {