Closed Clpsplug closed 1 year ago
Thank you for your detailed issue.
We must use the
config
variable available here, though.
What do you mean by this? Does it mean we have to use --config
option when we want to use _context.registers[:site].config['source']
?
If there is a variable that holds the value of source
, I think we can just add it to @@template_dir
.
We must use the
config
variable available here, though. What do you mean by this?
By this part, I meant that only the context
parameter for the render
method holds the object that we need. Whether it's from _config.yml
or from the --config
command line flag override, the source
config value will appear as context.registers[:site].config['source']
.
So yes, I think the fix is to prepend it to @@template_dir
, too. I'm making a PR, and I'm about to test it on my end. I'll also try modifying RSpec tests but it may become a bit complicated because there are Jekyll's configuration values taken into consideration.
The issue
Directories that this plugin would use are all expected to be present in the project root. However, Jekyll has a configuration to change the 'content root' of the site. It can change where Jekyll looks for the contents to build a site.
My site makes use of this configuration value. However, because the plugin only looks at the project root, I have to create a weird directory structure like this:
Notice that I have to repeat
_includes
dir twice.Since the outer
_includes
is outside of the 'content root,' Jekyll cannot auto-rebuild the site on a change tolinkpreview.html
when running the commandjekyll serve.
Potential fix
In Jekyll, it is possible to pull the configuration value from within the Tag class. This is done in a context-aware manner; for example, if you use the
--config
option in thejekyll
command, it will use the value in a specified file instead of_config.yml.
I gave a quick read of the source code, and it looks that capturing this value in the method below and prepending it to
@@template_dir
should do the trick.https://github.com/ysk24ok/jekyll-linkpreview/blob/181981c56c9daffa7da4082ae20a5f9dc64d1d48/lib/jekyll-linkpreview.rb#L147-L151
I'm not sure about the
@@cache_dir
, though. The required change is precisely the same, but the_cache
dir looks fine to stay outside the content root for me. But again, that directory being aware of the "source" config also makes total sense.I'd be happy to hear your opinion on this matter. Thanks for a great plugin! 😄