├── strip.rb ├── weighted_pages.rb ├── LICENCE ├── hyphenate.rb └── README.md /strip.rb: -------------------------------------------------------------------------------- 1 | # Replaces multiple newlines and whitespace 2 | # between them with one newline 3 | 4 | module Jekyll 5 | class StripTag < Liquid::Block 6 | 7 | def render(context) 8 | super.gsub /\n\s*\n/, "\n" 9 | end 10 | 11 | end 12 | end 13 | 14 | Liquid::Template.register_tag('strip', Jekyll::StripTag) -------------------------------------------------------------------------------- /weighted_pages.rb: -------------------------------------------------------------------------------- 1 | # Generates a copy of site.pages as site.weighted_pages 2 | # with pages sorted by weight attribute. Pages with no 3 | # weight specified are placed after the pages with specified weight. 4 | 5 | module Jekyll 6 | 7 | class WeightedPagesGenerator < Generator 8 | safe true 9 | 10 | def generate(site) 11 | site.config['weighted_pages'] = site.pages.sort_by { |a| 12 | a.data['weight'] ? a.data['weight'] : site.pages.length } 13 | end 14 | 15 | end 16 | 17 | end -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012 Aucor Oy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /hyphenate.rb: -------------------------------------------------------------------------------- 1 | require 'nokogiri' 2 | require 'text/hyphen' 3 | 4 | module Jekyll 5 | module HyphenateFilter 6 | 7 | def hyphenate(content) 8 | # Initialize Hyphen 9 | # (you can change the language as you wish, we're from Finland ;) 10 | # note: english is en_us or en_uk not just en 11 | hh = Text::Hyphen.new(:language => 'fi', :left => 2, :right => 2) 12 | 13 | # Parse html with Nokogiri 14 | fragment = Nokogiri::HTML::DocumentFragment.parse(content) 15 | 16 | # Grab the html as it is 17 | html = fragment.inner_html 18 | 19 | # Loop through every paragraph 20 | fragment.css('p').each do |p| 21 | h = p.content 22 | 23 | # Loop through every word 24 | p.content.split.each do |w| 25 | # Replace original word with a hyphenated one 26 | # unless it is the last word in a paragraph 27 | if w != p.content.split.last 28 | h = h.gsub(w, hh.visualize(w, '­')) 29 | end 30 | end 31 | 32 | # Replace original paragraph with a hyphenated one 33 | html = html.gsub(p, h) 34 | end 35 | 36 | # Return hyphenated html 37 | html 38 | 39 | end 40 | 41 | end 42 | end 43 | 44 | Liquid::Template.register_filter(Jekyll::HyphenateFilter) 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Jekyll plugins by Aucor 2 | ======================= 3 | 4 | Collection of plugins for the Jekyll static site generator. 5 | 6 | 7 | Overview 8 | -------- 9 | 10 | Plugins included in this repository: 11 | 12 | * **strip.rb** - Block tag for trimming away unwanted newlines and whitespace between them. 13 | * **weighted_pages.rb** - Generates a page listing with pages sorted by a weight attribute. 14 | * **hyphenate.rb** - Provides a hyphenation filter using [text-hyphen](https://rubygems.org/gems/text-hyphen) 15 | 16 | Usage 17 | ----- 18 | 19 | ### strip.rb 20 | 21 | Using eg. forloops to generate navigation produces often a huge amount of ugly whitespace. Wrapping the section with `{% strip %}{% endstrip %}` replaces the blocks of whitespace with one newline resulting in pretty markup. 22 | 23 | ### weighted_pages.rb 24 | 25 | Add `weight` attribute to the front matter of your pages (like `weight: 1`) and use `site.weighted_pages` instead of `site.pages` in your loops. 26 | 27 | Pages without the attribute are sorted to the end of the list (in the default order). 28 | 29 | ### hyphenate.rb 30 | 31 | By default the filter hyphenates content of all paragraph tags, but this can be customized at line 19 using Nokogiri css-selectors. You probably want to use this like `{{ content | hyphenate }}` 32 | 33 | Requires [Nokogiri](http://nokogiri.org/) & [text-hyphen](https://rubygems.org/gems/text-hyphen) gems. 34 | 35 | 36 | Author 37 | ------ 38 | 39 | Plugins written by Janne Ala-Äijälä of [Aucor Oy](http://www.aucor.fi) 40 | 41 | 42 | Copyright 43 | --------- 44 | 45 | Copyright (c) 2012 Aucor Oy. Released under MIT Licence (see LICENCE for details). --------------------------------------------------------------------------------