Created
August 4, 2015 23:48
-
-
Save xeraa/c30161bac25011a03058 to your computer and use it in GitHub Desktop.
Middleman: Fully automated alternate language links
This file contains hidden or 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
# Returns a hash of localized paths for a given page | |
def localized_paths_for(page) | |
localized_paths = {} | |
(langs).each do |locale| | |
# Loop over all pages to find the ones using the same templates (proxied_to) for each language | |
sitemap.resources.select do |resource| | |
if resource.proxied_to == page.proxied_to && resource.metadata[:options][:lang] == locale | |
localized_paths[locale] = resource.url | |
break | |
end | |
end | |
end | |
localized_paths | |
end |
This file contains hidden or 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
<% localized_paths_for(current_page).each do |text, path| %> | |
<link rel="alternate" hreflang="<%= text %>" href="https://example.com<%= path %>"/> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@xeraa when I try to run my Middleman localhost site with it I am getting:
Do I need to specify something in frontmatter?