mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
hugolib: Fix reloading corner cases for shortcodes
This commit fixes two different, but related issues: 1) Live-reload when a new shortcode was defined in the content file before the shortcode itself was created. 2) Live-reload when a newly defined shortcode changed its "inner content" status. This commit also improves the shortcode related error messages to include the full path to the content file in question. Fixes #3156
This commit is contained in:
@@ -557,7 +557,7 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
|
||||
tmplChanged := []fsnotify.Event{}
|
||||
dataChanged := []fsnotify.Event{}
|
||||
i18nChanged := []fsnotify.Event{}
|
||||
|
||||
shortcodesChanged := make(map[string]bool)
|
||||
// prevent spamming the log on changes
|
||||
logger := helpers.NewDistinctFeedbackLogger()
|
||||
|
||||
@@ -569,6 +569,13 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
|
||||
if s.isLayoutDirEvent(ev) {
|
||||
logger.Println("Template changed", ev.Name)
|
||||
tmplChanged = append(tmplChanged, ev)
|
||||
|
||||
if strings.Contains(ev.Name, "shortcodes") {
|
||||
clearIsInnerShortcodeCache()
|
||||
shortcode := filepath.Base(ev.Name)
|
||||
shortcode = strings.TrimSuffix(shortcode, filepath.Ext(shortcode))
|
||||
shortcodesChanged[shortcode] = true
|
||||
}
|
||||
}
|
||||
if s.isDataDirEvent(ev) {
|
||||
logger.Println("Data changed", ev.Name)
|
||||
@@ -681,6 +688,20 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
|
||||
|
||||
}
|
||||
|
||||
for shortcode, _ := range shortcodesChanged {
|
||||
// There are certain scenarios that, when a shortcode changes,
|
||||
// it isn't sufficient to just rerender the already parsed shortcode.
|
||||
// One example is if the user adds a new shortcode to the content file first,
|
||||
// and then creates the shortcode on the file system.
|
||||
// To handle these scenarios, we must do a full reprocessing of the
|
||||
// pages that keeps a reference to the changed shortcode.
|
||||
pagesWithShortcode := s.findPagesByShortcode(shortcode)
|
||||
for _, p := range pagesWithShortcode {
|
||||
p.rendered = false
|
||||
pageChan <- p
|
||||
}
|
||||
}
|
||||
|
||||
// we close the filechan as we have sent everything we want to send to it.
|
||||
// this will tell the sourceReaders to stop iterating on that channel
|
||||
close(filechan)
|
||||
|
Reference in New Issue
Block a user