Add plugin for automatic hyphenation
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -1,7 +1,8 @@
|
||||
source 'https://rubygems.org'
|
||||
gem 'jekyll-paginate'
|
||||
gem 'jekyll-paginate'
|
||||
gem 'kramdown'
|
||||
gem 'redcarpet'
|
||||
gem 'rouge'
|
||||
gem 'pygments.rb'
|
||||
gem 'text-hyphen'
|
||||
gem 'nokogiri'
|
||||
@@ -5,6 +5,7 @@ asset_prefix: /asset
|
||||
static_prefix: /static
|
||||
|
||||
# variables
|
||||
language: nl
|
||||
title: Rik @ St Andrews
|
||||
author: Rik Veenboer
|
||||
email: rik.veenboer@gmail.com
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div style="width: {{ include.width }}px;" class="caption">
|
||||
<img src="{{ include.image }}" />
|
||||
{% if include.text %}
|
||||
{{ include.text|markdownify }}
|
||||
{{ include.text | markdownify | hyphenate }}
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -5,7 +5,6 @@
|
||||
var disqus_identifier = '{{ page.id }}';
|
||||
var disqus_title = '{{ page.title|replace:"'":"\\'" }}';
|
||||
var disqus_url = '{{ site.absolute }}{{ page.url }}';
|
||||
|
||||
(function() {
|
||||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
||||
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<section itemscope itemtype="http://schema.org/BlogPosting">
|
||||
<header>
|
||||
<div class="timeline">
|
||||
{% if post.date %}
|
||||
<time datetime="{{ post.date|date_to_xmlschema }}" title="{{ post.date|date_to_xmlschema }}"><strong>{{ post.date|date:"%b %d"|upcase }}</strong><br />{{ post.date|date:"%Y" }}</time>
|
||||
{% endif %}
|
||||
{% if post.location %}
|
||||
<a href="https://maps.google.com/maps?hl=en&ll={{ post.location.latitude }},{{ post.location.longitude }}&t=w&z=12"><img alt="map" height="49" src="https://maps.googleapis.com/maps/api/staticmap?center={{ post.location.latitude }},{{ post.location.longitude }}&zoom=9&size=98x98&sensor=false" title="{{ post.location.title }}" width="49" /></a>
|
||||
{% endif %}
|
||||
{% if post.code %}
|
||||
<a href="{{ post.code }}"><img alt="code" height="49" src="{{ site.static_prefix }}/icon/code.png" width="49" /></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h1>
|
||||
<span itemprop="name">{{ post.title }}</span>
|
||||
<small class="print-only" itemprop="datePublished" content="{{ post.date|date:'%F') }}">{{ post.date|date:'%A, %B %d, %Y' }}</small>
|
||||
</h1>
|
||||
</header>
|
||||
<section class="post-content" itemprop="articleBody">
|
||||
{{ post.content }}
|
||||
</section>
|
||||
</section>
|
||||
@@ -17,7 +17,7 @@
|
||||
</h1>
|
||||
</header>
|
||||
<section class="post-content" itemprop="articleBody">
|
||||
{{ post.excerpt }}
|
||||
{{ post.excerpt | hyphenate }}
|
||||
{% capture content_words %}
|
||||
{{ post.content | number_of_words }}
|
||||
{% endcapture %}
|
||||
@@ -26,7 +26,7 @@
|
||||
{% endcapture %}
|
||||
{% if excerpt_words != content_words %}
|
||||
<p>
|
||||
<a href="/{{ site.baseurl }}{{ post.url }}" class="read-more" role="button">{{ site.read_more }}</a>
|
||||
<a href="/{{ site.baseurl }}{{ post.url }}#more" class="read-more" role="button">{{ site.read_more }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
{% endif %}
|
||||
</header>
|
||||
<section class="post-content" itemprop="articleBody">
|
||||
{{ content }}
|
||||
{{ content | hyphenate }}
|
||||
</section>
|
||||
{% if false != page.comments %}
|
||||
{% include disqus.html %}
|
||||
|
||||
41
_plugins/hyphenate.rb
Normal file
41
_plugins/hyphenate.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
# adapted from
|
||||
# - https://raw.githubusercontent.com/aucor/jekyll-plugins/master/hyphenate.rb
|
||||
|
||||
require 'nokogiri'
|
||||
require 'text/hyphen'
|
||||
|
||||
module Jekyll
|
||||
module HyphenateFilter
|
||||
def hyphenate(content)
|
||||
# Initialize Hyphen
|
||||
hh = Text::Hyphen.new(:language => @context.registers[:site].config['language'], :left => 2, :right => 2)
|
||||
|
||||
# Parse html with Nokogiri
|
||||
fragment = Nokogiri::HTML::DocumentFragment.parse(content)
|
||||
|
||||
# Grab the html as it is
|
||||
html = fragment.inner_html
|
||||
|
||||
# Loop through every paragraph
|
||||
fragment.css('p').each do |p|
|
||||
h = p.content
|
||||
|
||||
# Loop through every word
|
||||
p.content.split.each do |w|
|
||||
# Replace original word with a hyphenated one unless it is the last word in a paragraph
|
||||
if w != p.content.split.last
|
||||
h = h.gsub(w, hh.visualize(w, '­'))
|
||||
end
|
||||
end
|
||||
|
||||
# Replace original paragraph with a hyphenated one
|
||||
html = html.gsub(p, h)
|
||||
end
|
||||
|
||||
# Return hyphenated html
|
||||
html
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_filter(Jekyll::HyphenateFilter)
|
||||
@@ -5,7 +5,7 @@ tags: blog scotland chemistry phd
|
||||
---
|
||||
<section>
|
||||
<p>
|
||||
In dit blog houd ik jullie zo goed mogelijk op de hoogte van mijn belevenissen in St Andrews, Schotland. Daar ben ik in november 2013 begonnen aan een vierjarige PhD in de scheikunde, met als uiteindelijk doel het halen van de doctor titel. Nostalgicie zijn misschien verknocht aan de <a href="http://csbnw.no-ip.org:38/">oude versie</a> van dit blog.
|
||||
In dit blog houd ik jullie zo goed mogelijk op de hoogte van mijn belevenissen in St Andrews, Schotland. Daar ben ik in november 2013 begonnen aan een vierjarige PhD in de scheikunde, met als uiteindelijk doel het halen van de doctor titel. Om het voor iedereen leuk te houden zal ik niet uitweiden over ontwikkelingen op academisch gebied. Nostalgicie zijn misschien verknocht aan de <a href="http://csbnw.no-ip.org:38/">oude versie</a> van dit blog.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user