Support open "current content page" in browser

This commit adds a new `--navigateToChanged` and config setting with the same name, that, when running the Hugo server with live reload enabled, will navigate to the current content file's URL on save. 

This is really useful for site-wide content changes (copyedits etc.).
Fixes #3643
This commit is contained in:
Bjørn Erik Pedersen
2017-06-26 21:34:16 +02:00
committed by GitHub
parent 7198ea8a1e
commit c825a73121
5 changed files with 114 additions and 6 deletions

View File

@@ -19,6 +19,8 @@ import (
"strings"
"sync"
"path/filepath"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
@@ -38,6 +40,27 @@ type HugoSites struct {
*deps.Deps
}
// GetContentPage finds a Page with content given the absolute filename.
// Returns nil if none found.
func (h *HugoSites) GetContentPage(filename string) *Page {
s := h.Sites[0]
contendDir := filepath.Join(s.PathSpec.AbsPathify(s.Cfg.GetString("contentDir")))
if !strings.HasPrefix(filename, contendDir) {
return nil
}
rel := strings.TrimPrefix(filename, contendDir)
rel = strings.TrimPrefix(rel, helpers.FilePathSeparator)
pos := s.rawAllPages.findPagePosByFilePath(rel)
if pos == -1 {
return nil
}
return s.rawAllPages[pos]
}
// NewHugoSites creates a new collection of sites given the input sites, building
// a language configuration based on those.
func newHugoSites(cfg deps.DepsCfg, sites ...*Site) (*HugoSites, error) {