-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #865 from Fryguy/canonical_urls
Add support for canonical URLs
- Loading branch information
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Jekyll::Page#url is memoized on first call, but this causes issues with the | ||
# paginator. As such, we get the URL and then remove the memoization. | ||
def extract_page_url(page) | ||
had_url = page.instance_variable_defined?(:@url) | ||
page.url.tap do | ||
page.instance_variable_set(:@url, nil) unless had_url | ||
end | ||
end | ||
|
||
Jekyll::Hooks.register :pages, :post_init do |page| | ||
page.data['canonical_url'] ||= extract_page_url(page) | ||
end | ||
|
||
Jekyll::Hooks.register :posts, :post_init do |post| | ||
post.data['canonical_url'] ||= extract_page_url(post) | ||
end | ||
|
||
Jekyll::Hooks.register :documents, :post_init do |doc| | ||
doc.data['canonical_url'] ||= extract_page_url(doc) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters