A personal project to fix a minor annoyance that I've had for a while but should you have the same annoyance and find this useful, then the code is here under an MIT License so make use of it as you will. It is very much still under development so it may change beyond all recognition or, if I really lose my temper with it, disappear without warning.
Over the past few years, through purchases and give-aways from various online stores and event promos, I have found myself to be the proud owner of a big pile of e-books that live outside of Amazon's Kindle or Apple's iBooks platforms. A big old jumble of files on my computer. I find the file viewer less than helpful in keeping things organised and have occasionally, and I know I'm not alone in this as I've seen others on Twitter do the same, bought the same book twice having not realised I already owned it until the Save As dialogue asked if I wanted to replace an older file of the same name (uh oh!).
This is a place for me - hopefully with some help from my friends - to tinker with writing a command line script to generate a flat HTML page or 3 to help me keep track of my book collection. It's being worked on as an occasional side project alongside a full-time job so updates are likely to be infrequent and either in service of fixing a random thing that's bugging me or to try out a new idea I've recently read about. It will pander also pander to the idiosyncratic file structure that I've developed while trying to keep the file sprawl in check. We're deep in "scratch your own itch" territory here.
Oh and the use of flat files (CSS and JavaScript welcome, just no backend stuff) is a deliberate trick to allow the resulting file(s) to run right out of the filesystem rather than needing a webserver running in the background to quickly look something up. This restriction has caused some interesting problems, particularly around not being able to use JavasScript modules or certain kinds of include statements that are seen as cross-domain when served over file://
rather than http://
; I can't serve a source map, for example.
The basic current file structure inside my bookshelf
folder, which has changed slightly since starting the project, looks a bit like this (but longer, much, much longer)
├── A Little Riak Book
│ ├── _meta
│ │ ├── cover.jpg
│ │ └── info.js
│ ├── riaklil-en.epub
│ ├── riaklil-en.mobi
│ └── riaklil-en.pdf
├── The Little MongoDB Book
│ ├── Little_MongoDB_Book.pdf
│ └── _meta
│ ├── cover.jpg
│ └── info.js
As you can see, each book has it's own named folder containing the book file itself - or files plural if I own it in more than one format - and a _meta
folder containing a JSON file (currently generated by hand) containing stuff like - sorry to be so handwavy here, but this bit's very much under construction - the book's full title, the publisher, the authors (they're mostly tech books so having an array of authors seems logical), the ISBN (if it has one, some freebie "use my product!" books don't), the publisher, a notes field that's currently only used to highlight which edition/printing of Agile Web Development with Rails covers which Rails version but could be more generally useful. And a cover image, currently 160px high with a varying width as it turns out, as I should have been able to spot right away by turning round and looking at my actual book shelf, not all books are the same size (or even in the same aspect ratio), but I hate the screen jumping around as it loads so as it's my ************, I've arbitrarily declared 160px high to be a standard.
At some point, I'm going to need a Librarian app to manage the metadata and images. Manually creating JSON files and creating screenshot images is pretty annoying at scale (it turns out).
It also turns out that in some cases I own more than one edition/printing/version/whatevs of the same book. A recent addition to the file structure spec, therefore makes it look something like this...
├── Agile Web Development with Rails
│ ├── 4th Edition v3.0
│ │ ├── _meta
│ │ │ ├── cover.jpg
│ │ │ └── info.js
│ │ ├── book.epub
│ │ ├── book.mobi
│ ├── 4th Edition v3.1
│ │ ├── _meta
│ │ │ ├── cover.jpg
│ │ │ └── info.js
│ │ ├── book.mobi
│ │ └── book.pdf
Which allows me to a) group them in a way that looks reasonably sensible to me (and, as I said before - my files, my rules) and b) that stops the file list from getting cluttered up with "Book A v1", "Book A v2" and so on.
(As soon as I got this more or less working, Sandi Metz published a second edition of the excellent 99 Bottles of OOP which completely broke my folder structure and delivered an instant lesson in assumptions. I've cheated for now but at some point I need to sit down and figure out how to model an "edition" that has multiple variants of the book title, each with its own group of formats.)
Ok, sorry, probably should have done this bit sooner...
- Git clone your own copy of the repository
- Drop
assets
andapp
directories and theRakefile
into the top level directory of a folder structure that's arranged a bit like mine and has lots of books in it† - From the command line, navigate to the folder you copied the files into
- Install the prerequisites
- Let's assume you already have ruby
- Install the bundler gem (if you don't already have it) with
gem install bundler
(the version used by the project is at the end of theGemfile.lock
file) - Run
rake install
to install the bundled gems and npm
- Run the rake file to generate the HTML:
rake generate_index_file shelf="."
- Load the resulting index.html into your favourite browser
Tip: vary the value of shelf=
to change the target directory for the script
†If you don't have a folder with lots of books in it‡, you may have come to the wrong place
‡If you would like a folder with lots of books in it, may I suggest Project Gutenberg as a good starting point