From: Radek Czajka Date: Fri, 2 Mar 2012 13:00:12 +0000 (+0100) Subject: Merge branch 'master' into ofop X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/941b8e6effd4c0ffff52fa7e548d866f8454dddb?hp=0e46bb2843680717d6708f7bff585dd7d37f185d Merge branch 'master' into ofop --- diff --git a/librarian/cover.py b/librarian/cover.py index e7a8e1b..c345a50 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -232,6 +232,8 @@ class WLCover(Cover): bar_width = 35 background_color = '#444' author_color = '#444' + default_background = get_resource('res/cover.png') + format = 'JPEG' epochs = { u'Starożytność': 0, @@ -257,6 +259,8 @@ class WLCover(Cover): bg_src = urlopen(book_info.cover_url) self.background_img = StringIO(bg_src.read()) bg_src.close() + else: + self.background_img = self.default_background def pretty_author(self): return self.author.upper() diff --git a/librarian/html.py b/librarian/html.py index 39e5a01..e04790f 100644 --- a/librarian/html.py +++ b/librarian/html.py @@ -163,7 +163,8 @@ def extract_fragments(input_filename): # Process all elements except begin and end else: # Omit annotation tags - if len(element.get('name', '')) or element.get('class', '') == 'annotation': + if (len(element.get('name', '')) or + element.get('class', '') in ('annotation', 'anchor')): if event == 'end' and element.tail: for fragment_id in open_fragments: open_fragments[fragment_id].append('text', element.tail) @@ -220,6 +221,14 @@ def add_anchors(root): counter += 1 +def raw_printable_text(element): + working = copy.deepcopy(element) + for e in working.findall('a'): + if e.get('class') == 'annotation': + e.text = '' + return etree.tostring(working, method='text', encoding=unicode).strip() + + def add_table_of_contents(root): sections = [] counter = 1 @@ -228,8 +237,7 @@ def add_table_of_contents(root): if any_ancestor(element, lambda e: e.get('id') in ('footnotes',) or e.get('class') in ('person-list',)): continue - element_text = etree.tostring(element, method='text', - encoding=unicode).strip() + element_text = raw_printable_text(element) if element.tag == 'h3' and len(sections) and sections[-1][1] == 'h2': sections[-1][3].append((counter, element.tag, element_text, [])) else: diff --git a/librarian/packagers.py b/librarian/packagers.py index 9a93e56..cc9902b 100644 --- a/librarian/packagers.py +++ b/librarian/packagers.py @@ -81,7 +81,7 @@ class PrestigioPdfPackager(PdfPackager): flags = ('less-advertising',) -class VirtualoEpubPackager(Packager): +class VirtualoPackager(Packager): @staticmethod def utf_trunc(text, limit): """ truncates text to at most `limit' bytes in utf-8 """ @@ -139,9 +139,16 @@ class VirtualoEpubPackager(Packager): cover.VirtualoCover(info).save(os.path.join(outfile_dir, slug+'.jpg')) outfile = os.path.join(outfile_dir, '1.epub') outfile_sample = os.path.join(outfile_dir, '1.sample.epub') - doc.save_output_file(epub.transform(doc), + doc.save_output_file(doc.as_epub(), output_path=outfile) - doc.save_output_file(epub.transform(doc, sample=25), + doc.save_output_file(doc.as_epub(doc, sample=25), + output_path=outfile_sample) + outfile = os.path.join(outfile_dir, '1.mobi') + outfile_sample = os.path.join(outfile_dir, '1.sample.mobi') + doc.save_output_file(doc.as_mobi(cover=cover.VirtualoCover), + output_path=outfile) + doc.save_output_file( + doc.as_mobi(doc, cover=cover.VirtualoCover, sample=25), output_path=outfile_sample) except ParseError, e: print '%(file)s:%(name)s:%(message)s' % { diff --git a/librarian/res/cover.png b/librarian/res/cover.png new file mode 100644 index 0000000..e02acaa Binary files /dev/null and b/librarian/res/cover.png differ diff --git a/librarian/res/webtreatsetc-5647576127-ccby.png b/librarian/res/webtreatsetc-5647576127-ccby.png new file mode 100644 index 0000000..6919e93 Binary files /dev/null and b/librarian/res/webtreatsetc-5647576127-ccby.png differ diff --git a/librarian/xslt/book2html.xslt b/librarian/xslt/book2html.xslt index 441f641..f81f981 100755 --- a/librarian/xslt/book2html.xslt +++ b/librarian/xslt/book2html.xslt @@ -10,6 +10,7 @@ xmlns:dc="http://purl.org/dc/elements/1.1/" > + @@ -508,23 +509,28 @@ +

+

+

+

+
@@ -533,11 +539,15 @@
-

+

+ + +