Incorporate `relative_url` within `post_url` tag (#7589)

Merge pull request 7589
This commit is contained in:
Ashwin Maroli 2019-03-29 12:24:45 +05:30 committed by jekyllbot
parent c985dc5899
commit 2591f33aa8
5 changed files with 41 additions and 6 deletions

View File

@ -22,6 +22,25 @@ and fetch the latest version of Jekyll:
gem update jekyll
```
<div class="note warning">
<h5><code>post_url</code> Tag and Baseurl</h5>
<p>&nbsp;</p>
<p>
The <code>post_url</code> tag now incorporates the <code>relative_url</code> filter within itself
and therefore automatically prepends your site's <code>baseurl</code> to the post's <code>url</code>
value.
</p>
<p>
Please ensure that you change all instances of the <code>post_url</code> usage as following:
</p>
{% highlight diff %}
- {{ site.baseurl }}/{% post_url 2018-03-20-hello-world.markdown %}
+ {% post_url 2018-03-20-hello-world.markdown %}
{% endhighlight %}
</div>
## Template rendering
We've slightly altered the way Jekyll parses and renders your various templates

View File

@ -708,6 +708,15 @@ h5 > code,
0 -1px 0 rgba(0,0,0,.5));
}
.note .highlight {
width: 94%;
pre code {
font-size: 0.9em;
background-color: transparent;
box-shadow: none;
}
}
.note code {
background-color: #333;
background-color: rgba(0,0,0,0.2);

View File

@ -71,7 +71,7 @@ Feature: PostUrl Tag
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "<p><a href=\"/2019/02/04/hello-world.html\">Welcome</a></p>" in "_site/index.html"
And I should see "<p><a href=\"/blog/2019/02/04/hello-world.html\">Welcome</a></p>" in "_site/index.html"
Scenario: Posts with categories
Given I have a _posts directory

View File

@ -56,6 +56,10 @@ Gem::Specification.new do |s|
You should no longer prepend `{{ site.baseurl }}` to `{% link foo.md %}`
For further details: https://github.com/jekyll/jekyll/pull/6727
* Our `post_url` tag now comes with the `relative_url` filter incorporated into it.
You shouldn't prepend `{{ site.baseurl }}` to `{% post_url 2019-03-27-hello %}`
For further details: https://github.com/jekyll/jekyll/pull/7589
* Our `highlight` tag no longer parses Liquid and Liquid-like constructs in the
tag's content body. While this means you no longer need to enclose the content
within a `{% raw %}{% endraw %}` block, it also means that you can no longer

View File

@ -57,6 +57,8 @@ module Jekyll
end
class PostUrl < Liquid::Tag
include Jekyll::Filters::URLFilters
def initialize(tag_name, post, tokens)
super
@orig_post = post.strip
@ -72,24 +74,25 @@ module Jekyll
end
def render(context)
@context = context
site = context.registers[:site]
site.posts.docs.each do |p|
return p.url if @post == p
site.posts.docs.each do |document|
return relative_url(document) if @post == document
end
# New matching method did not match, fall back to old method
# with deprecation warning if this matches
site.posts.docs.each do |p|
next unless @post.deprecated_equality p
site.posts.docs.each do |document|
next unless @post.deprecated_equality document
Jekyll::Deprecator.deprecation_message "A call to "\
"'{% post_url #{@post.name} %}' did not match " \
"a post using the new matching method of checking name " \
"(path-date-slug) equality. Please make sure that you " \
"change this tag to match the post's name exactly."
return p.url
return relative_url(document)
end
raise Jekyll::Errors::PostURLError, <<~MSG