Show the code for sample generator first [skip ci]

This commit is contained in:
Ashwin Maroli 2019-02-12 22:12:50 +05:30
parent 20d9cbe231
commit 9a4b74c44b
1 changed files with 17 additions and 16 deletions

View File

@ -44,22 +44,6 @@ This is a more complex generator that generates new pages:
```ruby ```ruby
module Jekyll module Jekyll
class CategoryPage < Page
def initialize(site, base, dir, category)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
self.data['category'] = category
category_title_prefix = site.config['category_title_prefix'] || 'Category: '
self.data['title'] = "#{category_title_prefix}#{category}"
end
end
class CategoryPageGenerator < Generator class CategoryPageGenerator < Generator
safe true safe true
@ -72,6 +56,23 @@ module Jekyll
end end
end end
end end
# A Page subclass used in the `CategoryPageGenerator`
class CategoryPage < Page
def initialize(site, base, dir, category)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
self.data['category'] = category
category_title_prefix = site.config['category_title_prefix'] || 'Category: '
self.data['title'] = "#{category_title_prefix}#{category}"
end
end
end end
``` ```