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

Update derive_lang_from_path to derive from any part of path #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions lib/jekyll/polyglot/patches/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ def derive_lang_from_path(doc)
end

segments = doc.relative_path.split('/')
if doc.relative_path[0] == '_' \
&& segments.length > 2 \
&& segments[1] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
return segments[1]
elsif segments.length > 1 \
&& segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
return segments[0]
end

# loop through all segments and check if they match the language regex
segments.each do |segment|
if segment =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
george-gca marked this conversation as resolved.
Show resolved Hide resolved
return segment
end
end

nil
end

Expand Down