aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-03-17 11:12:33 +0100
committerBjørn Erik Pedersen <[email protected]>2024-05-14 13:12:08 +0200
commite2d66e3218e180bbfca06ca3a29ce01957c513e9 (patch)
treeed29bb99cf16b75b6334e2fc618d31e80203e5d5 /helpers
parent55dea41c1ab703f13b841389c6888815a033cf86 (diff)
downloadhugo-e2d66e3218e180bbfca06ca3a29ce01957c513e9.tar.gz
hugo-e2d66e3218e180bbfca06ca3a29ce01957c513e9.zip
Create pages from _content.gotmpl
Closes #12427 Closes #12485 Closes #6310 Closes #5074
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go23
-rw-r--r--helpers/content_test.go2
-rw-r--r--helpers/general_test.go6
3 files changed, 14 insertions, 17 deletions
diff --git a/helpers/content.go b/helpers/content.go
index be79ad540..49283d526 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -26,6 +26,7 @@ import (
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
+ "github.com/gohugoio/hugo/media"
"github.com/spf13/afero"
@@ -135,20 +136,16 @@ func (c *ContentSpec) SanitizeAnchorName(s string) string {
}
func (c *ContentSpec) ResolveMarkup(in string) string {
- if c == nil {
- panic("nil ContentSpec")
- }
in = strings.ToLower(in)
- switch in {
- case "md", "markdown", "mdown":
- return "markdown"
- case "html", "htm":
- return "html"
- default:
- if conv := c.Converters.Get(in); conv != nil {
- return conv.Name()
- }
+
+ if mediaType, found := c.Cfg.ContentTypes().(media.ContentTypes).Types().GetBestMatch(markup.ResolveMarkup(in)); found {
+ return mediaType.SubType
}
+
+ if conv := c.Converters.Get(in); conv != nil {
+ return markup.ResolveMarkup(conv.Name())
+ }
+
return ""
}
@@ -244,7 +241,7 @@ func (c *ContentSpec) TrimShortHTML(input []byte, markup string) []byte {
openingTag := []byte("<p>")
closingTag := []byte("</p>")
- if markup == "asciidocext" {
+ if markup == media.DefaultContentTypes.AsciiDoc.SubType {
openingTag = []byte("<div class=\"paragraph\">\n<p>")
closingTag = []byte("</p>\n</div>")
}
diff --git a/helpers/content_test.go b/helpers/content_test.go
index f1cbfad04..22d468191 100644
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -41,7 +41,7 @@ func TestTrimShortHTML(t *testing.T) {
{"markdown", []byte("<h2 id=`a`>b</h2>\n\n<p>c</p>"), []byte("<h2 id=`a`>b</h2>\n\n<p>c</p>")},
// Issue 12369
{"markdown", []byte("<div class=\"paragraph\">\n<p>foo</p>\n</div>"), []byte("<div class=\"paragraph\">\n<p>foo</p>\n</div>")},
- {"asciidocext", []byte("<div class=\"paragraph\">\n<p>foo</p>\n</div>"), []byte("foo")},
+ {"asciidoc", []byte("<div class=\"paragraph\">\n<p>foo</p>\n</div>"), []byte("foo")},
}
c := newTestContentSpec(nil)
diff --git a/helpers/general_test.go b/helpers/general_test.go
index 54607d699..7bef1b776 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -35,9 +35,9 @@ func TestResolveMarkup(t *testing.T) {
{"md", "markdown"},
{"markdown", "markdown"},
{"mdown", "markdown"},
- {"asciidocext", "asciidocext"},
- {"adoc", "asciidocext"},
- {"ad", "asciidocext"},
+ {"asciidocext", "asciidoc"},
+ {"adoc", "asciidoc"},
+ {"ad", "asciidoc"},
{"rst", "rst"},
{"pandoc", "pandoc"},
{"pdc", "pandoc"},