Permalink
Browse files

Incorporate `relative_url` filter in `link` tag (#6727)

Merge pull request 6727
  • Loading branch information...
ashmaroli authored and jekyllbot committed Nov 4, 2018
1 parent 1825813 commit d926ebf6880b2fe4022fb49d58a8d52805ffe051
Showing with 18 additions and 6 deletions.
  1. +4 −4 features/link_tag.feature
  2. +9 −0 jekyll.gemspec
  3. +5 −2 lib/jekyll/tags/link.rb
@@ -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 %})"
View
@@ -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")
View
@@ -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 @@ def initialize(tag_name, relative_path, tokens)
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

0 comments on commit d926ebf

Please sign in to comment.