Skip to content

Commit

Permalink
Fix page names that contain dot
Browse files Browse the repository at this point in the history
changes:
    - in hugolib/page.go, `func permalink` and `func TargetPath`
      Fixed the attempt to *replace* the extension of something
      that was *already* a basename.
    - in source/file.go, `func NewFile`
      added check for allowed languages before translating filename

Fixes gohugoio#2555
  • Loading branch information
vyuh authored and bep committed Nov 1, 2016
1 parent cda3b36 commit 186db7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (p *Page) permalink() (*url.URL, error) {
permalink = helpers.URLPrep(viper.GetBool("uglyURLs"), path.Join(dir, p.Slug+"."+p.Extension()))
} else {
t := p.Source.TranslationBaseName()
permalink = helpers.URLPrep(viper.GetBool("uglyURLs"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension())))
permalink = helpers.URLPrep(viper.GetBool("uglyURLs"), path.Join(dir, (strings.TrimSpace(t)+"."+p.Extension())))
}
}

Expand Down Expand Up @@ -1163,7 +1163,7 @@ func (p *Page) TargetPath() (outfile string) {
outfile = strings.TrimSpace(p.Slug) + "." + p.Extension()
} else {
// Fall back to filename
outfile = helpers.ReplaceExtension(p.Source.TranslationBaseName(), p.Extension())
outfile = (p.Source.TranslationBaseName() + "." + p.Extension())
}

return p.addLangFilepathPrefix(filepath.Join(strings.ToLower(
Expand Down
9 changes: 6 additions & 3 deletions source/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ func NewFile(relpath string) *File {
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
f.baseName = helpers.Filename(f.LogicalName())

f.lang = strings.TrimPrefix(filepath.Ext(f.baseName), ".")
if f.lang == "" {
lang := strings.TrimPrefix(filepath.Ext(f.baseName), ".")
if _, ok := viper.GetStringMap("languages")[lang]; lang == "" || !ok {
f.lang = viper.GetString("defaultContentLanguage")
f.translationBaseName = f.baseName
} else {
f.lang = lang
f.translationBaseName = helpers.Filename(f.baseName)
}
f.translationBaseName = helpers.Filename(f.baseName)

f.section = helpers.GuessSection(f.Dir())
f.uniqueID = helpers.Md5String(f.LogicalName())
Expand Down

0 comments on commit 186db7c

Please sign in to comment.