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

Allow reusing a set of filter/layout/... #58

Open
sdalu opened this issue Dec 17, 2020 · 2 comments
Open

Allow reusing a set of filter/layout/... #58

sdalu opened this issue Dec 17, 2020 · 2 comments

Comments

@sdalu
Copy link

sdalu commented Dec 17, 2020

When writing rules some of them can have a similar set of filter/layout/...
it would be useful to provide a mechanism to reuse some block of code

For example:

# Define a set of filter/layout that can be reuse later
apply :markdown do
  # Set of complex filter/layout/...
  filter: kramdow, .. complex set of options ..
  filter :foo
  filter :bar
  ...
end

# Compiling by reussing set of filter/layout/...
compile 'blog/**/*.md' do
  apply :markdown
  ...
end
compile '**/*.md' do
  apply :markdown
  ...
end
@denisdefreyne denisdefreyne transferred this issue from nanoc/nanoc Dec 18, 2020
@denisdefreyne
Copy link
Member

Thanks for the suggestion! I’ve moved this to the features repository to keep track of it.

@dseomn
Copy link

dseomn commented Jun 9, 2024

I got some code working in the Rules file to do this, but I'm inexperienced at ruby and this might be very very hacky:

module Nanoc::RuleDSL
  class CompilationRuleContext < RuleContext
    def minify_html
      filter(
        :external,
        exec: 'minify',
        options: [
          '--type=html',
          '--html-keep-document-tags',
        ],
      )
      nil
    end
  end
end

compile %r{^/pages/([^/]+)/index\.html\.erb$} do |slug,|
  filter :erb
  layout '/page.html.erb'
  layout '/base.html.erb'
  minify_html
  write "/#{slug}/index.html"
end

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

No branches or pull requests

3 participants