@@ -1,5 +1,6 @@
require 'date'
require 'rubygems'
require 'mini_magick'
require 'exifr'
# What we need:
# Git, Java, Convert (Image magic) exifr
@@ -9,7 +10,7 @@ require 'exifr'
# I don't really plan to rewrite it to be so either.
desc "Compile"
task :default => [ :prep , :generate_gallery , :compile ]
task :default => [ :prep , :generate_thumbs , : generate_gallery, :compile ]
desc "Setup the env"
task :prep do
@@ -40,207 +41,249 @@ task :commit do
sh "rm -rf /tmp/7tharochdale.org.uk/"
end
task :server => [ :prep , :generate_gallery , :run_server ]
task :server => [ :prep , :generate_thumbs , : generate_gallery, :run_server ]
desc "Run local server"
task :run_server do
Dir . chdir ( "/tmp/7tharochdale.org.uk/" )
sh "jekyll --auto --server"
#sh "rm -rf /tmp/7tharochdale.org.uk/"
sh "rm -rf /tmp/7tharochdale.org.uk/"
end
task :generate_thumbs do
Dir [ '/tmp/7tharochdale.org.uk/content/assests/gallery/images/**/*.png' ,
'/tmp/7tharochdale.org.uk/content/assests/gallery/images/**/*.jp*g' ] . each do |img |
image = MiniMagick ::Image . open ( img )
image . resize "150X150"
new_path = img . sub ( "/gallery/images/" , "/gallery/image_thumbnails/" )
new_dir = File . dirname ( new_path )
sh "mkdir -p #{ new_dir } "
image . write ( new_path )
end
Dir [ '/tmp/7tharochdale.org.uk/content/assests/gallery/video**/*.flv' ,
'/tmp/7tharochdale.org.uk/content/assests/gallery/video**/*.m4v' ,
'/tmp/7tharochdale.org.uk/content/assests/gallery/video**/*.swf' ,
'/tmp/7tharochdale.org.uk/content/assests/gallery/video**/*.mp4' ] . each do |video |
new_path = video . sub ( "/gallery/video/" , "/gallery/video_splash/" )
new_dir = File . dirname ( new_path )
sh "mkdir -p #{ new_dir } "
sh "ffmpeg -i #{ video } -r 1 -ss 00:00:05 -s 598x370 -an -qscale 1 #{ new_path } .png; exit 0"
end
end
task :generate_gallery do
Dir . chdir ( "/tmp/7tharochdale.org.uk/" )
albums = { }
base_url = "{{ site.basedomain }}"
thumbnail_url = "/assests/gallery/image_thumbnails"
gallery_url = "/assests/gallery/images"
gallery_data = "/gallery"
Dir [ 'content/assests/gallery/images/**/*.png' , 'content/assests/gallery/images/**/*.jp*g' ] . each do |file |
img = file . sub ( "content/assests/gallery/images/" , "" )
dir = File . dirname ( img )
name = img . sub ( dir , "" )
ext = File . extname ( file )
index_path = "content/#{ gallery_data } /#{ img } .html"
if ext == ".png"
image = EXIFR ::PNG . new ( file )
elsif ext == ".jpeg" or ext == ".jpg"
image = EXIFR ::JPEG . new ( file )
end
description = image . comment
if description == nil
description = name
end
full_url = "/assests/gallery/images"
gallery_path = "/gallery"
Dir [ 'content/assests/gallery/images/**/*' ] . each do |obj |
if File . directory? ( obj )
dir = obj . sub ( "content/assests/gallery/images/" , "" )
if albums [ dir ] == nil
albums [ dir ] = { }
albums [ dir ] = { }
albums [ dir ] [ "name" ] = dir . sub ( "_" , " " )
albums [ dir ] [ "folder" ] = dir
albums [ dir ] [ "url" ] = base_url + gallery_path + "/" + dir
parent = dir . split ( "/" ) [ 0 ..-2 ] . join ( "/" )
if parent == ""
albums [ dir ] [ "parent" ] = "Gallery"
albums [ dir ] [ "parent_url" ] = base_url + gallery_path
else
albums [ dir ] [ "parent" ] = parent
albums [ dir ] [ "parent_url" ] = base_url + gallery_path + "/" + parent
end
albums [ dir ] [ name ] = { }
albums [ dir ] [ name ] [ 'url' ] = base_url + gallery_data + "/" + img
albums [ dir ] [ name ] [ 'desc' ] = description
albums [ dir ] [ name ] [ 'name' ] = name
albums [ dir ] [ name ] [ 'thumb' ] = base_url + thumbnail_url + "/" + img
albums [ dir ] [ "images" ] = { }
end
next
end
img = obj . sub ( "content/assests/gallery/images/" , "" )
dir = File . dirname ( img )
name = File . basename ( img )
ext = File . extname ( obj )
if ext == ".png"
image = EXIFR ::PNG . new ( obj )
elsif ext == ".jpeg" or ext == ".jpg"
image = EXIFR ::JPEG . new ( obj )
else
next # We don't support this
end
description = image . comment
if description == nil
description = name
end
sh "mkdir -p content/gallery/#{ dir } "
albums [ dir ] [ "images" ] [ name ] = { }
albums [ dir ] [ "images" ] [ name ] [ 'url' ] = base_url + gallery_path + "/" + img
albums [ dir ] [ "images" ] [ name ] [ 'desc' ] = description
albums [ dir ] [ "images" ] [ name ] [ 'name' ] = name
albums [ dir ] [ "images" ] [ name ] [ 'gallery' ] = dir
albums [ dir ] [ "images" ] [ name ] [ 'thumb' ] = base_url + thumbnail_url + "/" + img
# Write out the sngle page (we deal with album indexes later)
fdata = <<EOS
------------
sh "mkdir -p content/gallery/#{ dir } "
# Write out the sngle page (we deal with album indexes later)
fdata = <<EOS
---
layout: default
title: #{ description }
------------
title: #{ description . sub ( ":" , "" ) }
---
<div class="gallery_single">
<img src="#{ base_url } /#{ gallery_url } /#{ img } " alt="#{ description } " />
<p class="description">#{ description } </p>
<img src="#{ base_url } /#{ full_url } /#{ img } " alt="#{ description } " />
<p class="description">#{ description } </p>
<p class="linkback">Back to <a href="#{ base_url } /#{ gallery_path } /#{ dir } ">#{ dir } </a></p>
</div>
<div id="comments>
<iframe src="http://www.facebook.com/plugins/like.php?href={{ site.basedomain }}/{{ page.url }}&
layout=standard&show_faces=false&width=450&action=like&font=verdana&colorscheme=light&"
height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;"
allowTransparency="true"></iframe>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<div id="comments">
<script type="text/javascript">fb_like('{{ site.basedomain }}/{{ page.url }}');</script>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
EOS
puts "Writing out image page (#{ index_path } )"
fh = File . open ( index_path , "w" )
fh . write ( fdata )
fh . close
# Write out this image index
index_path = "content/#{ gallery_path } /#{ img } .html"
fh = File . open ( index_path , "w" )
fh . write ( fdata )
fh . close
end
# Build up the ablum index the write it to disk
albums . each do |album , images |
name = album . sub ( "_" , " " )
dir = "content/#{ gallery_data } /#{ album } /"
adata = ""
adata += <<EOS
------------
## Now we loop over the album array and generate there indexes....
albums . each do |i , album |
adata = <<EOS
---
layout: default
title: #{ name }
------------
title: Gallery #{ album [ " name" ] }
---
<div class="gallery_album_subalbums ">
<div class="gallery_album_images ">
EOS
# Build out the sub albums list
Dir [ "content/#{ gallery_data } /#{ album } /*" ] . reject { |o | not File . directory? ( o ) } . each do |dir |
path = dir . sub ( "content/#{ gallery_data } /#{ album } /" , "" )
dname = path . sub ( "_" , " " )
adata += <<EOS
<p><a href="#{ base_url } /#{ gallery_data } /#{ path } /">#{ base_url } /#{ gallery_data } /#{ dname } /</a></p>
# Build out the images list
images = album [ "images" ]
images . each do |i , image |
adata += <<EOS
<p><a href="#{ image [ "url" ] } "><img src="#{ image [ "thumb" ] } " alt="#{ image [ "desc" ] } " /></a><br />#{ image [ "desc" ] } </p>
EOS
end
end
adata += <<EOS
adata += <<EOS
<p class="linkback">Back to <a href="#{ album [ "parent_url" ] } ">#{ album [ "parent" ] } </a></p>
</div>
<div class="gallery_album_images">
EOS
# Build out the images list
images . each do |name , image |
adata += <<EOS
<p><a href="#{ image [ "url" ] } ">#{ image [ "thumb" ] } </a><br />#{ image [ "desc" ] } </p>
if Dir [ "content/#{ gallery_path } /#{ album [ "name" ] } /*" ] . reject { |o | not File . directory? ( o ) } . length > 0
adata += <<EOS
<div class="gallery_album_subalbums">
<h3>Sub albums</h3>
EOS
# Build out the sub albums list
Dir [ "content/#{ gallery_path } /#{ album [ "name" ] } /*" ] . reject { |o | not File . directory? ( o ) } . each do |dir |
path = dir . sub ( "content/#{ gallery_path } /" , "" )
dname = path . split ( "/" ) [ 1 ..-1 ] . join ( "/" ) . sub ( "_" , " " ) . sub ( /^(\w )/ ) { |s | s . capitalize }
adata += <<EOS
<p><a href="#{ base_url } /#{ gallery_path } /#{ path } /">#{ dname } </a></p>
EOS
end
end
adata += <<EOS
adata += <<EOS
</div>
EOS
end
<div id="comments>
<iframe src="http://www.facebook.com/plugins/like.php?href={{ site.basedomain }}/{{ page.url }}&
layout=standard&show_faces=false&width=450&action=like&font=verdana&colorscheme=light&"
height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;"
allowTransparency="true"></iframe>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
adata += <<EOS
<div id="comments">
<script type="text/javascript">fb_like('{{ site.basedomain }}/{{ page.url }}');</script>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
EOS
# Write the index page
index_path = "content/#{ gallery_data } /#{ album } /index.html"
puts "Writing out album page (#{ index_path } )"
fh = File . open ( index_path , "w" )
fh . write ( adata )
fh . close
# Write the index page
index_path = "content/#{ gallery_path } /#{ album [ "folder" ] } /index.html"
fh = File . open ( index_path , "w" )
fh . write ( adata )
fh . close
end
# Write out the gallery index
adata = <<EOS
------------
# Now write out teh final index - the gallery!
adata = <<EOS
---
layout: default
title: Gallery
------------
---
<div class="gallery_album_subalbums">
EOS
Dir [ "content/#{ gallery_data } /*" ] . reject { |o | not File . directory? ( o ) } . each do |dir |
path = dir . sub ( "content/#{ gallery_data } /" , "" )
dname = path . sub ( "_" , " " )
Dir [ "content/#{ gallery_path } /*" ] . reject { |o | not File . directory? ( o ) } . each do |dir |
path = dir . sub ( "content/#{ gallery_path } /" , "" )
dname = path . sub ( "_" , " " )
adata += <<EOS
<p><a href="#{ base_url } /#{ gallery_data } /#{ path } /">#{ base_url } / #{ gallery_data } / #{ dname } / </a></p>
<p><a href="#{ base_url } /#{ gallery_path } /#{ path } /">#{ dname } </a></p>
EOS
end
adata += <<EOS
adata += <<EOS
</div>
<div id="comments>
<iframe src="http://www.facebook.com/plugins/like.php?href={{ site.basedomain }}/{{ page.url }}&
layout=standard&show_faces=false&width=450&action=like&font=verdana&colorscheme=light&"
height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;"
allowTransparency="true"></iframe>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<div id="comments">
<script type="text/javascript">fb_like('{{ site.basedomain }}/{{ page.url }}');</script>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '7tharochdale';
var disqus_identifier = '{{ page.url }}';
var disqus_url = '{{ site.basedomain }}/{{ page.url }}';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
EOS
# Write the index page
index_path = "content/#{ gallery_data } /index.html"
puts "Writing out album page (#{ index_path } )"
fh = File . open ( index_path , "w" )
fh . write ( adata )
fh . close
end
# Write the index page
index_path = "content/#{ gallery_path } /index.html"
fh = File . open ( index_path , "w" )
fh . write ( adata )
fh . close
end
task :minify => [ :compile , :minify_assests ]
desc "Minify assests"
@@ -269,12 +312,12 @@ namespace "post" do
File . open ( path , 'w' ) do |file |
file . write <<-EOS
---
layout: post
title: #{ args . title }
tags: []
---
EOS
end
puts "Created #{ path } "
end
end