mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Compare commits
6 Commits
debug-7328
...
johnkhughe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af867f66a3 | ||
|
|
798da59313 | ||
|
|
eeba201bf8 | ||
|
|
965d1fed1c | ||
|
|
34c0de6944 | ||
|
|
a4ec1c89a2 |
@@ -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:
|
||||
|
||||
@@ -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 => []
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user