sverrirs / jekyll-paginate-v2

Pagination Generator for Jekyll 3 (enhanced replacement for the old built-in jekyll-paginate gem) ⛺
https://rubygems.org/gems/jekyll-paginate-v2
MIT License
526 stars 289 forks source link

AutoPage layouts included in theme are not discovered #88

Open necopinus opened 6 years ago

necopinus commented 6 years ago

I'm currently working on a Jekyll theme, and have discovered while testing that jekyll-paginate-v2 doesn't properly pick up layouts outside of the site-wide _layouts directory.

Current Behavior: Suppose my theme includes the following files:

_layouts/autopage_category.html
_layouts/autopage_collection.html
_layouts/autopage_tags.html

Running bundle exec jekyll serve will cause AutoPages to complain that the relevant default layouts cannot be found. Copying these into my site's _layouts folder works as expected.

Expected Behavior: If a layout is included in a theme but not in the site's _layouts folder, use the theme's layout. This would bring jekyll-paginate-v2's behavior w.r.t. layouts in line with other Jekyll plugins (such as jekyll-archives).

muellesi commented 6 years ago

I have this same exact problem - I created the layout category-view.html inside my theme gem and configured autopages to use it for categories and tags.

When trying to build the site, I get a whole bunch of error messages:

Error reading file PATH_TO_SITE/_layouts/category-view.html: No such file or directory @ rb_sysopen - PATH_TO_SITE/_layouts/category-view.html
bradonomics commented 4 years ago

I'm getting the same errors for tags, categories, and collections.

         AutoPages: Generating tags pages
Error reading file /_layouts/archive.html: No such file or directory @ rb_sysopen - /_layouts/archive.html 
         AutoPages: Generating categories pages
Error reading file /_layouts/archive.html: No such file or directory @ rb_sysopen - /_layouts/archive.html 
         AutoPages: Generating collections pages
Error reading file /_layouts/portfolio-archive.html: No such file or directory @ rb_sysopen - /_layouts/portfolio-archive.html 

Any idea on time frame for a fix?

albertvolkman commented 4 years ago

I hacked this to make it work while using remote themes-

https://github.com/sverrirs/jekyll-paginate-v2/pull/203

viv-li commented 3 years ago

+1 would be good to have a fix for this :)

viv-li commented 3 years ago

Have done a bit of investigation, the issue occurs in this line while initialising a BaseAutoPage:

        self.read_yaml(File.join(site.source, layout_dir), layout_name)

Looking more closely at the Convertible.read_yaml method (code here):

    def read_yaml(base, name, opts = {})
      filename = @path || site.in_source_dir(base, name)
      Jekyll.logger.debug "Reading:", relative_path

      begin
        self.content = File.read(filename, **Utils.merged_file_read_opts(site, opts))
        ...

read_yaml will either use @path or look in the site's source dir to read a given file. But in order for read_yaml to read a layout that lives in a theme directory, we'd have to set the page @path to the theme layouts directory (which seems ugly and might lead to unexpected behaviour).

The layout is already passed through further down in the BaseAutoPage.initialise method in this line:

        self.data['layout'] = File.basename(layout_name, File.extname(layout_name))

and this will load a theme layout fine because the renderer later looks in site.layouts where any theme layouts have been made available.

Given that it's not required to load the layout, is there a particular reason that read_yaml is being called here that I may have missed? @sverrirs

arghc commented 2 years ago

I hacked this to make it work while using remote themes-

203

I'm currently developing my own gem theme and since I'm developing locally, using gem "myTheme", :path => "../myTheme/" the remote theme hack won't work. I'd hate to miss some important error getting drowned out by the flood of tag errors that aren't "real"