Skip to content

Commit

Permalink
Fix the "page picker" logic in --navigateToChanged
Browse files Browse the repository at this point in the history
Fixes #9051
  • Loading branch information
bep committed Oct 18, 2021
1 parent ba35e69 commit 096f5e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 11 additions & 5 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"syscall"
"time"

"github.com/gohugoio/hugo/hugofs/files"

"github.com/gohugoio/hugo/common/types"

"github.com/gohugoio/hugo/hugofs"
Expand Down Expand Up @@ -1200,12 +1202,16 @@ func partitionDynamicEvents(sourceFs *filesystems.SourceFilesystems, events []fs
func pickOneWriteOrCreatePath(events []fsnotify.Event) string {
name := ""

// Some editors (for example notepad.exe on Windows) triggers a change
// both for directory and file. So we pick the longest path, which should
// be the file itself.
for _, ev := range events {
if (ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create) && len(ev.Name) > len(name) {
name = ev.Name
if ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create {
if files.IsIndexContentFile(ev.Name) {
return ev.Name
}

if files.IsContentFile(ev.Name) {
name = ev.Name
}

}
}

Expand Down
10 changes: 10 additions & 0 deletions hugofs/files/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func IsContentFile(filename string) bool {
return contentFileExtensionsSet[strings.TrimPrefix(filepath.Ext(filename), ".")]
}

func IsIndexContentFile(filename string) bool {
if !IsContentFile(filename) {
return false
}

base := filepath.Base(filename)

return strings.HasPrefix(base, "index.") || strings.HasPrefix(base, "_index.")
}

func IsHTMLFile(filename string) bool {
return htmlFileExtensionsSet[strings.TrimPrefix(filepath.Ext(filename), ".")]
}
Expand Down

0 comments on commit 096f5e1

Please sign in to comment.