benbalter / jekyll-remote-theme

Jekyll plugin for building Jekyll sites with any GitHub-hosted theme
MIT License
291 stars 77 forks source link

Unable to use plugins from remote theme #75

Closed asbjornu closed 4 years ago

asbjornu commented 4 years ago

Describe the bug

We have a few custom tag plugins in the _plugins folder in a remote theme. Using the theme in another repository makes jekyll build fail as the plugins aren't found:

Liquid Exception: Liquid syntax error (line 2): Unknown tag 'icon' in payments/index.md
bundler: failed to load command: jekyll (/Users/aul/gems/bin/jekyll)
Liquid::SyntaxError: Liquid syntax error (line 2): Unknown tag 'icon'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/document.rb:23:in `unknown_tag'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/document.rb:11:in `block in parse'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/block_body.rb:32:in `parse'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/document.rb:10:in `parse'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/document.rb:5:in `parse'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/template.rb:132:in `parse'
  /Users/aul/gems/gems/liquid-4.0.3/lib/liquid/template.rb:116:in `parse'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/liquid_renderer/file.rb:13:in `block in parse'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/liquid_renderer/file.rb:60:in `measure_time'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/liquid_renderer/file.rb:12:in `parse'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:122:in `render_liquid'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:80:in `render_document'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:63:in `run'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:523:in `render_regenerated'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:516:in `block in render_pages'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:515:in `each'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:515:in `render_pages'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:202:in `render'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/site.rb:76:in `process'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/command.rb:28:in `process_site'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:65:in `build'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:36:in `process'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `block in process_with_graceful_fail'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `each'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `process_with_graceful_fail'
  /Users/aul/gems/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
  /Users/aul/gems/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
  /Users/aul/gems/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
  /Users/aul/gems/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
  /Users/aul/gems/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
  /Users/aul/gems/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
  /Users/aul/gems/gems/jekyll-4.0.0/exe/jekyll:15:in `<top (required)>'
  /Users/aul/gems/bin/jekyll:23:in `load'
  /Users/aul/gems/bin/jekyll:23:in `<top (required)>'

Steps to reproduce the behavior

  1. Clone this repository
  2. git checkout feature/dx-803_docker
  3. bundle exec jekyll build
  4. See error

Expected behavior

I expect plugins within the _plugins folder of a remote theme to work in Jekyll sites using said remote theme.

Additional context

$ bundle list
Gems included by the bundle:
  * activesupport (6.0.2.1)
  * addressable (2.7.0)
  * colorator (1.1.0)
  * concurrent-ruby (1.1.6)
  * em-websocket (0.5.1)
  * eventmachine (1.2.7)
  * faraday (0.17.3)
  * fastimage (1.8.1)
  * ffi (1.12.2)
  * forwardable-extended (2.6.0)
  * gemoji (3.0.1)
  * hike (1.2.3)
  * html-pipeline (2.12.3)
  * http_parser.rb (0.6.0)
  * i18n (1.8.2)
  * jekyll (4.0.0)
  * jekyll-assets (1.0.0)
  * jekyll-github-metadata (2.13.0)
  * jekyll-remote-theme (0.4.2)
  * jekyll-sass-converter (2.1.0)
  * jekyll-watch (2.2.1)
  * jemoji (0.12.0)
  * kramdown (2.1.0)
  * kramdown-parser-gfm (1.1.0)
  * liquid (4.0.3)
  * listen (3.2.1)
  * mercenary (0.3.6)
  * mini_magick (4.10.1)
  * mini_portile2 (2.4.0)
  * minitest (5.14.0)
  * multi_json (1.14.1)
  * multipart-post (2.1.1)
  * nokogiri (1.10.9)
  * octokit (4.17.0)
  * pathutil (0.16.2)
  * public_suffix (4.0.3)
  * rack (1.6.13)
  * rb-fsevent (0.10.3)
  * rb-inotify (0.10.1)
  * rouge (3.17.0)
  * rubyzip (2.3.0)
  * safe_yaml (1.0.5)
  * sass (3.7.4)
  * sass-listen (4.0.0)
  * sassc (2.2.1)
  * sawyer (0.8.2)
  * sprockets (2.12.5)
  * sprockets-helpers (1.2.1)
  * sprockets-sass (1.3.1)
  * terminal-table (1.8.0)
  * thread_safe (0.3.6)
  * tilt (1.4.1)
  * tzinfo (1.2.6)
  * unicode-display_width (1.7.0)
  * zeitwerk (2.3.0)
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

asbjornu commented 4 years ago

WONTFIX? 😢

allejo commented 4 years ago

The goal of this plugin is to allow downloading remote themes in a safe manner for GitHub pages. Downloading arbitrary (and possibly malicious) Ruby code as plugins is probably outside the scope of this project. I wouldn't get my hopes up that this would be implemented.

asbjornu commented 4 years ago

I understand. For Jekyll sites built by GitHub Pages, _plugins isn't supported regardless. But jekyll-remote-theme works for Jekyll sites that have custom builds, where only the resulting HTML is published to gh-pages. In that situation, the current behaviour is a bit unexpected.

It is a bit strange that a theme can load its own plugins to provide some neat functionality and then that functionality breaks when the theme is used by another Jekyll website. Perhaps _plugins in a remote theme can be supported under a new configuration property in _config.yml?

ghost commented 4 years ago

I have not tried this myself but in my mind changing one line in your remote theme's gemspec may work. Specifically, this line:

spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r!^(assets|_layouts|_includes|_sass|LICENSE|README)!i) }

would need to be changed to include the _plugins folder like so:

spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r!^(assets|_layouts|_includes|_sass|_plugins|LICENSE|README)!i) }

(And if that works, then #69 may be fixed in a like manner.)

asbjornu commented 4 years ago

@orchardcc, thanks for the tip! That may just work, but it seems like plugins need to be aware of the fact that they are installed via jekyll-remote-theme somehow, as pathing at least seems to be an issue. My spec.files assignment now looks like this:

spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(/^(assets|_layouts|_includes|_sass|_plugins|_assets|LICENSE|README)/i) }

Any ideas how a plugin from the remote theme can access files from the _assets folder of the remote theme? Currently, __dir__ within the plugin seems to return the base path of the jekyll site (not the remote theme) appended with _plugins and I'm not clear on where the remote theme's files are ending up and where to look for them.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.