Skip to content

Commit

Permalink
Build YAML list of gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed Mar 2, 2014
1 parent d94fb21 commit 739cc14
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion script/build_site_index
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /usr/bin/env ruby

require 'builder'
require 'fileutils'
require 'yaml'

def dir_blacklist
["css", "sass", "script"]
Expand All @@ -17,20 +19,31 @@ def get_gif_dirs
Dir.foreach(".").map { |f| f unless useless?(f) }.compact
end

def liquid_info_for_file(dir, filename)
path = File.join(filename)
{
"path" => path,
"modified_time" => File.mtime(path).to_i,
"extname" => File.extname(path)
}
end

list = Builder::XmlMarkup.new(
target: File.open("_includes/site-index.html", 'w'),
indent: 0,
margin: 0
)

dirs = get_gif_dirs
dirs = get_gif_dirs
files = []

list.ul do |builder|
dirs.each do |dir|
builder.li do |dir_element|
dir_element.text!(dir)
dir_element.ul do |ul|
Dir.glob("#{dir}/*.gif") do |gif|
files << liquid_info_for_file(dir, gif)
ul.li do |li|
li.a(
File.basename(gif),
Expand All @@ -44,3 +57,6 @@ list.ul do |builder|
end
end
end

FileUtils.mkdir_p("_data") unless File.directory?("_data")
File.open("_data/static_files.yml", 'w') { |f| f.write(YAML.dump(files)) }

0 comments on commit 739cc14

Please sign in to comment.