diff --git a/.gitignore b/.gitignore index 55438af..2da8a04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /_site /tmp /spec/examples.txt +vendor/bundle +.bundle /Gemfile.lock *.gem spec/fixtures/site/.jekyll-cache/ \ No newline at end of file diff --git a/lib/jekyll-relative-links/generator.rb b/lib/jekyll-relative-links/generator.rb index d4b3f00..bf4ece6 100644 --- a/lib/jekyll-relative-links/generator.rb +++ b/lib/jekyll-relative-links/generator.rb @@ -60,6 +60,8 @@ def replace_relative_links!(document) link.path = url replacement_text(link) end + + replace_relative_links_excerpt!(document) rescue ArgumentError => e raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8") end @@ -165,5 +167,9 @@ def excluded?(document) def global_entry_filter @global_entry_filter ||= Jekyll::EntryFilter.new(site) end + + def replace_relative_links_excerpt!(document) + document.data["excerpt"] = Jekyll::Excerpt.new(document) if document.data["excerpt"] + end end end diff --git a/spec/fixtures/site/_posts/2016-01-01-test.md b/spec/fixtures/site/_posts/2016-01-01-test.md index 59f76f8..a24b30e 100644 --- a/spec/fixtures/site/_posts/2016-01-01-test.md +++ b/spec/fixtures/site/_posts/2016-01-01-test.md @@ -1,10 +1,13 @@ --- +excerpt_separator: --- # Some post [Another Page](../another-page.md) + + [Page with permalink](../page-with-permalink.md) [Reference link][reference] diff --git a/spec/fixtures/site/subdir/_posts/2016-01-01-test.md b/spec/fixtures/site/subdir/_posts/2016-01-01-test.md index 8428b4d..1cf761e 100644 --- a/spec/fixtures/site/subdir/_posts/2016-01-01-test.md +++ b/spec/fixtures/site/subdir/_posts/2016-01-01-test.md @@ -1,4 +1,5 @@ --- +excerpt_separator: --- # Some post @@ -6,3 +7,7 @@ [Another Page](../../another-page.md) [Another Post](../../_posts/2016-01-01-test.md) + + + +Foobar \ No newline at end of file diff --git a/spec/jekyll-relative-links/generator_spec.rb b/spec/jekyll-relative-links/generator_spec.rb index 02fd985..b2eba10 100644 --- a/spec/jekyll-relative-links/generator_spec.rb +++ b/spec/jekyll-relative-links/generator_spec.rb @@ -233,7 +233,11 @@ expect(post.content).to include("[Another Page](/another-page.html)") end - it "converts relative links with permalinks from posts pages " do + it "converts relative links from posts to pages in the excerpt" do + expect(post.excerpt.content).to include("[Another Page](/another-page.html)") + end + + it "converts relative links with permalinks from posts to pages " do expect(post.content).to include("[Page with permalink](/page-with-permalink/)") end @@ -263,6 +267,10 @@ it "converts relative links from posts to posts" do expect(subdir_post.content).to include("[Another Post](/2016/01/01/test.html)") end + + it "converts relative links from posts to posts in the excerpt" do + expect(subdir_post.excerpt.content).to include("[Another Post](/2016/01/01/test.html)") + end end context "items (with output)" do