Permalink
Fetching contributors…
Cannot retrieve contributors at this time
245 lines (212 sloc) 11 KB
$def with (page)
$ title = page.title
$ 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 render_description():
items = []
title = page.title
if page.subtitle:
title += ": " + page.subtitle
if page.authors:
title += " by " + ", ".join(a.name or "" for a in page.get_authors())
items.append(title)
if page.edition_count:
items.append("%d %s" % (page.edition_count, cond(page.edition_count > 1, "editions", "edition")))
if page.first_publish_year:
items.append("First published in %s" % page.first_publish_year)
subjects = page.get_subjects()
if subjects:
items.append("Subjects: " + ", ".join(s for s in subjects))
if page.subject_places:
items.append("Places: " + ", ".join(s for s in page.subject_places))
if page.subject_people:
items.append("People: " + ", ".join(s for s in page.subject_people))
if page.subject_times:
items.append("Times: " + ", ".join(s for s in page.subject_times))
return "; ".join(items)
description = render_description()
putctx("description", description)
$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 class="contentContainer" itemscope itemtype="https://schema.org/Book">
<div id="contentHead">
$:macros.databarView(page)
<h1>
$if page.get('subtitle', ''):
<span itemprop="name">$page.title</span><span title="subtitle">: $page.subtitle</span>
$else:
<span itemprop="name">$page.title</span>
$if page.edition_count:
<span class="tools" style="white-space:nowrap;">
$if page.edition_count == 1:
<a href="$page.get_one_edition().url()" title="View this edition">1 edition</a>
$else:
<a href="#editions" class="plain brown">$page.edition_count editions</a>
</span>
</h1>
<div class="clearfix"></div>
$if page.authors:
$ author_list = ', '.join('<a href="%s" itemprop="author">%s</a>' % (a.url(), a.name) for a in page.get_authors())
<div class="work"><span class="editions">$_("By") $:author_list</span></div>
$else:
<div class="work"><span class="editions">$:_("By <em>unknown author</em>")</span></div>
<div class="shift">
$if page.has_ebook():
<a href="#editions">Go to the editions section to read or download ebooks</a>.
</div>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
<!--
\$().ready(function(){
var back = history.length;
\$().bind('cbox_closed', function(){
var page = back - history.length;
if (page < 0){
history.go(page);
}
});
});
//-->
</script>
<div id="contentBody">
<div class="workCover">
<div class="illustration" id="work">
$:render_template('covers/book_cover', page)
$:render_template("covers/change", page, ".bookCover img")
</div>
$if page.edition_count == 1:
<div class="editionTools">
$ book = page.get_one_edition()
$ links = book.get_links()
$:macros.databarWork(book)
$if "lists" in ctx.features:
<div class="Tools">
$:render_template("lists/widget", page)
</div>
$if links:
<div class="section">
<h3>Links <span class="gray small sansserif">($_("leaves Open Library"))</span></h3>
<ul class="booklinks sansserif">
$for link in links:
<li><a href="$link.url">$link.title</a></li>
</ul>
</div>
</div>
</div>
<div class="workAbout">
$if not (page.description or page.excerpts or page.first_sentence):
<div class="workHelp brown sansserif">
$ exclaim = random.choice(["Well, gosh.", "Dang.", "Darn it.", "Oy vey.","¬°Ay, caramba!", "Uh oh.","Sheesh.", "Ack!", "D'oh.","Oh, pooh.", "What the..?", "Cor blimey.", "Jeepers.", "Heavens to Betsy!", "Oh! The humanity!", "Alack!", "Alas...", "Zut alors!","Drat!","Fiddlesticks.", "Good grief.", "Rats.", "Yikes!", "Crikey!"])
<span id="curses">$exclaim</span> There's no description for this book yet. Can you <b><a href="$page.url('/edit')#about/about">help</a></b>?
</div>
<div class="workPadding">
$if not page.excerpts and page.first_sentence:
<p class="largest" style="margin-bottom: 20px;" title="First Sentence"><em>"$page.first_sentence</em>"</p>
$if page.description:
<div class="sansserif smallest brown collapse">About the Book</div>
$:sanitize(format(page.description))
$if page.original_languages:
<div class="sansserif smallest brown collapse">Original languages</div>
$', '.join(lang.name for lang in page.original_languages)<p>
$def render_subjects(label, subjects, prefix=""):
$if subjects:
<div class="section" style="margin-bottom:15px;">
<h6 class="collapse black uppercase">$label</h6>
<div class="sansserif">
$for subject in subjects:
<a href="/subjects/$prefix$utf8(subject.lower().replace(' ', '_').replace(',',''))">$subject</a>$cond(not loop.last,",","")
</div>
</div>
$:render_subjects("Subjects", page.get_subjects())
$:render_subjects("People", page.subject_people, prefix="person:")
$:render_subjects("Places", page.subject_places, prefix="place:")
$:render_subjects("Times", page.subject_times, prefix="time:")
$if page.excerpts:
<div class="section">
<h3 class="collapse">$_("Excerpts")</h3>
$for excerpt in page.excerpts:
<div class="excerpt">
<div class="text">
$for line in excerpt.excerpt.split('\n'):
$line<br/>
</div>
<div class="attribution">
$if excerpt.pages:
$_("Page") $excerpt.pages,
$if excerpt.author:
$_("added by") <a href="$excerpt.author.key">$excerpt.author.displayname</a>.
$else:
$_("added anonymously").
$if excerpt.comment:
"<em>$excerpt.comment</em>"
</div>
</div>
</div>
$if page.links or (page.wikipedia and page.wikipedia.startswith("http")):
<div class="section">
<h3>$_("Links") <span class="gray small sansserif">$_("(outside Open Library)")</span></h3>
<ul class="booklinks sansserif">
$if page.wikipedia and page.wikipedia.startswith("http"):
<li><a href="$page.wikipedia" class="sidebar">Wikipedia</a></li>
$for link in page.links:
<li><a href="$link.url">$link.title</a></li>
</ul>
</div>
$if page.edition_count > 1:
$if (page.lc_classifications or page.dewey_number):
<div class="section">
<h3 class="collapse">$_("Classifications")</h3>
<table class="meta"><tbody>
$if page.lc_classifications:
<tr><td class="title"><span class="title">Library of Congress</span></td>
<td><span class="object">$thingrepr(page.lc_classifications)</span></td></tr>
$if page.dewey_number:
<tr><td class="title"><span class="title">Dewey</span></td>
<td><span class="object">$thingrepr(page.dewey_number)</span></td></tr>
</tbody></table>
</div>
</div>
</div>
$if "lists" in ctx.features:
$if page.edition_count > 1:
<script type="text/javascript">
\$().ready(function(){
\$('#widget-my-lists').children().insertBefore('#widget-my-lists').end().end().remove();
\$('#widget-other-lists').children().insertBefore('#widget-other-lists').end().end().remove();
if (\$('.dropit').length) {
\$('#widget-add').addClass('contentQuarter').css('min-height','35px');
\$('#listsWork .listLists').wrap('<div class="contentThreeQuarter" style="min-height:35px;">');
\$('<div class="contentSpacer"></div>').insertBefore('.contentThreeQuarter');
\$('#listsWork').addClass('collapse');
} else {
\$('#listsWork').css('width','100%');
\$('ul.listLists').css('width','100%')
};
});
</script>
<div class="clearfix"></div>
<div class="section" id="listsWork" style="float:left;">
$:render_template("lists/widget", page)
</div>
<a name="editions"></a>
$if page.edition_count == 1:
$:render_template("books/edition-show", page.get_one_edition())
$elif page.edition_count > 1:
<div class="clearfix"></div>
$:render_template("type/work/editions_datatable", page)
$:render_template("lib/history", page)
</div>
</div>