jekyll-paginate-v2 icon indicating copy to clipboard operation
jekyll-paginate-v2 copied to clipboard

AutoPage layouts included in theme are not discovered

Open necopinus opened this issue 6 years ago • 6 comments

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).

necopinus avatar Mar 30 '18 16:03 necopinus

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

muellesi avatar May 13 '18 23:05 muellesi

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?

bradonomics avatar Jun 07 '20 20:06 bradonomics

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

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

albertvolkman avatar Sep 08 '20 20:09 albertvolkman

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

viv-li avatar Oct 15 '21 11:10 viv-li

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

viv-li avatar Oct 15 '21 13:10 viv-li

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"

arghc avatar Aug 15 '22 20:08 arghc