Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow an album to be configured by info.json allowing supply of descr…

…iption, thumbnail and name. Resolves issue #4, resolves issue #5
  • Loading branch information...
commit 5d237161d1ef5a6408aa4847cc047c8088236d8d 1 parent 644588f
@cianclarke authored
View
14 README.md
@@ -7,6 +7,7 @@ NodeJS Photo Gallery. Feed it a directory of photos, get back a JSON object & a
* Image titles = Photo Titles
* EXIF title = Description
* Displays camera capture info (exposure, aperture, ISO..)
+* Optional album description, album thumbnail by info.json
Installation
============
@@ -17,6 +18,19 @@ Examples
===================
A usage example using node-gallery with Express can be found in app.js. It should be simple to use with a framework of your choice - EJS templates are included.
+Photos
+===================
+Photos are added to your specified 'directory', in the example "photos". Albums are created for every folder we encounter, and thumbnails are automatically generated by using the first image we come across in this album.
+An optional info.json file can be supplied in an album to supply:
+*Description* Plaintext album description, can contain HTML
+*Thumbnail* Override the default thumbnail we find for this album. Specified relative to the current album, so if it's a photo in the album 'image.jpg', and if it's in a child album 'childAlbumFolderName/image.jpg'
+*Name* Override the default album name we obtain from the directory. Won't reflect in the breadcrumb for now because of the way it's constructed - hoping to change this soon!
+ {
+ "description" : "Album <strongDescription</strong>.",
+ "thumbnail" : "North%20Coast/_MG_0925.jpg",
+ name: "Some Overriding Name"
+ }
+
Usage (ExpressJS)
===================
/*
View
29 gallery.js
@@ -96,6 +96,7 @@ var gallery = {
buildAlbums: function(files, cb){
var albums = {
name: this.name,
+ prettyName: this.name,
isRoot: true,
path: this.directory,
photos: [],
@@ -109,7 +110,7 @@ var gallery = {
dirHashKey = "",
curAlbum = albums; // reset current album to root at each new file
- // Iterate over its directory path, checking if we've got an album for each
+ // Iterate over it's directory path, checking if we've got an album for each
// ""!==dirs[0] as we don't want to iterate if we have a file that is a photo at root
for (var j=0; j<dirs.length && dirs[0]!==""; j++){
var curDir = dirs[j];
@@ -123,6 +124,7 @@ var gallery = {
var newAlbum = {
name: curDir,
+ prettyName: decodeURIComponent(curDir),
description: "",
hash: dirHashKey,
path: currentAlbumPath,
@@ -146,10 +148,25 @@ var gallery = {
}
}
path = file.rootDir + '/' + file.name
- if(file.name == "info.txt") {
+ if(file.name == "info.json") {
var fullPath = gallery.directory + "/" + path;
fullPath = (gallery.static) ? gallery.static + "/" + fullPath: fullPath;
- curAlbum.description = fs.readFileSync(fullPath);
+ var info = fs.readFileSync(fullPath);
+ try{
+ info = JSON.parse(info);
+ }catch(e){
+ // If invalid JSON, just bail..
+ continue;
+ }
+ curAlbum.description = info.description || null;
+ curAlbum.prettyName = info.name || curAlbum.prettyName;
+
+ if (info.thumb || info.thumbnail){
+ var thumbnailImage = info.thumb || info.thumbnail;
+ thumbnailImage = curAlbum.path + "/" + thumbnailImage;
+ curAlbum.thumb = thumbnailImage;
+ }
+
} else {
var photoName = file.name.replace(/.[^\.]+$/, "");
var photo = {
@@ -178,7 +195,11 @@ var gallery = {
// Function to iterate over our completed albums, calling _buildThumbnails on each
function _recurseOverAlbums(al){
- al.thumb = _buildThumbnails(al);
+
+ if (!al.thumb){
+ al.thumb = _buildThumbnails(al); // only set this album's thumbanil if not already done in info.json
+ }
+
if (al.albums.length>0){
for (var i=0; i<al.albums.length; i++){
_recurseOverAlbums(al.albums[i]);
View
5 resources/photos/Ireland/info.json
@@ -0,0 +1,5 @@
+{
+ "description" : "Photos of Ireland.",
+ "thumbnail" : "North%20Coast/_MG_0925.jpg",
+ "name": "Ireland"
+}
View
6 views/album.ejs
@@ -10,7 +10,7 @@
<% } %>
<% } %>
-<h1><%= album.name %></h1>
+<h1><%= album.prettyName %></h1>
<% if (album.description){ %>
<p><%- album.description %></p>
<% } %>
@@ -21,8 +21,8 @@
<% album.albums.forEach(function(album){ %>
<li class="thumb">
<a href="<%= rootDir%>/<%= album.path%>">
- <div class="image"><img src="/<%= directory %>/<%= album.thumb %>" alt="<%= album.name%>"><br /></div>
- <span class="caption"><%= album.name%></span>
+ <div class="image"><img src="/<%= directory %>/<%= album.thumb %>" alt="<%= album.prettyName %>"><br /></div>
+ <span class="caption"><%= album.prettyName %></span>
</a>
</li>
<% }) %>
Please sign in to comment.
Something went wrong with that request. Please try again.