Skip to content

Commit

Permalink
hugolib: Correctly identify "my_index_page.md"
Browse files Browse the repository at this point in the history
The above example was earlier identified as a section page and not a regular page.

Fixes gohugoio#3234
  • Loading branch information
bep committed Mar 25, 2017
1 parent d07ff9d commit abe6408
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hugolib/page.go
Expand Up @@ -1859,8 +1859,15 @@ func sectionsFromFilename(filename string) []string {
return sections
}

const (
regularPageFileNameDoesNotStartWith = "_index"

// There can be "my_regular_index_page.md but not /_index_file.md
regularPageFileNameDoesNotContain = helpers.FilePathSeparator + regularPageFileNameDoesNotStartWith
)

func kindFromFilename(filename string) string {
if !strings.Contains(filename, "_index") {
if !strings.HasPrefix(filename, regularPageFileNameDoesNotStartWith) && !strings.Contains(filename, regularPageFileNameDoesNotContain) {
return KindPage
}

Expand Down
14 changes: 14 additions & 0 deletions hugolib/site_test.go
Expand Up @@ -201,6 +201,20 @@ func TestLastChange(t *testing.T) {
require.Equal(t, 2017, s.Info.LastChange.Year(), "Site.LastChange should be set to the page with latest Lastmod (year 2017)")
}

// Issue #_index
func TestPageWithUnderScoreIndexInFilename(t *testing.T) {
t.Parallel()

cfg, fs := newTestCfg()

writeSource(t, fs, filepath.Join("content", "sect/my_index_file.md"), "---\ntitle: doc1\nweight: 1\ndate: 2014-05-29\n---\n# doc1\n*some content*")

s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})

require.Len(t, s.RegularPages, 1)

}

// Issue #957
func TestCrossrefs(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit abe6408

Please sign in to comment.