Skip to content

Commit

Permalink
Add more determinant author byline and microformat tags to edition sh…
Browse files Browse the repository at this point in the history
…ow pages
  • Loading branch information
bfalling committed Aug 5, 2016
1 parent dc6cf06 commit bd981da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion openlibrary/templates/site/neck.html
Expand Up @@ -8,7 +8,7 @@
$if ctx.get("description"):
<meta name="description" content="$ctx.description" />

<title>$:title ($_("Open Library"))</title>
<title>$:title | $_("Open Library")</title>

$for link in ctx.get("links", []):
$:link
Expand Down
31 changes: 21 additions & 10 deletions openlibrary/templates/type/edition/view.html
@@ -1,6 +1,7 @@
$def with (page)

$var title: $page.title
$ title_suffix = cond(page.publish_date, "({0} edition)".format(page.publish_date), "(edition)")
$var title: $page.title $title_suffix

$add_metatag(property="twitter:card", content="summary")
$add_metatag(property="twitter:site", content="@openlibrary")
Expand Down Expand Up @@ -42,6 +43,18 @@
return meta
putctx("description", get_description(page))

$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>
Expand Down Expand Up @@ -198,12 +211,9 @@
<span title="$_('Go to the main page for %s', page.title)"><a href="$work.url()">$truncate(work.title or "", 60)</a></span>
$else:
<strong>$:_('1 edition')</strong> record for of $page.title
$ authors = cond(work, work and work.get_authors(), page.get_authors())
$if authors:
$ author_list = ', '.join('<a href="%s">%s</a>' % (a.url(), truncate(a.name, 40)) for a in authors)
$_("by") <span title="$_('Go to this author\'s page')">$:author_list</span>
$elif page.author_names:
by $", ".join(page.author_names)
$ authors_byline = get_authors_byline(page)
$if authors_byline:
$_("by") <span title="$_('Author')">$:authors_byline</span>
$else:
$:_("by an <em>unknown author</em>")
$if work:
Expand Down Expand Up @@ -265,8 +275,9 @@ <h1 class="edition">
<br /><em>$page.subtitle</em>
$if page.edition_title or page.edition_name:
<br />$page.edition_title $page.edition_name
$if page.by_statement:
<br />$page.by_statement
$ authors_byline = get_authors_byline(page, include_schema=True)
$if authors_byline:
<br />$_("by") $:authors_byline
</h1>
<h4 class="publisher">
$if page.publish_date or page.publishers or page.publish_places:
Expand All @@ -287,7 +298,7 @@ <h4 class="publisher">
<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 $:thingrepr(page.languages).
<br/>Written in <span itemprop="In language">$:thingrepr(page.languages)</span>.
</h4>
</div>

Expand Down

0 comments on commit bd981da

Please sign in to comment.