Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate relative_url within post_url tag #7589

Merged
merged 2 commits into from Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/_docs/upgrading/3-to-4.md
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/_sass/_style.scss
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion features/post_url_tag.feature
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions jekyll.gemspec
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions lib/jekyll/tags/post_url.rb
Expand Up @@ -57,6 +57,8 @@ def post_slug(other)
end

class PostUrl < Liquid::Tag
include Jekyll::Filters::URLFilters

def initialize(tag_name, post, tokens)
super
@orig_post = post.strip
Expand All @@ -72,24 +74,25 @@ def initialize(tag_name, post, tokens)
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
Expand Down