aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-02-24 07:23:10 +0100
committerBjørn Erik Pedersen <[email protected]>2023-02-24 10:40:06 +0100
commit271318ad787ee2442c6d553edffaa29e1d9a4cf7 (patch)
tree4314daa1667ecb7badff421a5c19e51f5ea7bc4f /resources
parente442a63bb7659d95aec2d48bf954cd9d61163559 (diff)
downloadhugo-271318ad787ee2442c6d553edffaa29e1d9a4cf7.tar.gz
hugo-271318ad787ee2442c6d553edffaa29e1d9a4cf7.zip
Split parse and render for Goldmark
This also speeds up situations where you only need the fragments/toc and not the rendered content, e.g. Related with fragments type indexing: ```bash name old time/op new time/op delta RelatedSite-10 12.3ms ± 2% 10.7ms ± 1% -12.95% (p=0.029 n=4+4) name old alloc/op new alloc/op delta RelatedSite-10 38.6MB ± 0% 38.2MB ± 0% -1.08% (p=0.029 n=4+4) name old allocs/op new allocs/op delta RelatedSite-10 117k ± 0% 115k ± 0% -1.36% (p=0.029 n=4+4) ``` Fixes #10750
Diffstat (limited to 'resources')
-rw-r--r--resources/page/page.go8
-rw-r--r--resources/page/page_lazy_contentprovider.go13
-rw-r--r--resources/page/page_nop.go9
3 files changed, 25 insertions, 5 deletions
diff --git a/resources/page/page.go b/resources/page/page.go
index 00e716e83..84153b8c6 100644
--- a/resources/page/page.go
+++ b/resources/page/page.go
@@ -109,9 +109,13 @@ type ContentProvider interface {
// ContentRenderer provides the content rendering methods for some content.
type ContentRenderer interface {
- // RenderContent renders the given content.
+ // ParseAndRenderContent renders the given content.
// For internal use only.
- RenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.Result, error)
+ ParseAndRenderContent(ctx context.Context, content []byte, enableTOC bool) (converter.ResultRender, error)
+ // For internal use only.
+ ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error)
+ // For internal use only.
+ RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error)
}
// FileProvider provides the source file.
diff --git a/resources/page/page_lazy_contentprovider.go b/resources/page/page_lazy_contentprovider.go
index e497718f9..d944b66d3 100644
--- a/resources/page/page_lazy_contentprovider.go
+++ b/resources/page/page_lazy_contentprovider.go
@@ -133,7 +133,16 @@ func (lcp *LazyContentProvider) TableOfContents(ctx context.Context) template.HT
return lcp.cp.TableOfContents(ctx)
}
-func (lcp *LazyContentProvider) RenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.Result, error) {
+func (lcp *LazyContentProvider) ParseAndRenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.ResultRender, error) {
lcp.init.Do(ctx)
- return lcp.cp.RenderContent(ctx, content, renderTOC)
+ return lcp.cp.ParseAndRenderContent(ctx, content, renderTOC)
+}
+
+func (lcp *LazyContentProvider) ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error) {
+ lcp.init.Do(ctx)
+ return lcp.cp.ParseContent(ctx, content)
+}
+func (lcp *LazyContentProvider) RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error) {
+ lcp.init.Do(ctx)
+ return lcp.cp.RenderContent(ctx, content, doc)
}
diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go
index 8946926a2..c04c019fe 100644
--- a/resources/page/page_nop.go
+++ b/resources/page/page_nop.go
@@ -538,7 +538,14 @@ func (p *nopPage) HeadingsFiltered(context.Context) tableofcontents.Headings {
type nopContentRenderer int
-func (r *nopContentRenderer) RenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.Result, error) {
+func (r *nopContentRenderer) ParseAndRenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.ResultRender, error) {
b := &bytes.Buffer{}
return b, nil
}
+
+func (r *nopContentRenderer) ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error) {
+ return nil, false, nil
+}
+func (r *nopContentRenderer) RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error) {
+ return nil, false, nil
+}