Skip to content

Commit

Permalink
Merge pull request #65 from qwtel/pr/53
Browse files Browse the repository at this point in the history
Pr/53
  • Loading branch information
benbalter authored Jul 13, 2020
2 parents ee58af1 + 7324302 commit 4449dba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/_site
/tmp
/spec/examples.txt
vendor/bundle
.bundle
/Gemfile.lock
*.gem
spec/fixtures/site/.jekyll-cache/
6 changes: 6 additions & 0 deletions lib/jekyll-relative-links/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions spec/fixtures/site/_posts/2016-01-01-test.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
excerpt_separator: <!--more-->
---

# Some post

[Another Page](../another-page.md)

<!--more-->

[Page with permalink](../page-with-permalink.md)

[Reference link][reference]
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/site/subdir/_posts/2016-01-01-test.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
excerpt_separator: <!--more-->
---

# Some post

[Another Page](../../another-page.md)

[Another Post](../../_posts/2016-01-01-test.md)

<!--more-->

Foobar
10 changes: 9 additions & 1 deletion spec/jekyll-relative-links/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4449dba

Please sign in to comment.