From 6f45344847a544542c54e8ddcf8fb03dd567af6c Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 3 Oct 2010 14:54:06 +0100 Subject: [PATCH] Add tweak to change articles in title sort pattern --- resources/default_tweaks.py | 9 +++++++++ src/calibre/ebooks/metadata/__init__.py | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 3b60e3410e..17ed0eeea7 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -83,6 +83,15 @@ title_series_sorting = 'library_order' # strictly_alphabetic, it would remain "The Client". save_template_title_series_sorting = 'library_order' +# Set the list of words that are to be considered 'articles' when computing the +# title sort strings. The list is a regular expression, with the articles +# separated by 'or' bars. Comparisons are case insensitive, and that cannot be +# changed. Changes to this tweak won't have an effect until the book is modified +# in some way. If you enter an invalid pattern, it is silently ignored. +# Default: '^(A|The|An)\s+' +title_sort_articles='^(A|The|An)\s+' + + # Specify a folder that calibre should connect to at startup using # connect_to_folder. This must be a full path to the folder. If the folder does # not exist when calibre starts, it is ignored. If there are '\' characters in diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 429ba06c6e..01e5190640 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -44,7 +44,15 @@ def author_to_author_sort(author): def authors_to_sort_string(authors): return ' & '.join(map(author_to_author_sort, authors)) -_title_pat = re.compile('^(A|The|An)\s+', re.IGNORECASE) +try: + _title_pat = re.compile(tweaks.get('title_sort_articles', + r'^(A|The|An)\s+'), re.IGNORECASE) +except: + print 'Error in title sort pattern' + import traceback + traceback.print_exc() + _title_pat = re.compile('^(A|The|An)\s+', re.IGNORECASE) + _ignore_starts = u'\'"'+u''.join(unichr(x) for x in range(0x2018, 0x201e)+[0x2032, 0x2033]) def title_sort(title):