<tantalum>
ddfreyne, Are you around? Can I ask some questions about #438
<tantalum>
*Issue #438
pkunc has quit [Quit: Leaving.]
cDlm_ has quit [Read error: Connection reset by peer]
cDlm_ has joined #nanoc
pkunc has joined #nanoc
<ddfreyne>
tantalum: Hi! Sorry, I'm kinda swamped (but thank God for the weekend)
<ddfreyne>
tantalum: What's your question?
<tantalum>
Well I have it figured out now
<tantalum>
I was having an issue calling the sass compiler directly, per issue #438
<tantalum>
I got around the issue by making a mock filter that implemented an empty `imported_filename_to_item` function and passed that as the `nanoc_current_filter` when I was compiling the sass files
<tantalum>
it seems to work and fix the issue until the real fix you implemented is merged into a release
cDlm__ has joined #nanoc
cDlm_ has quit [Ping timeout: 246 seconds]
cDlm__ has quit [Ping timeout: 240 seconds]
cDlm__ has joined #nanoc
pkunc has quit [Quit: Leaving.]
pkunc has joined #nanoc
pkunc has quit [Quit: Leaving.]
pkunc has joined #nanoc
pkunc has quit [Quit: Leaving.]
smkelly has quit [Quit: Goodbye]
tantalum has quit [Ping timeout: 260 seconds]
smkelly has joined #nanoc
daf_I443 has joined #nanoc
<daf_I443>
Heloo all
<daf_I443>
I have a Nanoc question I could use some help with
<bobthecow>
hey daf_I443
<daf_I443>
Hi
<daf_I443>
Hoping someone with a bit more knowledge can give me a hand here
<daf_I443>
So far I have it generating thumbnails, but I need a few exceptions for my site which are troubling me.
<daf_I443>
First of all, my /assets/-folder holds images and other filters (c-source, zip files etc). I obviously want those filtered and not passed to the thumbnailizer.
<daf_I443>
I've set up a case construction in the compile rule which triggers on the file extension, this seems to be working fine.
tantalum has joined #nanoc
<daf_I443>
All thumbnails in an article should be 500px wide, except the first thumbnail which should be 200px wide. How would I filter that one out so I can pass it to the filter with the ':width 200' argument instead of the usual ':width 500'?
<bobthecow>
how do you know which is the first thumbnail in the article?
<daf_I443>
We'll, for now I name that frontpage.jpg, but maybe there are more clever ideas.
<bobthecow>
nanoc tends to work best if you don't try to make things clever :)
<daf_I443>
:-)
<bobthecow>
for example, if you have a bunch of things that need to be thumbnailed, put 'em in a folder called "thumbnail"
<bobthecow>
then use file matches rather than complicated code to decide what to do.
<daf_I443>
I'd rather avoid that, since it burdens the insertion of links in my articles.
<bobthecow>
nope nope
<bobthecow>
you don't have to include that folder name in the routes.
<bobthecow>
just in the source.
<daf_I443>
I'd rather write [link](/assets/image.jpg) and [link](/assets/these-files-are-excluded-from-thumbnailing/code.c) if you know what I mean...
<bobthecow>
not really.
<bobthecow>
but those links don't have to match the source folders.
<bobthecow>
for example...
<bobthecow>
if you have a site with /assets/style.css, /assets/script.js, etc
<bobthecow>
say there are several css and js files that you need to process, all of which you want to live under /assets/
<bobthecow>
you *could* make a really complex rule for /assets/* that uses extensions and stuff to figure out how to compile and route all of them.
<bobthecow>
or you could make the source folder actually /content/assets/style/... and /content/assets/script/...
<bobthecow>
make your compile rules use /assets/style/* and /assets/script/*
<daf_I443>
I understand.
<bobthecow>
and have your routing rules strip out the /script/ and /style/
<bobthecow>
so the links to those are the original links.
<bobthecow>
but the source doesn't have to be.
<daf_I443>
So you suggets I make different folders under /assets/postxxx/ called /images,/frontpage_image, /other?
<bobthecow>
similar thing with your thumbnails. you could try to do something clever, or you could use the source directory or filename to indicate how you want to handle it.
<bobthecow>
i usually do it the other way.
<bobthecow>
under /assets/.../post
<bobthecow>
but you should optimize for whatever makes it easiest for you to work with.
<daf_I443>
Sounds like that would work but would mean a lot of navigating folders when writing posts
<bobthecow>
if you want all the assets for a post to be together, your way would be better.
<daf_I443>
I prefer that yes.
<daf_I443>
Let me ask a different question
<daf_I443>
Suppose I want to check in a compile rule if the filename of an item starts with 'Frontpage', how would I do that?
<bobthecow>
this is what i'm saying, don't build complicated code-based compile rules, just use the filenames and paths to decide what to do.
<bobthecow>
since that's ultimately what you're doing anyway.
<daf_I443>
Ok, give me a minute to wrap my head (and code) around that...
<bobthecow>
you're just recreating all the stuff that nanoc already does for deciding how to compile files, but you're doing it in a more fragile and less well tuned way :)
<daf_I443>
So I could do the following:
<daf_I443>
compile '/assets/*/', :rep => :thumbnail do case item[:extension] when 'JPG' filter :thumbnailize, :width => 500 end end compile '/assets/*/Frontpage*/', :rep => :thumbnail do case item[:extension] when 'JPG' filter :thumbnailize, :width => 200 end end
<bobthecow>
you have to match the more specific one firs.t
<bobthecow>
otherwise, yeah.
<daf_I443>
If I match the more specific first, would the more general rule overwrite the previous output?
<bobthecow>
no, it takes the first match.
<bobthecow>
so you put generic rules last.
<bobthecow>
same way routing works in rails, for example.
<bobthecow>
or symfony, or whatever framework you're familiar with.
<daf_I443>
Wouldn't know, you're dealing with an old C/C++ programmer here so sorry for the dim questions :-)
<bobthecow>
heh. no worries at all :)
<daf_I443>
I feel comfortable programming firmware for microcontrollers though that doesn't quite help me here :-)
<daf_I443>
Ok, let me try to compile this.
<daf_I443>
Another questiojn; can I stack when statements in a case?
<daf_I443>
like this:
<daf_I443>
case item[:extension]
<bobthecow>
when foo, bar
<daf_I443>
when 'JPG'
<daf_I443>
when 'jpg'
<daf_I443>
when 'gif'
<daf_I443>
filter :thumbnailize, :width => 200
<daf_I443>
end
<bobthecow>
when 'JPG', 'jpg', 'gif'
<daf_I443>
ok :-)
<bobthecow>
you can do your case on item[:extension].downcase and save yourself some of those whens though.
<daf_I443>
(compiling)
<daf_I443>
It starts smelling like progress in here
<bobthecow>
great!
pkunc has joined #nanoc
<daf_I443>
Let me test it first
<daf_I443>
And then I'll have a follow-up question :-)
<daf_I443>
Cool, that seems to work!
<daf_I443>
I have:
<daf_I443>
ompile '/assets/*/Frontpage*/', :rep => :thumbnail do case item[:extension].downcase when 'jpg', 'gif', 'png' filter :thumbnailize, :width => 200 end end
<daf_I443>
compile '/assets/*/', :rep => :thumbnail do case item[:extension].downcase when 'jpg', 'gif', 'png' filter :thumbnailize, :width => 500 end end
<daf_I443>
route '/assets/*/', :rep => :thumbnail do item.identifier.chop + ' thumb.' + item[:extension] end
<daf_I443>
Thanks for helping me with that; that was easy!
<daf_I443>
Now for my follow-up question: is there an easy wayt to automatically link image thumbnails to the full-resolution version?
<bobthecow>
you'll probably want to put the same case inside your route rule as well
<daf_I443>
I usually write: ![ALT](/assets/Running the Mespelare firmware/Clipboard09.jpg)
<bobthecow>
otherwise it'll try to make a "thumbnail" of everything even if it's not an image
<daf_I443>
Ah ok...
<daf_I443>
Like this?
<daf_I443>
route '/assets/*/', :rep => :thumbnail do case item[:extension].downcase when 'jpg', 'gif', 'png' item.identifier.chop + ' thumb.' + item[:extension] end end
<bobthecow>
yep
<daf_I443>
I'll include that. Seemed to work without it though...
<bobthecow>
right. you wouldn't notice
<daf_I443>
:-)
<bobthecow>
you'd just get files overwriting themselves from other rules
<bobthecow>
or you'd get extra files.
<daf_I443>
Sounds like a waste of cycles...
<bobthecow>
yep.
<bobthecow>
so only route things you intend to route
<bobthecow>
mostly it's only an issue for reps
<daf_I443>
Now to my other question: is there a way to make this Ma'rkdown ![](/assets/post/Clipboard09.jpg)
<daf_I443>
render as <a href="/assets/post/Clipboard09.jpg"><img href="/assets/post/Clipboard09.jpg"></a>
<daf_I443>
instead of <img href="/assets/post/Clipboard09 thumb.jpg">?
<bobthecow>
you could use a filter to post-process it,
<daf_I443>
How would I go about that?
<bobthecow>
check out the relativize_links filter in the nanoc source
<bobthecow>
that's a fairly straightforward one.
<bobthecow>
you'd do something similar, basically look for image tags and wrap them in links.
<bobthecow>
but in your case, probably only if they start with /assets/post/ or something?