Incorporate `relative_url` filter in `link` tag (#6727)
Merge pull request 6727
This commit is contained in:
parent
1825813c93
commit
d926ebf688
|
@ -38,8 +38,8 @@ Feature: Link 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=\"/about.html\">About my projects</a></p>" in "_site/index.html"
|
||||
And I should see "<p><a href=\"/\">Home</a></p>" in "_site/about.html"
|
||||
And I should see "<p><a href=\"/blog/about.html\">About my projects</a></p>" in "_site/index.html"
|
||||
And I should see "<p><a href=\"/blog/\">Home</a></p>" in "_site/about.html"
|
||||
|
||||
Scenario: Basic site with two pages and custom baseurl and permalinks
|
||||
Given I have an "index.md" page that contains "[About my projects]({% link about.md %})"
|
||||
|
@ -52,8 +52,8 @@ Feature: Link 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=\"/about/\">About my projects</a></p>" in "_site/index.html"
|
||||
And I should see "<p><a href=\"/\">Home</a></p>" in "_site/about/index.html"
|
||||
And I should see "<p><a href=\"/blog/about/\">About my projects</a></p>" in "_site/index.html"
|
||||
And I should see "<p><a href=\"/blog/\">Home</a></p>" in "_site/about/index.html"
|
||||
|
||||
Scenario: Linking to a ghost file
|
||||
Given I have an "index.md" page that contains "[About my projects]({% link about.md %})"
|
||||
|
|
|
@ -30,6 +30,15 @@ Gem::Specification.new do |s|
|
|||
s.rdoc_options = ["--charset=UTF-8"]
|
||||
s.extra_rdoc_files = %w(README.markdown LICENSE)
|
||||
|
||||
s.post_install_message = <<~MSG
|
||||
----------------------------------------------------------------------------------
|
||||
This version of Jekyll comes with some major changes. Most notably:
|
||||
* Our `link` tag now comes with the `relative_url` filter incorporated into it.
|
||||
You should no longer prepend `{{ site.baseurl }}` to `{% link foo.md %}`
|
||||
For further details: https://github.com/jekyll/jekyll/pull/6727
|
||||
----------------------------------------------------------------------------------
|
||||
MSG
|
||||
|
||||
s.add_runtime_dependency("addressable", "~> 2.4")
|
||||
s.add_runtime_dependency("colorator", "~> 1.0")
|
||||
s.add_runtime_dependency("em-websocket", "~> 0.5")
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
module Jekyll
|
||||
module Tags
|
||||
class Link < Liquid::Tag
|
||||
include Jekyll::Filters::URLFilters
|
||||
|
||||
class << self
|
||||
def tag_name
|
||||
name.split("::").last.downcase
|
||||
|
@ -16,13 +18,14 @@ module Jekyll
|
|||
end
|
||||
|
||||
def render(context)
|
||||
@context = context
|
||||
site = context.registers[:site]
|
||||
relative_path = Liquid::Template.parse(@relative_path).render(context)
|
||||
|
||||
site.each_site_file do |item|
|
||||
return item.url if item.relative_path == relative_path
|
||||
return relative_url(item) if item.relative_path == relative_path
|
||||
# This takes care of the case for static files that have a leading /
|
||||
return item.url if item.relative_path == "/#{relative_path}"
|
||||
return relative_url(item) if item.relative_path == "/#{relative_path}"
|
||||
end
|
||||
|
||||
raise ArgumentError, <<~MSG
|
||||
|
|
Loading…
Reference in New Issue