Skip to content

Instantly share code, notes, and snippets.

@anolson
Created June 7, 2012 14:32
Show Gist options
  • Save anolson/2889110 to your computer and use it in GitHub Desktop.
Save anolson/2889110 to your computer and use it in GitHub Desktop.
Create a static website out of a tree of files (pdf)
<html>
<head>
<link rel=stylesheet href="/style/screen.css" media="screen" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><%= @path %></title>
</head>
<body>
<div id="wrap">
<div id="content">
<h1><%= @name %></h1>(articles)
<% @entries.each do |child| %>
<div class="item hentry">
<a href="<%= child %>" title="<%= child %>"><%= child %></a>
</div>
<% end %>
</div>
<div id="footer">footer crap here</div>
</div>
</body>
</html>
<html>
<head>
<link rel=stylesheet href="/style/screen.css" media="screen" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><%= @path %></title>
</head>
<body>
<div id="wrap">
<div id="content">
<h1><%= @name %></h1>(navigation)
<% @entries.each do |child| %>
<div class="item hentry">
<a href="<%= child %>" title="<%= child %>"><%= child %></a>
</div>
<% end %>
</div>
<div id="footer">footer crap here</div>
</div>
</body>
</html>
#!/usr/bin/ruby
require 'erb'
class IndexPage
FILES_TO_EXCLUDE = /^[.]+|([a-z]+((.txt)|(.html)))/
attr_reader :path, :name, :children
def initialize(path)
@path = path
@name = path.split('/').last
@children = Dir.new(path).entries
@entries = @children.select{|v| v !~ FILES_TO_EXCLUDE}
end
def get_binding
binding
end
def is_leaf?
@children.select{ |v| v =~ /(info.txt)/ }.size > 0
end
end
def create_index_page(path)
puts "Creating index page for #{path}"
template=nil
page = IndexPage.new(path)
if page.is_leaf?
template = IO.read(File.expand_path "articles.rhtml")
else
template = IO.read(File.expand_path "navigation.rhtml")
end
rhtml = ERB.new(template, 0, ">")
File.open(path + "/index.html", "w") do |file|
file.write(rhtml.result(page.get_binding))
end
end
all_files=File.join("**", "**")
Dir.glob(all_files).select{ |item| File.directory? item }.each { |dir|
create_index_page dir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment