From c12a04dbc1aca844ff2b57880381b8497d363466 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 11 Nov 2020 16:06:54 +0530 Subject: [PATCH] Allow triggering `:post_convert` events atomically (#8465) Merge pull request 8465 --- features/hooks.feature | 45 ++++++++++++++++++++++++++++++++++++++++++ lib/jekyll/hooks.rb | 9 +++++---- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/features/hooks.feature b/features/hooks.feature index f8c5f8fa..1deb7f98 100644 --- a/features/hooks.feature +++ b/features/hooks.feature @@ -362,6 +362,51 @@ Feature: Hooks And I should see "

Page heading

" in "_site/memes/doc1.html" And I should see "

all your base

" in "_site/memes/doc1.html" + Scenario: Modify the converted HTML content of document of a particular collection before rendering layout + Given I have a _layouts directory + And I have a "_layouts/meme.html" file with content: + """ +

Page heading

+ {{ content }} + """ + And I have a "_config.yml" file with content: + """ + collections: + memes: + output: true + """ + And I have a _memes directory + And I have a "_memes/doc1.md" file with content: + """ + --- + layout: meme + text: all your base + --- + ### {{ page.text }} + """ + And I have a _posts directory + And I have a "_posts/2016-01-01-example.md" file with content: + """ + --- + layout: meme + text: all your base + --- + ### {{ page.text }} + """ + And I have a _plugins directory + And I have a "_plugins/ext.rb" file with content: + """ + Jekyll::Hooks.register :memes, :post_convert do |document| + document.content = document.content.gsub('h3', 'h4') + end + """ + When I run jekyll build + Then I should get a zero exit status + And the _site directory should exist + And I should see "

Page heading

" in "_site/memes/doc1.html" + And I should see "

all your base

" in "_site/memes/doc1.html" + But I should see "

all your base

" in "_site/2016/01/01/example.html" + Scenario: Update a document after rendering it, but before writing it to disk Given I have a _plugins directory And I have a "_plugins/ext.rb" file with content: diff --git a/lib/jekyll/hooks.rb b/lib/jekyll/hooks.rb index e3ddca8b..efb85269 100644 --- a/lib/jekyll/hooks.rb +++ b/lib/jekyll/hooks.rb @@ -70,10 +70,11 @@ module Jekyll # register a single hook to be called later, internal API def self.register_one(owner, event, priority, &block) @registry[owner] ||= { - :post_init => [], - :pre_render => [], - :post_render => [], - :post_write => [], + :post_init => [], + :pre_render => [], + :post_convert => [], + :post_render => [], + :post_write => [], } unless @registry[owner][event]