mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Content server: Add support for link_maps
Only URLs of type http(s) are allowed
This commit is contained in:
parent
899ffb4e61
commit
5f515131a5
1
imgsrc/srv/external-link.svg
Normal file
1
imgsrc/srv/external-link.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1408 928v-480q0-26-19-45t-45-19h-480q-42 0-59 39-17 41 14 70l144 144-534 534q-19 19-19 45t19 45l102 102q19 19 45 19t45-19l534-534 144 144q18 19 45 19 12 0 25-5 39-17 39-59zm256-512v960q0 119-84.5 203.5t-203.5 84.5h-960q-119 0-203.5-84.5t-84.5-203.5v-960q0-119 84.5-203.5t203.5-84.5h960q119 0 203.5 84.5t84.5 203.5z"/></svg>
|
After Width: | Height: | Size: 425 B |
@ -2386,9 +2386,9 @@ class Cache:
|
||||
return cached
|
||||
links = {}
|
||||
def add_links_for_field(f):
|
||||
table = self.fields[f].table
|
||||
field_ids = self._field_ids_for(f, book_id)
|
||||
if field_ids:
|
||||
table = self.fields[f].table
|
||||
lm = table.link_map
|
||||
id_link_map = {fid:lm.get(fid) for fid in field_ids}
|
||||
vm = table.id_map
|
||||
|
@ -87,6 +87,9 @@ def book_as_json(db, book_id):
|
||||
langs = ans.get('languages')
|
||||
if langs:
|
||||
ans['lang_names'] = {l:calibre_langcode_to_name(l) for l in langs}
|
||||
link_maps = db.get_all_link_maps_for_book(book_id)
|
||||
if link_maps:
|
||||
ans['link_maps'] = link_maps
|
||||
return ans
|
||||
|
||||
|
||||
|
@ -190,6 +190,7 @@ def render_metadata(mi, table, book_id, iframe_css): # {{{
|
||||
else:
|
||||
fields = filter(allowed_fields, fields)
|
||||
comments = v'[]'
|
||||
link_maps = mi.link_maps or v'{}'
|
||||
|
||||
def add_row(field, name, val, is_searchable=False, is_html=False, join=None, search_text=None, use_quotes=True):
|
||||
if val is undefined or val is None:
|
||||
@ -199,18 +200,25 @@ def render_metadata(mi, table, book_id, iframe_css): # {{{
|
||||
def add_val(v):
|
||||
if not v.appendChild:
|
||||
v += ''
|
||||
parent = table.lastChild.lastChild
|
||||
if is_searchable:
|
||||
text_rep = search_text or v
|
||||
table.lastChild.lastChild.appendChild(E.a(
|
||||
parent.appendChild(E.a(
|
||||
v,
|
||||
title=_('Click to see books with {0}: {1}').format(name, text_rep), class_='blue-link',
|
||||
href=href_for_search(is_searchable, text_rep, use_quotes=use_quotes)
|
||||
))
|
||||
if link_maps[field] and link_maps[field][text_rep]:
|
||||
url = link_maps[field][text_rep]
|
||||
if url.startswith('https://') or url.startswith('http://'):
|
||||
parent.appendChild(document.createTextNode(' '))
|
||||
parent.appendChild(E.a(
|
||||
svgicon('external-link'), title=_('Click to open') + ': ' + url, href=url, target='_new', class_='blue-link'))
|
||||
else:
|
||||
if v.appendChild:
|
||||
table.lastChild.lastChild.appendChild(v)
|
||||
parent.appendChild(v)
|
||||
else:
|
||||
table.lastChild.lastChild.appendChild(document.createTextNode(v))
|
||||
parent.appendChild(document.createTextNode(v))
|
||||
|
||||
table.appendChild(E.tr(E.td(name + ':'), E.td()))
|
||||
if is_html and /[<>]/.test(val + ''):
|
||||
|
Loading…
x
Reference in New Issue
Block a user