benschwarz / bonsai

A tiny static web site generator
http://tinytree.info/
MIT License
297 stars 39 forks source link

children should be sorted #21

Closed pluskid closed 12 years ago

pluskid commented 12 years ago

children is not sorted currently.

.sort_by{|p| p.disk_path }

should be added to lib/bonsai/page.rb:105

benschwarz commented 12 years ago

children is sorted by name, which is probably the most logical way to do it. I was thinking just now that using a liquid filter would probably be the best way to customise what you get in your template.

benschwarz commented 12 years ago

Actually, children is sorted by whatever ruby (and the filesystem underneath) will return… on a mac, this is the equivalent of what you've suggested (from memory).

Otherwise, I'm happy to accept a patch (with a test) for this…

pluskid commented 12 years ago

Firstly, I would like to thank you for such useful tool. I like it very much.

Secondly, you mentioned in the doc "Bonsai will order your pages within the “navigation”, “children” and “siblings” arrays by the prefix given to its parent folder." (see http://tinytree.info/how-it-works/), so I guess you would like to either modify the doc or the code.

Unfortunately, the order of files returned by the OS is not guaranteed to have any order. In my system, it is random (actually, incidentally sorted based on the time I created them). That's why I found this problem in the code.

Finally, I'm new to liquid, and don't know whether there is a "sort" filter already available. It would be very nice if you put that into the bonsai doc. In particularly, currently I have no idea where to put the .rb file if I would like to write some customized filter for liquid.

Thanks again for this awesome utility!

benschwarz commented 12 years ago

I agree that the documentation needs updating… I haven't done so since updating to use liquid recently. I guess I was testing the waters—If you have some time available to update the site, I'll gladly accept a patch.

I just created bonsai 1.4.4 which adds an an interesting feature: loading of extensions.rb.

Basically, if you add a file named extensions.rb to your site root, bonsai will attempt to load it. You could place any liquid customisations in here… if you're interested in trailing the feature, I'd love to hear your thoughts.

pluskid commented 12 years ago

Hi, here again. I still think sorting the children is needed here. I hope you could modify your code as suggested above. Because the default order returned by directory listing from the OS is totally undefined. Being able to control the order of sub-levels of my sites is a required feature for me (and some other people I think). Thanks again!

pluskid commented 12 years ago

BTW: thanks for the extensions.rb, I'll try it recently, to refactor some of my page templates.

Unfortunately, I can't create a test or spec because I'm not familiar with the dev environment of bonsai. But the patch would be simple (just a one-line change as shown above). So it would be very easy for you to do this.