Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/53 #65

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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