untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
394 stars 58 forks source link

`relative_url_regex': target of repeat operator is not specified #204

Closed hynrng closed 1 month ago

hynrng commented 1 month ago

Hello, thank you for a great plugin. I would love to try this plugin for my Jekyll blog.


However unfortunately I'm facing the following error:

C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/jekyll-polyglot-1.8.0/lib/jekyll/polyglot/patches/jekyll/site.rb:234:in
`relative_url_regex': target of repeat operator is not specified: /href="?\/((?:(?!*.gem)(?!*.gemspec)(?!docs)(?!tools)
(?!README.md)(?!LICENSE)(?!*.config.js)(?!package*.json)(?!.sass-cache)(?!.jekyll-cache)(?!gemfiles)(?!Gemfile)
(?!Gemfile.lock)(?!node_modules)(?!vendor\/bundle\/)(?!vendor\/cache\/)(?!vendor\/gems\/)(?!vendor\/ruby\/)
(?!_data\/)(?!_includes\/)(?!_plugins\/)(?!_sass\/)(?!_tabs\/)(?!.github\/)(?!assets\/)(?!en\/)
(?!ko\/)[^,'"\s\/?.]+\.?)*(?:\/[^\]\[)("'\s]*)?)"/ (RegexpError)

It seems the following code is causing the error,

def relative_url_regex(disabled = false)
  regex = ''
  unless disabled
    @exclude.each do |x|
      regex += "(?!#{x})"
    end
    @languages.each do |x|
      regex += "(?!#{x}\/)"
    end
  end
  start = disabled ? 'ferh' : 'href'
  %r{#{start}="?#{@baseurl}/((?:#{regex}[^,'"\s/?.]+\.?)*(?:/[^\]\[)("'\s]*)?)"}
end

However I don't think fixing the code would help.

for the information, my _config.yml file is like:

plugins:
  - jekyll-polyglot

languages: ["en", "ko"]
default_lang: "ko"
exclude_from_localization: ["_data", "_includes", "_plugins", "_sass", "_tabs", ".github", "assets"]
parallel_localization: false

I've followed the another issue seems related with my situation (removing ".gem" and ".gemspec" from _config.yml) but it didn't help. (I'm using Ruby 3.3.0, jekyll 4.3.3, and working on Windows.)

untra commented 1 month ago

Hello @hynrng 👋

The problem is .github in the exclude_from_localization configuration. That is used to build a regex and the . in a directory name is likely not handled well.

However that exclude_from_localization setting is for specifying directories you want included only once in your built jekyll site, and not localized for N many languages (["en", "ko"]).

You should instead specify the .github directory as part of the exclude: [...] configuration for jekyll if you specifically want that directory excluded from the built site, which is what I think you want.

I hope this helps and makes sense!

hynrng commented 1 month ago

Thank you for your detailed response.

However, although I read your response carefully, I am still under the same problem. My understanding is that need to add .github to the exclude: part of _config.yml, but I'm still getting the same error. I'm sorry, but could you help me a little more? I would really like to try this plugin.


my _config.yml is currently like:

exclude:
  ...
  - .github # jekyll-polyglot
untra commented 1 month ago

looking closer, when I run the regex in your error

/href="?\/((?:(?!*.gem)(?!*.gemspec)(?!docs)(?!tools)
(?!README.md)(?!LICENSE)(?!*.config.js)(?!package*.json)(?!.sass-cache)(?!.jekyll-cache)(?!gemfiles)(?!Gemfile)
(?!Gemfile.lock)(?!node_modules)(?!vendor\/bundle\/)(?!vendor\/cache\/)(?!vendor\/gems\/)(?!vendor\/ruby\/)
(?!_data\/)(?!_includes\/)(?!_plugins\/)(?!_sass\/)(?!_tabs\/)(?!.github\/)(?!assets\/)(?!en\/)
(?!ko\/)[^,'"\s\/?.]+\.?)*(?:\/[^\]\[)("'\s]*)?)"/

through regexr I see it highlights the *.gem and *.gemspec that you took out. It also flags *.config.js which I don't see you mentioned anywhere in your config, but that value is being included and problematic to the built regex. Try taking that out wherever you may have specified it:

Screenshot 2024-05-30 at 8 15 03 AM
hynrng commented 1 month ago

Uh, sorry, I forgot to mention that. I'm using Chirpy theme and by default, the _config.yml of it excludes:

- "*.gem"
- "*.gemspec"
- docs
- tools
- README.md
- LICENSE
- "*.config.js"
- package*.json

and I guess those with the wildcard are causing the problem. I tried to take them out, and sure enough, the page builds without 'relative_url_regex': target of repeat operator is not specified error, but it ends up being broken like: "Index of ..."

untra commented 1 month ago

I would say that this is a bug in the chirpy theme: https://github.com/cotes2020/jekyll-theme-chirpy/blob/master/_config.yml#L211-L217

exclude entries are supposed to be file or directory names, not glob patterns. https://jekyllrb.com/docs/configuration/options/#global-configuration

either the jekyll documentation is wrong, or chirpy theme excludes are not working correctly. I would open a bug in that project and ask about this.

hynrng commented 1 month ago

Thank you for your sincere response.

There doesn't seem to be much I can do on my own. It's unfortunate, but I'd better to wait for the issue to be resolved 🥲

hynrng commented 1 month ago

Problem solved

I discovered other jekyll themes such as miminal-mistakes are using flob patterns on exlude: section.

So, rather than opening an issue on Chirpy theme, I edited the site.rb code like: