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
Fix/i18n headers #67
Fix/i18n headers #67
Changes from 6 commits
4429d46
be6b649
2f5067d
2016efe
2ca3c91
b033972
dceb57d
2a26a02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,13 @@ becomes | |
Notice the link `<a href="/fr/menu/">...` directs to the french website. | ||
|
||
Even if you are falling back to `default_lang` page, relative links built on the *french* site will | ||
still link to *french* pages. | ||
still link to *french* pages.v | ||
|
||
#### Relativized Absolute Urls | ||
If you defined a site `url` in your `_config.yaml`, polyglot will automatically relativize links pointing to your absolute site url. If you don't want them relativized, adding a space explicitly to an href prevents the the absolute url from being relativized. | ||
|
||
processed: `href="http://mywebsite.com/about"` | ||
unprocessed: `href=" http://mywebsite.com/about"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the space trick work for absolute URLs only? Frankly speaking, I think it is easier to understand in a form of "in case you want to keep the URL as is, just prepend it with a whitespace and polyglot would ignore the link". If whitespace trick works for all kinds of URLs, then the wording should probably be improved. Currently it sounds like the feature is absolute-URL-only. |
||
|
||
#### Localized site.data | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,15 @@ def coordinate_documents(docs) | |
|
||
# performs any necesarry operations on the documents before rendering them | ||
def process_documents(docs) | ||
return if @active_lang == @default_lang | ||
url = config.fetch('url', false) | ||
rel_regex = relative_url_regex | ||
abs_regex = absolute_url_regex(url) | ||
docs.each do |doc| | ||
relativize_urls doc | ||
relativize_urls(doc, rel_regex) | ||
if url | ||
then relativize_absolute_urls(doc, abs_regex, url) | ||
end | ||
end | ||
end | ||
|
||
|
@@ -125,14 +132,26 @@ def relative_url_regex | |
@exclude.each do |x| | ||
regex += "(?!#{x}\/)" | ||
end | ||
url_quoted = config['url'] | ||
url_quoted = Regexp.quote(url_quoted) unless url_quoted.nil? | ||
%r{href=\"(?:#{url_quoted})?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"} | ||
%r{href=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, relative URLs like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be intentional. The exclusion of the You are right thought a relative url like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they're getting the same treatment 👍 |
||
end | ||
|
||
def relativize_urls(doc) | ||
return if @active_lang == @default_lang | ||
doc.output.gsub!(relative_url_regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"') | ||
def absolute_url_regex(url) | ||
regex = '' | ||
@exclude.each do |x| | ||
regex += "(?!#{x}\/)" | ||
end | ||
@languages.each do |l| | ||
regex += "(?!#{l}\/)" | ||
end | ||
%r{href=\"?#{url}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be %r{href=\"?#{url}#{baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"} |
||
end | ||
|
||
def relativize_urls(doc, regex) | ||
doc.output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"') | ||
end | ||
|
||
def relativize_absolute_urls(doc, regex, url) | ||
doc.output.gsub!(regex, "href=\"#{url}/#{@active_lang}/" + '\1"') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be doc.output.gsub!(regex, "href=\"#{url}#{baseurl}/#{@active_lang}/" + '\1"') |
||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last v looks odd.