mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
Fix handling of HTML files without front matter
This means that any HTML file inside /content will be treated as a regular file. If you want it processes with shortcodes and a layout, add front matter. The defintion of an HTML file here is: * File with extension .htm or .html * With first non-whitespace character "<" that isn't a HTML comment. This is in line with the documentation. Fixes #7030 Fixes #7028 See #6789
This commit is contained in:
parent
8279d2e227
commit
ffcb4aeb8e
18 changed files with 168 additions and 309 deletions
|
@ -122,93 +122,84 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
|
|||
|
||||
isHTML := cp.p.m.markup == "html"
|
||||
|
||||
if p.renderable {
|
||||
if !isHTML {
|
||||
r, err := cp.renderContent(cp.workContent, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cp.workContent = r.Bytes()
|
||||
|
||||
if tocProvider, ok := r.(converter.TableOfContentsProvider); ok {
|
||||
cfg := p.s.ContentSpec.Converters.GetMarkupConfig()
|
||||
cp.tableOfContents = template.HTML(
|
||||
tocProvider.TableOfContents().ToHTML(
|
||||
cfg.TableOfContents.StartLevel,
|
||||
cfg.TableOfContents.EndLevel,
|
||||
cfg.TableOfContents.Ordered,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
tmpContent, tmpTableOfContents := helpers.ExtractTOC(cp.workContent)
|
||||
cp.tableOfContents = helpers.BytesToHTML(tmpTableOfContents)
|
||||
cp.workContent = tmpContent
|
||||
}
|
||||
if !isHTML {
|
||||
r, err := cp.renderContent(cp.workContent, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cp.placeholdersEnabled {
|
||||
// ToC was accessed via .Page.TableOfContents in the shortcode,
|
||||
// at a time when the ToC wasn't ready.
|
||||
cp.contentPlaceholders[tocShortcodePlaceholder] = string(cp.tableOfContents)
|
||||
cp.workContent = r.Bytes()
|
||||
|
||||
if tocProvider, ok := r.(converter.TableOfContentsProvider); ok {
|
||||
cfg := p.s.ContentSpec.Converters.GetMarkupConfig()
|
||||
cp.tableOfContents = template.HTML(
|
||||
tocProvider.TableOfContents().ToHTML(
|
||||
cfg.TableOfContents.StartLevel,
|
||||
cfg.TableOfContents.EndLevel,
|
||||
cfg.TableOfContents.Ordered,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
tmpContent, tmpTableOfContents := helpers.ExtractTOC(cp.workContent)
|
||||
cp.tableOfContents = helpers.BytesToHTML(tmpTableOfContents)
|
||||
cp.workContent = tmpContent
|
||||
}
|
||||
|
||||
if p.cmap.hasNonMarkdownShortcode || cp.placeholdersEnabled {
|
||||
// There are one or more replacement tokens to be replaced.
|
||||
cp.workContent, err = replaceShortcodeTokens(cp.workContent, cp.contentPlaceholders)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cp.p.source.hasSummaryDivider {
|
||||
if isHTML {
|
||||
src := p.source.parsed.Input()
|
||||
|
||||
// Use the summary sections as they are provided by the user.
|
||||
if p.source.posSummaryEnd != -1 {
|
||||
cp.summary = helpers.BytesToHTML(src[p.source.posMainContent:p.source.posSummaryEnd])
|
||||
}
|
||||
|
||||
if cp.p.source.posBodyStart != -1 {
|
||||
cp.workContent = src[cp.p.source.posBodyStart:]
|
||||
}
|
||||
|
||||
} else {
|
||||
summary, content, err := splitUserDefinedSummaryAndContent(cp.p.m.markup, cp.workContent)
|
||||
if err != nil {
|
||||
cp.p.s.Log.ERROR.Printf("Failed to set user defined summary for page %q: %s", cp.p.pathOrTitle(), err)
|
||||
} else {
|
||||
cp.workContent = content
|
||||
cp.summary = helpers.BytesToHTML(summary)
|
||||
}
|
||||
}
|
||||
} else if cp.p.m.summary != "" {
|
||||
b, err := cp.renderContent([]byte(cp.p.m.summary), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
html := cp.p.s.ContentSpec.TrimShortHTML(b.Bytes())
|
||||
cp.summary = helpers.BytesToHTML(html)
|
||||
}
|
||||
|
||||
cp.content = helpers.BytesToHTML(cp.workContent)
|
||||
|
||||
}
|
||||
|
||||
if !p.renderable {
|
||||
err := cp.addSelfTemplate()
|
||||
return err
|
||||
if cp.placeholdersEnabled {
|
||||
// ToC was accessed via .Page.TableOfContents in the shortcode,
|
||||
// at a time when the ToC wasn't ready.
|
||||
cp.contentPlaceholders[tocShortcodePlaceholder] = string(cp.tableOfContents)
|
||||
}
|
||||
|
||||
if p.cmap.hasNonMarkdownShortcode || cp.placeholdersEnabled {
|
||||
// There are one or more replacement tokens to be replaced.
|
||||
cp.workContent, err = replaceShortcodeTokens(cp.workContent, cp.contentPlaceholders)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cp.p.source.hasSummaryDivider {
|
||||
if isHTML {
|
||||
src := p.source.parsed.Input()
|
||||
|
||||
// Use the summary sections as they are provided by the user.
|
||||
if p.source.posSummaryEnd != -1 {
|
||||
cp.summary = helpers.BytesToHTML(src[p.source.posMainContent:p.source.posSummaryEnd])
|
||||
}
|
||||
|
||||
if cp.p.source.posBodyStart != -1 {
|
||||
cp.workContent = src[cp.p.source.posBodyStart:]
|
||||
}
|
||||
|
||||
} else {
|
||||
summary, content, err := splitUserDefinedSummaryAndContent(cp.p.m.markup, cp.workContent)
|
||||
if err != nil {
|
||||
cp.p.s.Log.ERROR.Printf("Failed to set user defined summary for page %q: %s", cp.p.pathOrTitle(), err)
|
||||
} else {
|
||||
cp.workContent = content
|
||||
cp.summary = helpers.BytesToHTML(summary)
|
||||
}
|
||||
}
|
||||
} else if cp.p.m.summary != "" {
|
||||
b, err := cp.renderContent([]byte(cp.p.m.summary), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
html := cp.p.s.ContentSpec.TrimShortHTML(b.Bytes())
|
||||
cp.summary = helpers.BytesToHTML(html)
|
||||
}
|
||||
|
||||
cp.content = helpers.BytesToHTML(cp.workContent)
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// Recursive loops can only happen in content files with template code (shortcodes etc.)
|
||||
// Avoid creating new goroutines if we don't have to.
|
||||
needTimeout := !p.renderable || p.shortcodeState.hasShortcodes()
|
||||
needTimeout = needTimeout || cp.renderHooks != nil
|
||||
needTimeout := p.shortcodeState.hasShortcodes() || cp.renderHooks != nil
|
||||
|
||||
if needTimeout {
|
||||
cp.initMain = parent.BranchWithTimeout(p.s.siteCfg.timeout, func(ctx context.Context) (interface{}, error) {
|
||||
|
@ -428,15 +419,6 @@ func (p *pageContentOutput) setWordCounts(isCJKLanguage bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *pageContentOutput) addSelfTemplate() error {
|
||||
self := p.p.selfLayoutForOutput(p.f)
|
||||
err := p.p.s.Tmpl().(tpl.TemplateManager).AddLateTemplate(self, string(p.workContent))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A callback to signal that we have inserted a placeholder into the rendered
|
||||
// content. This avoids doing extra replacement work.
|
||||
func (p *pageContentOutput) enablePlaceholders() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue