Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
376 lines (330 sloc) 16.3 KB
$def with (page)
$ work = page.works and page.works[0] or None
$ book_title = page.get('title', '') if page.title else (work.title if work else '')
$ work_title = work.title if work else page.get('title', '')
$ book_subtitle = page.subtitle if page.get('subtitle') else (work.subtitle if work and work.get('subtitle') else '')
$ title_suffix = cond(page.publish_date, u"({0} edition)".format(page.publish_date), "(edition)")
$ title = book_title + " " + title_suffix
$ title_with_site = title + " | Open Library"
$ meta_cover_url = item_image(page.get_cover_url("M"), default="https://openlibrary.org/images/icons/avatar_book-sm.png")
$var title: $title
$code:
def has_any(*keys):
return any(page[k] for k in keys)
$code:
def get_description(book):
if book.publishers and book.publish_date:
edition = book.publish_date + ', ' + ', '.join(book.publishers)
elif book.publish_date:
edition = book.publish_date
elif book.publishers:
edition = ', '.join(book.publishers)
else:
edition = 'unknown'
work = page.works and page.works[0]
title = cond(work, work.title, book.title)
authors = cond(work, work and work.get_authors(), book.get_authors())
author_info = " by " + ", ".join(a.name for a in authors)
format = ""
if book.physical_format:
format += book.physical_format.replace('[', '').replace(']', '')
if book.languages:
format += ' in ' + ', '.join(lang.name for lang in book.languages)
if book.edition_name:
format += " - " + book.edition_name
meta = title + author_info + ", " + edition + " edition, " + format
return meta
description = get_description(page)
putctx("description", description)
$code:
def get_authors_byline(page, include_schema=False):
work = page.works and page.works[0]
schema_attribute = cond(include_schema, ' itemprop="author"', '')
authors = cond(work, work and work.get_authors(), page.get_authors())
if authors:
return ', '.join('<a href="%s"%s>%s</a>' % (a.url(), schema_attribute, truncate(a.name, 40)) for a in authors)
elif page.author_names:
return ('<span%s>' % (schema_attribute)) + ", ".join(page.author_names) + "</span>"
else:
return None
$def display_value(label, value, itemprop=None):
$if value:
<tr>
<td class="title"><span class="title">$label</span></td>
$if itemprop:
<td><span itemprop="$itemprop" class="object">$:thingrepr(value)</span></td>
$else:
<td><span class="object">$:thingrepr(value)</span></td>
</tr>
$def display_identifiers(label, ids, itemprop=None):
$if label != "Goodreads":
$ all_ids = [-1!=id['value'].find('openlib-') for id in ids]
$if (True in all_ids) and (1==len(all_ids)):
$return
<tr>
<td class="title"><span class="title">$label</span></td>
<td class="object"><span class="object" $:cond(itemprop, 'itemprop="%s"' % itemprop, '')>
$for id in ids:
$ sep = cond(loop.last, "", ", ")
$if -1 != id.value.find('openlib-'):
$continue
$if id.url:
<a href="$id.url">$id.value</a>$sep
$else:
${id.value}$sep
</span></td>
</tr>
$def display_goodreads(label, ids):
$if label == "Goodreads":
<table class="meta collapse">
<tbody>
<tr>
<td class="title"><span class="title">$label</span></td>
<td class="object">
<span class="object">
$for id in ids:
<a href="$id.url">$id.value</a>
</span>
</td>
</tr>
</tbody>
</table>
$def display_contributor(c):
<li><span>$c.role</span><br />$c.name </li>
$add_metatag(property="twitter:card", content="summary")
$add_metatag(property="twitter:site", content="@openlibrary")
$add_metatag(property="twitter:title", content=title_with_site)
$add_metatag(property="twitter:description", content="View the book on Open Library.")
$add_metatag(property="twitter:image", content=meta_cover_url)
$add_metatag(property="og:title", content=title_with_site)
$add_metatag(property="og:type", content="books.book")
$add_metatag(property="og:image", content=meta_cover_url)
$add_metatag(property="og:url", content=request.canonical_url)
$add_metatag(property="og:site_name", content="Open Library")
$add_metatag(property="og:description", content=description)
$set_share_links(url=request.canonical_url, title=title, view_context=ctx)
<div id="contentHead">
<table width="100%">
<tbody>
<tr>
$ item_id = None
$if 'ocaid' in page:
$ item_id = page['ocaid']
$ meta_fields = page.get_ia_meta_fields()
$if meta_fields:
$ collection = meta_fields.get('collection', [])
$if 'printdisabled' in collection or 'lendinglibrary' in collection:
$ item_id = None
<td valign="top" width="100%">
$:macros.databarView(page)
<div class="navEdition sansserif">
$ edition_count = work.edition_count if work and work.edition_count else 1
<a href="$(work.url() if work else '')"><strong>$edition_count edition$("s" if edition_count > 1 else "")</strong></a> of <span class="booktitle">$truncate(work_title, 60)</span> found in the catalog.
$if work:
<span><a href="/books/add?work=$work.key" title="$_('Add another edition of') $book_title">$_("Add another edition")</a>?</span>
<br />
<div class="shift">
$if page.ocaid:
An ebook is available for this edition.
<a href="#read">Go to the read section to download</a>.
$else:
No ebook is available for this edition.
</div>
</div>
</td>
</tr></tbody></table>
</div>
<div id="contentBody" role="main" itemscope itemtype="https://schema.org/Book">
<div class="workDetails">
<div class="editionCover">
<div class="illustration edition-cover">
$:render_template('covers/book_cover', page)
$# Don't display add/change cover link for /books/ia:foo00bar pages
$if not page.is_fake_record():
$:render_template('covers/change', page, ".edition-cover .bookCover img")
</div>
$# pages like /books/ia:foo00bar are fake records created from metadata API.
$# Adding them to lists doesn't work. Disabling it to avoid any issues.
$if "lists" in ctx.features and not page.is_fake_record():
<div class="user-book-options">
<div class="Tools tools-override">
$:render_template("lists/widget", page, include_header=False)
</div>
</div>
$ contributors = page.get('contributors', [])
$if contributors:
<div class="section">
<h3 class="collapse">$_("Contributors")</h3>
<ul class="contributors">
$for c in contributors:
$:display_contributor(c)
</ul>
</div>
</div>
<div class="editionAbout">
<div class="book-overview section sansserif">
<h1 class="work-title" itemprop="name">$book_title</h1>
$if book_subtitle:
<h2 class="work-subtitle">$book_subtitle</h2>
$if page.edition_title or page.edition_name:
<h2 class="edition-title">
$page.edition_title $page.edition_name
</h2>
$ authors_byline = get_authors_byline(page, include_schema=True)
$if authors_byline:
<h2 class="edition-byline">$_("by") $:authors_byline</h2>
$ rating_stats = work.get_rating_stats() if work else {}
$ stats_by_bookshelf = work.get_num_users_by_bookshelf() if work else {}
$if rating_stats or stats_by_bookshelf:
<ul class="readers-stats">
$if rating_stats and rating_stats['avg_rating'] > 0 and rating_stats['num_ratings'] > 1:
<li class="avg-ratings">
$:('<span class="star">★</span>' * int(rating_stats['avg_rating'])) $(rating_stats['avg_rating'])
</li>
<li>
$rating_stats['num_ratings'] Ratings
</li>
$if stats_by_bookshelf.get('want-to-read', 0) > 1:
<li class="reading-log-stat">$stats_by_bookshelf['want-to-read'] Want to read</li>
$if stats_by_bookshelf.get('currently-reading', 0) > 1:
<li class="reading-log-stat">$stats_by_bookshelf['currently-reading'] Currently reading</li>
$if stats_by_bookshelf.get('already-read', 0) > 1:
<li class="reading-log-stat">$stats_by_bookshelf['already-read'] Have read</li>
</ul>
<h4 class="publisher">
$if page.publish_date or page.publishers or page.publish_places:
Published
$if page.publish_date:
<strong itemprop="datePublished">$page.publish_date</strong>
$if page.publishers:
by
$for p in page.publishers:
$if "publishers" in ctx.features:
<a itemprop="publisher" href="/publishers/$p.replace(' ', '_')" title="$_('Show for other books from %s', p)">$p</a>$cond(loop.last, "", ", ")
$else:
<a itemprop="publisher" href="/search?publisher_facet=$p.replace('&','%26')" title="$_('Search for other books from') $p">$p</a>$cond(loop.last, "", ", ")
$if page.publish_places:
in
$for p in page.publish_places:
<a href="/search/subjects?q=$p.replace('&','%26')" title="$_('Search for subjects about') $p">$p</a>$cond(loop.last, "", ", ")
<span class="adjust">.</span>
$if page.languages:
<br/>Written in <span itemprop="In language">$:thingrepr(page.languages)</span>.
</h4>
</div>
$if page.description:
<h3 class="collapse">$_("About the Book")</h3>
$:format(page.description)
$if page.first_sentence:
<h3 class="collapse">$_("First Sentence")</h3>
<p>$page.first_sentence</p>
$ table_of_contents = page.get_table_of_contents()
$if table_of_contents and len(table_of_contents) > 1:
<div class="section">
<h3 class="collapse">$_("Table of Contents")</h3>
<table class="meta sansserif" id="toc-table">
<tbody>
$for toc in table_of_contents:
<tr class="toc-level-$toc.level">
<td class="toc-label">$toc.label</td>
$if item_id and toc.pagenum.isdigit():
<td class="toc-title"><a href="//archive.org/stream/$item_id#page/$toc.pagenum">$toc.title</a></td>
$else:
<td class="toc-title">$toc.title</td>
<td class="toc-pagenum">$toc.pagenum</td>
</tr>
</tbody>
</table>
</div>
$if page.notes or page.series or page.volume or page.genres or page.other_titles or page.copyright_date or page.translation_of or page.translated_from:
<div class="section">
<h3 class="collapse">$_("Edition Notes")</h3>
$if page.notes:
<span class="sansserif">$:format(page.notes)</span>
<table class="meta">
<tbody>
$:display_value(_("Series"), page.series)
$:display_value(_("Volume"), page.volume)
$:display_value(_("Genre"), page.genres)
$:display_value(_("Other Titles"), page.other_titles)
$:display_value(_("Copyright Date"), page.copyright_date)
$:display_value(_("Translation Of"), page.translation_of)
$:display_value(_("Translated From"), page.translated_from)
</tbody>
</table>
</div>
$ classifications = page.get_classifications().multi_items()
$if classifications:
<div class="section">
<h3 class="collapse">$_("Classifications")</h3>
<table class="meta">
<tbody>
$for name, values in classifications:
$:display_identifiers(values[0].label, values)
</tbody>
</table>
</div>
$if has_any("physical_format", "pagination", "physical_dimensions", "weight"):
<div class="section">
<h3 class="collapse">$_("The Physical Object")</h3>
<table class="meta">
<tbody>
$:display_value(_("Format"), page.physical_format)
$:display_value(_("Pagination"), page.pagination)
$:display_value(_("Number of pages"), page.number_of_pages, itemprop="numberOfPages")
$:display_value(_("Dimensions"), page.physical_dimensions)
$:display_value(_("Weight"), page.weight)
</tbody>
</table>
</div>
<div class="section">
<h3 class="collapse">$_("ID Numbers")</h3>
<table class="meta">
<tbody>
$:display_identifiers("Open Library", [storage(url=None, value=page.key.split("/")[-1])])
$for name, values in page.get_identifiers().multi_items():
$ identifier_label = values[0].label
$if not (page.is_in_private_collection() and identifier_label == 'Internet Archive'):
$:display_identifiers(identifier_label, values, itemprop=cond(name in ["isbn_10", "isbn_13"], "isbn", None))
</tbody>
</table>
$:display_goodreads("Open Library", [storage(url=None, value=page.key.split("/")[-1])])
$for name, values in page.get_identifiers().multi_items():
$:display_goodreads(values[0].label, values)
</div>
</div>
<div class="editionTools">
$:macros.databarWork(page, editions_page=True)
</div>
</div>
$ work = page.works and page.works[0]
$:macros.RelatedWorksCarousel(work)
$if ctx.user and ctx.user.is_admin():
<div class="small sansserif clearfix"><br/><span class="adminOnly"><a href="$page.url('/borrow_admin')">View loan debugging information</a></span></div>
$:render_template("lib/history", page)
<script type="text/javascript">
<!--
\$(function(){
\$('#historyTools').append('| <a href="javascript:;" id="wikilink" title="Cite this on Wikipedia">Wikipedia citation</a>');
\$('#wikilink').colorbox({inline:true,opacity:"0.5",href:"#wikicode"});
\$('#wikiselect').focus(function(){\$(this).select();})
});
//-->
</script>
<div class="hidden">
<div class="coverFloat" id="wikicode">
<div class="coverFloatHead">
Wikipedia citation
<a class="floaterShut" href="javascript:;" onclick="\$.fn.colorbox.close();"><span class="shift">Close</span></a>
</div>
<p>Copy and paste this code into your Wikipedia page. <a href="http://en.wikipedia.org/wiki/Template:Cite#Citing_books" target="_blank" title="Get instructions at Wikipedia in a new window">Need help</a>?</p>
<form method="get">
<textarea cols="30" rows="20" readonly="readonly" id="wikiselect">{{Citation
$for k, v in page.wp_citation_fields.iteritems():
|$k = $v
}}</textarea>
</form>
</div>
</div>
</div>
<!-- source_records: $page.get('source_records', []) -->