Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator plugins broken by new cleanup behavior #268

Closed
andyfowler opened this issue Jan 17, 2011 · 14 comments
Closed

Generator plugins broken by new cleanup behavior #268

andyfowler opened this issue Jan 17, 2011 · 14 comments
Milestone

Comments

@andyfowler
Copy link

Any generator that writes files directly to the output directory is broken as of commit c1ed790 -- this includes the sample generator code in the wiki. It's not clear how a generator should specify that the files it creates are 'whitelisted'.

@molte
Copy link

molte commented Jan 30, 2011

I am experiencing this issue too.

Any file that is created by a generator will be marked as obsolete and deleted even though it has just been created.

@philippbosch
Copy link

Same here. Good to know I'm not alone with this problem …
Any advice welcome.

@molte
Copy link

molte commented Feb 3, 2011

Creating a Ruby file in the "_plugins" folder with the following contents works for me, though I haven't run it against the test suite:

module Jekyll
  class Site
    def process
      self.reset
      self.read
      self.cleanup
      self.generate
      self.render
      self.write
    end
  end
end

@andyfowler
Copy link
Author

@molte -- nice workaround, although I hope this isn't the long-term solution. In my case, I'm compiling LESS.js files, and with this workaround, they're all regenerated each run.

@molte
Copy link

molte commented Feb 5, 2011

Of course you could also entirely remove the self.cleanup line and then setup the generator to only regenerate/recompile if the source file has been modified by including something like this in your generator:

def generate(site)
  if modified? File.join(site.source, "foo"), File.join(site.dest, "bar")
    # Execute the generation ...
  end
end

def file_timestamp(path)
  File.exist?(path) ? File.mtime(path).to_i : 0
end

def modified?(input_path, output_path)
  file_timestamp(input_path) != file_timestamp(output_path)
end

@josegonzalez
Copy link

You can actually fix this by doing site.static_files << index after performing index.write(site.dest), where index is the GeneratorObject. I tried using site.pages instead of site.static_files, but I ended up getting Liquid Exceptions. Of course, I would still integrate @molte's suggestion.

I've also updated the sample code in the wiki.

@sparkertime
Copy link

I think that updated example in the wiki isn't right - "index" isn't anything at that point in the code.

@josegonzalez
Copy link

Sorry about that, it should be "f". I just took index from a plugin I wrote for my installation.

If it's still broken, I can provide a complete working example, it just wont be the specific one the wiki uses.

@sparkertime
Copy link

The working example may be good - even with that it looks like it's busted on the latest version of jekyll - it tries to call #destination on whatever is passed into static_files

@josegonzalez
Copy link

I've updated the example, although it might not be the simplest. It generates category index files, which people might find useful.

@adunkman
Copy link

I ended up using a custom implementation of StaticFile that didn't actually do anything during the write phase, but since it existed in site.static_files, the output wouldn't get cleaned away. See https://gist.github.com/920651

@parkr
Copy link
Member

parkr commented Apr 14, 2013

Site#cleanup depends upon the site having created the list of files. The better option would be for Generators and the like to add the files they generate to the Site's file manifest and to remove those files from the chopping block.

Why doesn't this affect the pagination plugin?

@pathawks
Copy link
Member

I have absolutely no idea why my file is created during generation, and then deleted during cleanup.

File.open(File.join( site.dest, 'feeds/posts', 'full.xml' ), 'w') do |f|
  f.write('foo-bar')
  f.close
end

site.static_files << Jekyll::StaticFile.new(site, site.dest, 'feeds/posts', 'full.xml')

I can't find any documentation relating to this at all.

@parkr
Copy link
Member

parkr commented May 18, 2013

Our pagination generator is an example of getting around this. In your generate method, add your pages to site.pages and boom-she-boom you're good to go.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants