Skip to content

Commit

Permalink
img-index: a simple image gallery generator
Browse files Browse the repository at this point in the history
  • Loading branch information
robmiller committed Mar 20, 2022
1 parent 5147299 commit 819e229
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/img-index
@@ -0,0 +1,49 @@
#!/usr/bin/env ruby

require "pathname"
require "erb"

dir = ARGV[0] || Dir.pwd
dir = Pathname(dir)

images = dir.children.select { |f| %w(.png .jpg .jpeg .gif).include? f.extname }.map { |f| f.basename }

template = ERB.new(DATA.read)
puts template.result(binding)

__END__
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Index of <%= dir.basename %></title>
<style>
body {
background: #191919;
font-family: 16px/18px Georgia, serif;
color: #eee;
}

figure {
margin: 2em 0;
}

figure img {
width: 100%;
height: auto;
}

figcaption {
font-style: italic;
}
</style>
</head>
<body>
<% images.each do |image| %>
<figure>
<img src="<%= image %>" alt="<%= image %>">
<figcaption><%= image %></figcaption>
</figure>
<% end %>
</body>
</html>

0 comments on commit 819e229

Please sign in to comment.