From ad219ff8ccc5e036e8240e26ef0803b1fed8c83a Mon Sep 17 00:00:00 2001
From: Rik Veenboer
Date: Fri, 22 Jan 2016 19:27:34 +0000
Subject: [PATCH] Move galleries to collection, generate map and slideshow on
build, stop using loopdir plugin, update templates accordingly
---
_config.yml | 17 ++-
_includes/caption.html | 4 +
_includes/gallery-list.html | 11 ++
_includes/gallery.html | 7 +-
_includes/gallery_list.html | 4 -
_includes/gallery_list640w.html | 2 -
_includes/photo.html | 4 +-
.../{post_detail.html => post-detail.html} | 0
_layouts/gallery-list.html | 27 +++--
_layouts/gallery-map.html | 26 +++--
_layouts/gallery-photo.html | 24 ++---
_layouts/gallery-slideshow.html | 35 +++---
_plugins/gallery.rb | 27 +++++
_plugins/loopdir.rb | 100 ------------------
_scripts/convert-galleries.php | 96 +++++++++++++++++
_scripts/generate-gallery.php | 42 +-------
gallery/index.html | 16 +--
index.html | 7 +-
18 files changed, 236 insertions(+), 213 deletions(-)
create mode 100644 _includes/gallery-list.html
delete mode 100644 _includes/gallery_list.html
delete mode 100644 _includes/gallery_list640w.html
rename _includes/{post_detail.html => post-detail.html} (100%)
create mode 100644 _plugins/gallery.rb
delete mode 100644 _plugins/loopdir.rb
create mode 100644 _scripts/convert-galleries.php
diff --git a/_config.yml b/_config.yml
index 081b481..d0ac3f2 100644
--- a/_config.yml
+++ b/_config.yml
@@ -25,6 +25,20 @@ previous_page: '← Vorige pagina'
next_page: 'Volgende pagina →'
mentioned_in: 'Komt voor in:'
+# collections
+collections:
+ gallery:
+ output: true
+ permalink: /:collection/:name/
+
+# defaults
+defaults:
+ -
+ scope:
+ type: gallery
+ values:
+ layout: gallery-list
+
# other
gems: [jekyll-paginate]
markdown: rdiscount
@@ -32,4 +46,5 @@ rdiscount:
extensions: [smart]
exclude:
- LICENSE
-- README
\ No newline at end of file
+- README
+array: []
\ No newline at end of file
diff --git a/_includes/caption.html b/_includes/caption.html
index e47bf3f..22727ea 100644
--- a/_includes/caption.html
+++ b/_includes/caption.html
@@ -1,5 +1,9 @@
+ {% if include.link %}
+
+ {% else %}
+ {% endif %}
{% if include.text %}
{{ include.text | markdownify | hyphenate }}
{% endif %}
diff --git a/_includes/gallery-list.html b/_includes/gallery-list.html
new file mode 100644
index 0000000..d2bf10f
--- /dev/null
+++ b/_includes/gallery-list.html
@@ -0,0 +1,11 @@
+
+{% for p in site.pages %}
+ {% if p.layout == 'gallery-photo' and p.gallery == gallery %}
+
+
+
+
+
+ {% endif %}
+{% endfor %}
+
diff --git a/_includes/gallery.html b/_includes/gallery.html
index c486d49..2da2170 100644
--- a/_includes/gallery.html
+++ b/_includes/gallery.html
@@ -1,4 +1,7 @@
-{% capture path %}gallery/{{ include.gallery }}{% endcapture %}
- {% loopdir path:path match:"*.md" sort:"ordering" %}
{% endloopdir %}
+{% for p in site.pages %}
+ {% if p.layout == 'gallery-photo' and p.gallery == include.gallery %}
+
+ {% endif %}
+{% endfor %}
\ No newline at end of file
diff --git a/_includes/gallery_list.html b/_includes/gallery_list.html
deleted file mode 100644
index 2c77175..0000000
--- a/_includes/gallery_list.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
- {% capture path %}gallery/{{ include.gallery }}{% endcapture %}
- {% loopdir path:path match:"*.md" sort:"ordering" %}
{% endloopdir %}
-
diff --git a/_includes/gallery_list640w.html b/_includes/gallery_list640w.html
deleted file mode 100644
index 27d721e..0000000
--- a/_includes/gallery_list640w.html
+++ /dev/null
@@ -1,2 +0,0 @@
-{% capture path %}gallery/{{ include.gallery }}{% endcapture %}
-{% loopdir path:path match:"*.md" sort:"ordering" %}
{% endloopdir %}
diff --git a/_includes/photo.html b/_includes/photo.html
index e2ed500..6a3ba07 100644
--- a/_includes/photo.html
+++ b/_includes/photo.html
@@ -1,6 +1,8 @@
-{% capture image %}/asset/gallery/{{ include.album }}/{{ include.photo }}~640w.jpg{% endcapture %}
+{% capture image %}/asset/gallery/{{ include.gallery }}/{{ include.photo }}~640w.jpg{% endcapture %}
+{% capture link %}/{{ site.baseurl }}/gallery/{{ include.gallery }}/{{ include.photo }}.html{% endcapture %}
{% include caption.html
width='600'
image=image
text=include.text
+ link=link
%}
\ No newline at end of file
diff --git a/_includes/post_detail.html b/_includes/post-detail.html
similarity index 100%
rename from _includes/post_detail.html
rename to _includes/post-detail.html
diff --git a/_layouts/gallery-list.html b/_layouts/gallery-list.html
index dd3dbc0..73d74a8 100644
--- a/_layouts/gallery-list.html
+++ b/_layouts/gallery-list.html
@@ -11,34 +11,33 @@ layout: default
- {{ content }}
+ {{ content }}
{% if false != page.slideshow %}
[ slideshow ]
{% endif %}
- {% if false != page.slideshow and false != page.map %}
+ {% if false != page.slideshow and page.map %}
|
{% endif %}
- {% if false != page.map %}
+ {% if page.map %}
[ map ]
{% endif %}
- {% include gallery_list.html gallery=gallery %}
- {% capture list %}
- {% for post in site.posts %}
- {% if post.content contains gallery %}
-
- {{ post.title }}
-
+ {% assign items = site.array %}
+ {% for p in site.posts %}
+ {% if p.content contains gallery %}
+ {% assign items = items | push:p %}
{% endif %}
{% endfor %}
- {% endcapture %}
- {% if list %}
+ {% if items | size > 0 %}
{{ site.mentioned_in }}
{% endif %}
+ {% include gallery-list.html gallery=gallery %}
{% if false != page.comments %}
{% include disqus.html %}
{% endif %}
-
+
\ No newline at end of file
diff --git a/_layouts/gallery-map.html b/_layouts/gallery-map.html
index a7b5b82..d23b341 100644
--- a/_layouts/gallery-map.html
+++ b/_layouts/gallery-map.html
@@ -1,7 +1,9 @@
---
layout: post
---
-{% capture gallery %}{{ page.url|replace:'/map.html',''|remove_first:'/' }}{% endcapture %}
+
+
\ No newline at end of file
diff --git a/_layouts/gallery-photo.html b/_layouts/gallery-photo.html
index cde88dd..7641a61 100644
--- a/_layouts/gallery-photo.html
+++ b/_layouts/gallery-photo.html
@@ -5,12 +5,16 @@ layout: default
diff --git a/_layouts/gallery-slideshow.html b/_layouts/gallery-slideshow.html
index fb792c9..dc5a925 100644
--- a/_layouts/gallery-slideshow.html
+++ b/_layouts/gallery-slideshow.html
@@ -1,10 +1,10 @@
+{% assign item = site.gallery | where:'name', page.gallery | first %}
- {% capture gallery %}{{ page.url|replace:'/slideshow.html',''|remove_first:'/' }}{% endcapture %}
{{ page.title }}
-
+
@@ -40,24 +40,27 @@
}
-
{{ page.title }}
- {% loopdir path:gallery match:"*.md" sort:"ordering" %}
+ {% endif %}
+ {% endfor %}
diff --git a/_plugins/gallery.rb b/_plugins/gallery.rb
new file mode 100644
index 0000000..5778d13
--- /dev/null
+++ b/_plugins/gallery.rb
@@ -0,0 +1,27 @@
+module Jekyll
+ class GalleryPage < Page
+ def initialize(site, gallery, layout)
+ @site = site
+ @dir = gallery.url
+ @name = layout + '.html'
+ self.process(@name)
+ self.read_yaml(File.join(site.source, '_layouts'), 'gallery-' + layout + '.html')
+ self.data.merge!( gallery.data)
+ self.data['gallery'] = gallery.url.split('/')[2]
+ self.data['layout'] = 'gallery-' + layout
+ end
+ end
+
+ class GalleryPageGenerator < Generator
+ def generate(site)
+ site.collections['gallery'].docs.each do |gallery|
+ if gallery.respond_to?('map')
+ site.pages << GalleryPage.new(site, gallery, 'map')
+ end
+ if !gallery.respond_to?('slideshow')
+ site.pages << GalleryPage.new(site, gallery, 'slideshow')
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/_plugins/loopdir.rb b/_plugins/loopdir.rb
deleted file mode 100644
index 6ce33a0..0000000
--- a/_plugins/loopdir.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-# inspired by
-# - https://gist.github.com/jgatjens/8925165
-# - http://simon.heimlicher.com/articles/2012/02/01/jekyll-directory-listing
-
-module Jekyll
- class Loopdir < Liquid::Block
- include Liquid::StandardFilters
- Syntax = /(#{Liquid::QuotedFragment}+)?/
-
- def initialize(tag_name, markup, tokens)
- @attributes = {}
-
- @attributes['path'] = nil;
- @attributes['parse'] = 'true';
- @attributes['match'] = '*';
- @attributes['sort'] = 'path';
-
- markup.scan(Liquid::TagAttributes) do | key, value |
- if 'path' == key
- # path can be dynamic to support includes
- @attributes['path'] = Liquid::Variable.new(value)
- else
- @attributes[key] = value.gsub /"(.*)"/, '\1'
- end
- end
-
- if @attributes['path'].nil?
- raise SyntaxError.new("The `path` attribute is missing for `loopdir` tag.")
- end
-
- if 'true' == @attributes['parse']
- @attributes['parse'] = true
- else
- @attributes['parse'] = false
- end
-
- super
- end
-
- def render(context)
- context.registers[:loopdir] ||= Hash.new(0)
-
- items = []
-
- path = @attributes['path'].render(context)
-
- Dir.glob(File.join(path, @attributes['match'])).each do |pathname|
- if @attributes['parse']
- item = {}
-
- content = File.read(pathname)
-
- if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
- content = $POSTMATCH
-
- begin
- item = YAML.load($1)
- rescue => e
- puts "YAML Exception reading #{name}: #{e.message}"
- end
- end
-
- item['content'] = content
- else
- context['item'] = pathname
- end
-
- item['name'] = File.basename(pathname, @attributes['match'].sub('*', ''))
- item['fullname'] = pathname.gsub(/\.[^\.]+$/, '')
- item['path'] = pathname
-
- items.push item
- end
-
- sortby = @attributes['sort'].gsub(/^-/, '')
-
- items.sort! do | x, y |
- x[sortby] <=> y[sortby]
- end
-
- if sortby != @attributes['sort']
- items.reverse!
- end
-
- context.stack do
- result = []
-
- items.each do | item |
- context['item'] = item
-
- result << render_all(@nodelist, context)
- end
-
- result
- end
- end
- end
-end
-
-Liquid::Template.register_tag('loopdir', Jekyll::Loopdir)
diff --git a/_scripts/convert-galleries.php b/_scripts/convert-galleries.php
new file mode 100644
index 0000000..5563c44
--- /dev/null
+++ b/_scripts/convert-galleries.php
@@ -0,0 +1,96 @@
+ 0 ? max($oEndDate, $aPhoto['date']) : $aPhoto['date'];
if (isset($aPhoto['exif']['Make'])) {
- $aMatter['exif']['make'] = $aPhoto['exif']['Make'];
+ $aMatter['make'] = $aPhoto['exif']['Make'];
if (isset($aPhoto['exif']['Model'])) {
$aMatter['model'] = $aPhoto['exif']['Model'];
}
@@ -294,42 +294,7 @@ $oConsole
);
$oOutput->writeln(' done');
}
-
- // Write slideshow
- $bSlideshow = isset($aGallery['slideshow']) ? $aGallery['slideshow'] : true;
- if ($bSlideshow) {
- $oOutput->write('slideshow ');
- $aMatter = [
- 'layout' => 'gallery-slideshow',
- 'title' => empty($aGallery['title']) ? '' : $aGallery['title']
- ];
- file_put_contents(
- $sRenderPath . '/slideshow.html',
- '---' . "\n" . yamlDump($aMatter) . '---' . "\n"
- );
- $oOutput->writeln(' done');
- }
- // Write map
- $bMap = count($aLongitude) > 0 && (isset($aGallery['map']) ? $aGallery['map'] : true);
- if ($bMap) {
- $oOutput->write('map ');
- $aMatter = [
- 'layout' => 'gallery-map',
- 'title' => empty($aGallery['title']) ? '' : $aGallery['title'],
- 'gallery_map' => [
- 'latitude' => array_sum($aLatitude) / count($aLatitude),
- 'longitude' => array_sum($aLongitude) / count($aLongitude),
- 'zoom' => 8
- ]
- ];
- file_put_contents(
- $sRenderPath . '/map.html',
- '---' . "\n" . yamlDump($aMatter) . '---' . "\n"
- );
- $oOutput->writeln(' done');
- }
-
// Write gallery index
$oOutput->write('index ');
$aMatter = [
@@ -338,9 +303,11 @@ $oConsole
'highlight_photo' => empty($sHighlight) ? $aPhotos[0]['id'] : $sHighlight,
'date' => $oDate->format('Y-m-d')
];
+ $bSlideshow = isset($aGallery['slideshow']) ? $aGallery['slideshow'] : true;
if (!$bSlideshow) {
$aMatter['slideshow'] = false;
}
+ $bMap = count($aLongitude) > 0 && (isset($aGallery['map']) ? $aGallery['map'] : true);
if (!$bMap) {
$aMatter['map'] = false;
}
@@ -359,8 +326,7 @@ $oConsole
$sRenderPath . '/index.html',
'---' . "\n" . yamlDump($aMatter) . '---' . "\n" . $sContents
);
- $oOutput->writeln(' done');
-
+ $oOutput->writeln(' done');
}
);
diff --git a/gallery/index.html b/gallery/index.html
index aec538a..ff5ba4e 100644
--- a/gallery/index.html
+++ b/gallery/index.html
@@ -8,16 +8,18 @@ layout: default
- {% loopdir path:"gallery" match:"*/index.html" sort:"-date" %}
- {% if item.ignore == null %}
+{% assign items = site.gallery | sort:'date' | reverse %}
+{% for item in items %}
+ {% if item.ignore == null %}
+ {% assign name = item.id | split:'/' | last %}
- {% endif %}
- {% endloopdir %}
+ {% endif %}
+{% endfor %}
diff --git a/index.html b/index.html
index d35979a..442f1ff 100644
--- a/index.html
+++ b/index.html
@@ -1,19 +1,16 @@
---
title: Home
-layout: default
tags: blog scotland chemistry phd
+layout: default
---
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 oude versie van dit blog.
-
{% for post in paginator.posts %}
- {% include post_detail.html %}
+ {% include post-detail.html %}
{% endfor %}
-
-
{% if paginator.total_pages > 1 %}