My friend, Ricardo, created a photo gallery generator called
jgal that I've grown accustomed to using. Up until a couple
of weeks ago jgal has been working, giving errors, but still working. However,
It seems that a recent update to slackware-current has finally broken jgal
beyond use. Well, not beyond use, but it no longer re-sized the slide images
and thumbnails to their smaller size and instead leaves them all full size. I
can fix this my manually resizing the image files. Or, even better, I could
try to fix jgal for him and then give him the fix. The only trouble with that
is jgal is written in perl, which I know essentially nothing about. So, I
thought I'd take it upon myself to write up something that spits out the same
thing as jgal, but using the only thing I know at the moment which is bash.
So far I have all of the features that I use working. Those being:
- Image Captions
- Forcing thumbnail and slide regeneration
- Changing the default index file name
- Using image caption for the slide titles, striping out the HTML tags
- Linking directly to the image and not creating HTML slide files
- Scaling of thumbnails and slide images
Now, I must say, this is probably the most educational thing I've done and the
biggest thing I've ever written. So, I'm sure it's not written particularly
well, but thus far, it works. Which is what I want. Of course, it's slow
compared to jgal but it's not horrifically slow.
The big hurtle I ran into was generating the table to be put in the index
template. I used a place holder
<!--INDEX-TABLE--> in the
template with the idea that I could use sed to insert the table. I could send
the HTML to the screen and have it look right, but then sed would choke on it.
I even had the special characters escaped properly. And you wouldn't believe
how difficult it is to get an answer other than "use perl" when asking for help
in forums! I know, perl is easier, but only if you actually
know perl
in the first place. I needed a solution using something that I sort of knew,
and it just didn't make any sense that sed or awk was not capable of doing what
I wanted. Ultimately, the problem was me using the search command in sed. It
just didn't like the multiple lines and would complain about an improperly
terminated search string or something like that. I had a working function
called
indextd that spit out the HTML. After much prying and
reminding that I don't know perl I finally got a decent suggestion, use the
Change command like so:
sed "/<\!--INDEX-TABLE-->/c\
\\$(indextd)
"
The c\ is the change command and the \\ preserves the leading spaces in the
replacement text.
Oh, something else I learned is that it seems sed doesn't know how to do a
non-greedy match with a regular expression. In trying to strip off the HTML of
the captions to be used in the page title I tried
s/<.*?>//g
but sed was unhappy with that. What does work is
s/<[^>]*>//g which essentially says that the match can't
include the end of it in the middle anywhere. So, it only matches the complete
tags and not the first tag it sees, the last tag it sees, and everything in the
middle.
Anyway, I'm going to keep working on this script, even just for the learning
experience. Plus when I'm done I'll have a practical utility.
One day I'll have to learn perl. bash+sed+grep can't do everything, but for my purposes
they do most everything that I want at this time.