Build a beautiful and simple website in literally minutes. Demo at http://deanattali.com/beautiful-jekyll
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

7 years ago
  1. module Jekyll
  2. class TagIndex < Page
  3. def initialize(site, base, dir, tag)
  4. @site = site
  5. @base = base
  6. @dir = dir
  7. @name = 'index.html'
  8. self.process(@name)
  9. self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
  10. self.data['tag'] = tag
  11. tag_title_prefix = site.config['tag_title_prefix'] || 'Posts Tagged &ldquo;'
  12. tag_title_suffix = site.config['tag_title_suffix'] || '&rdquo;'
  13. self.data['title'] = "#{tag_title_prefix}#{tag}#{tag_title_suffix}"
  14. end
  15. end
  16. class TagGenerator < Generator
  17. safe true
  18. def generate(site)
  19. if site.layouts.key? 'tag_index'
  20. dir = site.config['tag_dir'] || 'tag'
  21. site.tags.keys.each do |tag|
  22. write_tag_index(site, File.join(dir, tag), tag)
  23. end
  24. end
  25. end
  26. def write_tag_index(site, dir, tag)
  27. index = TagIndex.new(site, site.source, dir, tag)
  28. index.render(site.layouts, site.site_payload)
  29. index.write(site.dest)
  30. site.pages << index
  31. end
  32. end
  33. end