@@ -492,12 +492,7 @@ func (h *HugoSites) setupTranslations() {
492492 }
493493}
494494
495- func (s * Site ) preparePagesForRender (outFormatIdx int , cfg * BuildCfg ) {
496-
497- if outFormatIdx > 0 {
498- // TODO(bep) for now
499- return
500- }
495+ func (s * Site ) preparePagesForRender (cfg * BuildCfg ) {
501496
502497 pageChan := make (chan * Page )
503498 wg := & sync.WaitGroup {}
@@ -508,8 +503,16 @@ func (s *Site) preparePagesForRender(outFormatIdx int, cfg *BuildCfg) {
508503 go func (pages <- chan * Page , wg * sync.WaitGroup ) {
509504 defer wg .Done ()
510505 for p := range pages {
506+ if ! p .shouldRenderTo (s .rc .Format ) {
507+ // No need to prepare
508+ continue
509+ }
510+ var shortcodeUpdate bool
511+ if p .shortcodeState != nil {
512+ shortcodeUpdate = p .shortcodeState .updateDelta ()
513+ }
511514
512- if ! cfg .whatChanged .other && p .rendered {
515+ if ! shortcodeUpdate && ! cfg .whatChanged .other && p .rendered {
513516 // No need to process it again.
514517 continue
515518 }
@@ -521,10 +524,12 @@ func (s *Site) preparePagesForRender(outFormatIdx int, cfg *BuildCfg) {
521524 // Mark it as rendered
522525 p .rendered = true
523526
524- // If in watch mode, we need to keep the original so we can
525- // repeat this process on rebuild.
527+ // If in watch mode or if we have multiple output formats,
528+ // we need to keep the original so we can
529+ // potentially repeat this process on rebuild.
530+ needsACopy := cfg .Watching || len (p .outputFormats ) > 1
526531 var workContentCopy []byte
527- if cfg . Watching {
532+ if needsACopy {
528533 workContentCopy = make ([]byte , len (p .workContent ))
529534 copy (workContentCopy , p .workContent )
530535 } else {
@@ -589,15 +594,15 @@ func (h *HugoSites) Pages() Pages {
589594}
590595
591596func handleShortcodes (p * Page , rawContentCopy []byte ) ([]byte , error ) {
592- if p .shortcodeState != nil && len (p .shortcodeState .contentShortCodes ) > 0 {
593- p .s .Log .DEBUG .Printf ("Replace %d shortcodes in %q" , len (p .shortcodeState .contentShortCodes ), p .BaseFileName ())
594- shortcodes , err := executeShortcodeFuncMap ( p .shortcodeState .contentShortCodes )
597+ if p .shortcodeState != nil && len (p .shortcodeState .contentShortcodes ) > 0 {
598+ p .s .Log .DEBUG .Printf ("Replace %d shortcodes in %q" , len (p .shortcodeState .contentShortcodes ), p .BaseFileName ())
599+ err := p .shortcodeState .executeShortcodesForDelta ( p )
595600
596601 if err != nil {
597602 return rawContentCopy , err
598603 }
599604
600- rawContentCopy , err = replaceShortcodeTokens (rawContentCopy , shortcodePlaceholderPrefix , shortcodes )
605+ rawContentCopy , err = replaceShortcodeTokens (rawContentCopy , shortcodePlaceholderPrefix , p . shortcodeState . renderedShortcodes )
601606
602607 if err != nil {
603608 p .s .Log .FATAL .Printf ("Failed to replace shortcode tokens in %s:\n %s" , p .BaseFileName (), err .Error ())
0 commit comments