[enhancement] priority rule for tailoring too-long filenames

Bug #821935 reported by Netsaver Paul on 2011-08-06
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Undecided
Unassigned

Bug Description

Having a composite filename which occasionally could run over 250 chars size:
{title:shorten(70,_,30)} - {author},{pubdate}
it would be better sometimes not (only) to shorten a single field, but to establish a priority among fields, i.e.
{title:p1} - {author:p2},{pubdate:p3}, so that shortening starts from secondary fields (pubdate).
Much better is also avoiding shortening of directory names, otherwise there could be an explosion of similar subdirs.
Thanks and regards,
Netsaver

Related branches

Charles Haley (cbhaley) wrote :

Can't do it the way you ask. The individual template items are evaluated separately, then combined together. At that point the priority information, which would need to be in the form of a function, would be lost.

I have added a new template function, strcat_max, that does what you want in a different way. The documentation for the new function is:
strcat_max(max, string1, prefix2, string2, ...)`` -- Returns a string formed by concatenating the arguments. The returned value is initialized to string1. `Prefix, string` pairs are added to the end of the value as long as the resulting string length is less than `max`. String1 is returned even if string1 is longer than max. You can pass as many `prefix, string` pairs as you wish

You would use something like:
{:'strcat_max(100, field('title'), ' - ', field('author'), ',', field('pubdate'))'}

You might want to 'shorten' the first argument(title).

Changed in calibre:
status: New → Fix Committed

Fixed in branch lp:calibre. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers