From 929595c8056632dff8648d20bc29d3eeaba8af34 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 2 Jan 2017 14:22:54 +0530 Subject: [PATCH] Access the publications Landmarks via Go to... --- src/calibre/srv/render_book.py | 8 ++++++-- src/pyj/read_book/goto.pyj | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 8c04142028..212a258c20 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -26,7 +26,7 @@ from calibre.ebooks.oeb.polish.cover import set_epub_cover, find_cover_image from calibre.ebooks.oeb.polish.css import transform_css from calibre.ebooks.oeb.polish.utils import extract from calibre.ebooks.css_transform_rules import StyleDeclaration -from calibre.ebooks.oeb.polish.toc import get_toc +from calibre.ebooks.oeb.polish.toc import get_toc, get_landmarks from calibre.ebooks.oeb.polish.utils import guess_type from calibre.utils.short_uuid import uuid4 from calibre.utils.logging import default_log @@ -182,11 +182,14 @@ class Container(ContainerBase): } raster_cover_name, titlepage_name = self.create_cover_page(input_fmt.lower()) toc = get_toc(self).to_dict(count()) + spine = [name for name, is_linear in self.spine_names] + spineq = frozenset(spine) + landmarks = [l for l in get_landmarks(self) if l['dest'] in spineq] self.book_render_data = data = { 'version': RENDER_VERSION, 'toc':toc, - 'spine':[name for name, is_linear in self.spine_names], + 'spine':spine, 'link_uid': uuid4(), 'book_hash': book_hash, 'is_comic': input_fmt.lower() in {'cbc', 'cbz', 'cbr', 'cb7'}, @@ -196,6 +199,7 @@ class Container(ContainerBase): 'total_length': 0, 'spine_length': 0, 'toc_anchor_map': toc_anchor_map(toc), + 'landmarks': landmarks, } # Mark the spine as dirty since we have to ensure it is normalized for name in data['spine']: diff --git a/src/pyj/read_book/goto.pyj b/src/pyj/read_book/goto.pyj index fa3c32a4b5..ec95ed6586 100644 --- a/src/pyj/read_book/goto.pyj +++ b/src/pyj/read_book/goto.pyj @@ -14,6 +14,7 @@ from read_book.globals import current_book def create_goto_list(onclick): ans = E.div() items = v'[]' + landmarks = current_book().manifest.landmarks toc = current_book().manifest.toc id_map = get_toc_maps(toc)[1] before, after = get_border_nodes(toc, id_map) @@ -23,6 +24,8 @@ def create_goto_list(onclick): items.push(create_item(_('Previous Section'), icon='caret-left', subtitle=before.title, action=onclick.bind(None, before.dest, before.frag))) items.push(create_item(_('Document Start'), action=onclick.bind(None, def(view): view.goto_doc_boundary(True);))) items.push(create_item(_('Document End'), action=onclick.bind(None, def(view): view.goto_doc_boundary(False);))) + for l in landmarks: + items.push(create_item(l.title, action=onclick.bind(None, l.dest, l.frag))) build_list(ans, items) return ans