Compare commits

...

6 Commits

Author SHA1 Message Date
John Hughes
af867f66a3 Add post_covert tests 2016-07-26 12:10:51 -07:00
John Hughes
798da59313 Rename post convert hook in lib/jekyll/hooks.rb 2016-07-26 12:10:51 -07:00
John Hughes
eeba201bf8 Rename post convert hook 2016-07-26 12:09:44 -07:00
John Hughes
965d1fed1c Add rendered content hook to documentation 2016-07-26 12:09:44 -07:00
John Hughes
34c0de6944 Rename rendered content hook 2016-07-26 12:09:44 -07:00
John Hughes
a4ec1c89a2 Add hook to modify rendered content without layout 2016-07-26 12:08:17 -07:00
4 changed files with 93 additions and 1 deletions

View File

@@ -103,6 +103,32 @@ Feature: Hooks
Then I should see "special" in "_site/page1.html"
And I should not see "special" in "_site/page2.html"
Scenario: Modify the converted HTML content before rendering the page
Given I have a _plugins directory
And I have a "_layouts/page.html" file with the content:
"""
<h3>Page heading</h3>
{{ content }}
"""
And I have a "page.md" page with the content:
"""
---
layout: page
---
### Heading
"""
And I have a "_plugins/ext.rb" file with content:
"""
Jekyll::Hooks.register :pages, :post_convert do |page|
page.content = page.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 "<h3>Page heading</h3>" in "_site/page.html"
And I should see "<h4>Heading</h4>" in "_site/page.html"
Scenario: Modify page contents before writing to disk
Given I have a _plugins directory
And I have a "index.html" page that contains "WRAP ME"
@@ -170,6 +196,32 @@ Feature: Hooks
Then I should see "old post" in "_site/2015/03/14/entry1.html"
And I should see "new post" in "_site/2015/03/15/entry2.html"
Scenario: Modify the converted HTML content before rendering the post
Given I have a _plugins directory
And I have a "_layouts/post.html" file with the content:
"""
<h3>Page heading</h3>
{{ content }}
"""
And I have a "_posts/2016-01-01-example.md" file with the content:
"""
---
layout: post
---
### Heading
"""
And I have a "_plugins/ext.rb" file with content:
"""
Jekyll::Hooks.register :opsts, :post_convert do |post|
post.content = post.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 "<h3>Page heading</h3>" in "_site/2016/01/01/example.html"
And I should see "<h4>Heading</h4>" in "_site/2016/01/01/example.html"
Scenario: Modify post contents before writing to disk
Given I have a _plugins directory
And I have a "_plugins/ext.rb" file with content:

View File

@@ -19,21 +19,24 @@ module Jekyll
:post_render => [],
:post_write => []
},
:pages => {
:pages => {
:post_init => [],
:pre_render => [],
:post_convert => [],
:post_render => [],
:post_write => []
},
:posts => {
:post_init => [],
:pre_render => [],
:post_convert => [],
:post_render => [],
:post_write => []
},
:documents => {
:post_init => [],
:pre_render => [],
:post_convert => [],
:post_render => [],
:post_write => []
}

View File

@@ -66,6 +66,10 @@ module Jekyll
output = convert(output)
document.content = output
# Hook to modify converted content before layout is applied
document.trigger_hooks(:post_convert, output)
output = document.content
if document.place_in_layout?
Jekyll.logger.debug "Rendering Layout:", document.relative_path
place_in_layouts(

View File

@@ -605,6 +605,17 @@ The complete list of available hooks is below:
<p>Just before rendering a page</p>
</td>
</tr>
<tr>
<td>
<p><code>:pages</code></p>
</td>
<td>
<p><code>:post_convert</code></p>
</td>
<td>
<p>After converting the page content, but before rendering the page layout</p>
</td>
</tr>
<tr>
<td>
<p><code>:pages</code></p>
@@ -649,6 +660,17 @@ The complete list of available hooks is below:
<p>Just before rendering a post</p>
</td>
</tr>
<tr>
<td>
<p><code>:posts</code></p>
</td>
<td>
<p><code>:post_convert</code></p>
</td>
<td>
<p>After converting the post content, but before rendering the post layout</p>
</td>
</tr>
<tr>
<td>
<p><code>:posts</code></p>
@@ -693,6 +715,17 @@ The complete list of available hooks is below:
<p>Just before rendering a document</p>
</td>
</tr>
<tr>
<td>
<p><code>:documents</code></p>
</td>
<td>
<p><code>:post_convert</code></p>
</td>
<td>
<p>After converting the document content, but before rendering the document layout</p>
</td>
</tr>
<tr>
<td>
<p><code>:documents</code></p>