From d926ebf6880b2fe4022fb49d58a8d52805ffe051 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 5 Nov 2018 00:33:18 +0530 Subject: [PATCH] Incorporate `relative_url` filter in `link` tag (#6727) Merge pull request 6727 --- features/link_tag.feature | 8 ++++---- jekyll.gemspec | 9 +++++++++ lib/jekyll/tags/link.rb | 7 +++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/features/link_tag.feature b/features/link_tag.feature index a94b8676..3ea8cf64 100644 --- a/features/link_tag.feature +++ b/features/link_tag.feature @@ -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 "

About my projects

" in "_site/index.html" - And I should see "

Home

" in "_site/about.html" + And I should see "

About my projects

" in "_site/index.html" + And I should see "

Home

" 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 "

About my projects

" in "_site/index.html" - And I should see "

Home

" in "_site/about/index.html" + And I should see "

About my projects

" in "_site/index.html" + And I should see "

Home

" 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 %})" diff --git a/jekyll.gemspec b/jekyll.gemspec index 76f92f41..3d4a2d7b 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -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") diff --git a/lib/jekyll/tags/link.rb b/lib/jekyll/tags/link.rb index b8496a0a..85411e4d 100644 --- a/lib/jekyll/tags/link.rb +++ b/lib/jekyll/tags/link.rb @@ -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