Skip to content

Commit 6978961

Browse files
authored
Merge pull request #10586 from SivanC/trustedbookprovider-interstitial
Migrate to Interstitial for Trusted Book Provider read actions
2 parents 142b054 + 45ee297 commit 6978961

15 files changed

+97
-267
lines changed

openlibrary/book_providers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,14 @@ def get_template_path(self, typ: Literal['read_button', 'download_options']) ->
189189
return f"book_providers/{self.short_name}_{typ}.html"
190190

191191
def render_read_button(
192-
self, ed_or_solr: Edition | dict, analytics_attr: Callable[[str], str]
192+
self,
193+
edition_key: str,
194+
ed_or_solr: Edition | dict,
195+
analytics_attr: Callable[[str], str],
193196
) -> TemplateResult:
194197
return render_template(
195198
self.get_template_path('read_button'),
199+
edition_key,
196200
self.get_best_identifier(ed_or_solr),
197201
analytics_attr,
198202
)
@@ -495,7 +499,10 @@ def get_identifiers(self, ed_or_solr: Edition | dict) -> list[str]:
495499
return []
496500

497501
def render_read_button(
498-
self, ed_or_solr: Edition | dict, analytics_attr: Callable[[str], str]
502+
self,
503+
edition_key: str,
504+
ed_or_solr: Edition | dict,
505+
analytics_attr: Callable[[str], str],
499506
) -> TemplateResult | str:
500507
acq_sorted = sorted(
501508
(
@@ -519,7 +526,7 @@ def render_read_button(
519526
parsed_url = parse.urlparse(url)
520527
domain = parsed_url.netloc
521528
return render_template(
522-
self.get_template_path('read_button'), acquisition, domain
529+
self.get_template_path('read_button'), edition_key, acquisition, domain
523530
)
524531

525532
def render_download_options(self, edition: Edition, extra_args: list | None = None):

openlibrary/i18n/messages.pot

Lines changed: 25 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,20 @@ msgstr ""
461461
#: interstitial.html
462462
#, python-format
463463
msgid ""
464-
"This book is provided by %s, a third-party Open Library Trusted Book "
465-
"Provider"
464+
"This book is provided by %(book_provider)s, a third-party Open Library "
465+
"Trusted Book Provider"
466466
msgstr ""
467467

468468
#: interstitial.html
469469
#, python-format
470-
msgid "You will be automatically redirected to %s in %s seconds..."
470+
msgid "In %(time)s seconds, you will be automatically redirected to: %(url)s"
471471
msgstr ""
472472

473473
#: CreateListModal.html EditButtons.html account/notifications.html
474474
#: account/password/reset.html account/privacy.html admin/imports-add.html
475475
#: admin/permissions.html books/add.html databarEdit.html interstitial.html
476-
#: merge/authors.html my_books/dropdown_content.html type/tag/form.html
476+
#: merge/authors.html my_books/dropdown_content.html support.html
477+
#: type/tag/form.html
477478
msgid "Cancel"
478479
msgstr ""
479480

@@ -590,15 +591,7 @@ msgid "Thank you very much for improving that record!"
590591
msgstr ""
591592

592593
#: BookPreview.html CreateListModal.html DonateModal.html NotesModal.html
593-
#: ObservationsModal.html ShareModal.html
594-
#: book_providers/cita_press_read_button.html
595-
#: book_providers/direct_read_button.html
596-
#: book_providers/gutenberg_read_button.html
597-
#: book_providers/librivox_read_button.html
598-
#: book_providers/openstax_read_button.html
599-
#: book_providers/runeberg_read_button.html
600-
#: book_providers/standard_ebooks_read_button.html
601-
#: book_providers/wikisource_read_button.html covers/author_photo.html
594+
#: ObservationsModal.html ShareModal.html covers/author_photo.html
602595
#: covers/book_cover.html covers/book_cover_single_edition.html
603596
#: covers/book_cover_work.html covers/change.html lib/history.html
604597
#: my_books/dropdown_content.html native_dialog.html
@@ -836,13 +829,6 @@ msgstr ""
836829
msgid "Send"
837830
msgstr ""
838831

839-
#: CreateListModal.html EditButtons.html account/notifications.html
840-
#: account/password/reset.html account/privacy.html admin/imports-add.html
841-
#: admin/permissions.html books/add.html databarEdit.html merge/authors.html
842-
#: my_books/dropdown_content.html support.html type/tag/form.html
843-
msgid "Cancel"
844-
msgstr ""
845-
846832
#: trending.html
847833
msgid "Now"
848834
msgstr ""
@@ -2938,36 +2924,10 @@ msgstr ""
29382924
msgid "Read eBook from Cita Press"
29392925
msgstr ""
29402926

2941-
#: book_providers/cita_press_read_button.html
2942-
msgid ""
2943-
"This book is available from <a href=\"https://citapress.org/\">Cita "
2944-
"Press</a>. Cita Press is a trusted book provider of works written by "
2945-
"women, pairing contemporary authors and designers with open access texts "
2946-
"to make carefully designed books available for free and open source."
2947-
msgstr ""
2948-
2949-
#: book_providers/cita_press_read_button.html
2950-
#: book_providers/direct_read_button.html
2951-
#: book_providers/gutenberg_read_button.html
2952-
#: book_providers/librivox_read_button.html
2953-
#: book_providers/openstax_read_button.html
2954-
#: book_providers/runeberg_read_button.html
2955-
#: book_providers/standard_ebooks_read_button.html
2956-
#: book_providers/wikisource_read_button.html
2957-
msgid "Learn more"
2958-
msgstr ""
2959-
29602927
#: book_providers/direct_read_button.html
29612928
msgid "Read free online"
29622929
msgstr ""
29632930

2964-
#: book_providers/direct_read_button.html
2965-
#, python-format
2966-
msgid ""
2967-
"This book is freely available from <a href=\"%s\">%s</a>, an external "
2968-
"third-party book provider."
2969-
msgstr ""
2970-
29712931
#: book_providers/gutenberg_download_options.html
29722932
msgid "Download an HTML from Project Gutenberg"
29732933
msgstr ""
@@ -3007,15 +2967,6 @@ msgstr ""
30072967
msgid "Read eBook from Project Gutenberg"
30082968
msgstr ""
30092969

3010-
#: book_providers/gutenberg_read_button.html
3011-
msgid ""
3012-
"This book is available from <a "
3013-
"href=\"https://www.gutenberg.org/\">Project Gutenberg</a>. Project "
3014-
"Gutenberg is a trusted book provider of classic ebooks, supporting "
3015-
"thousands of volunteers in the creation and distribution of over 60,000 "
3016-
"free eBooks."
3017-
msgstr ""
3018-
30192970
#: book_providers/ia_download_options.html
30202971
msgid "Download a PDF from Internet Archive"
30212972
msgstr ""
@@ -3072,14 +3023,6 @@ msgstr ""
30723023
msgid "Audiobook"
30733024
msgstr ""
30743025

3075-
#: book_providers/librivox_read_button.html
3076-
msgid ""
3077-
"This book is available from <a "
3078-
"href=\"https://librivox.org/\">LibriVox</a>. LibriVox is a trusted book "
3079-
"provider of public domain audiobooks, narrated by volunteers, distributed"
3080-
" for free on the internet."
3081-
msgstr ""
3082-
30833026
#: book_providers/openstax_download_options.html
30843027
msgid "Download PDF from OpenStax"
30853028
msgstr ""
@@ -3092,15 +3035,6 @@ msgstr ""
30923035
msgid "Read eBook from OpenStax"
30933036
msgstr ""
30943037

3095-
#: book_providers/openstax_read_button.html
3096-
msgid ""
3097-
"This book is available from <a "
3098-
"href=\"https://www.openstax.org/\">OpenStax</a>. OpenStax is a trusted "
3099-
"book provider and a 501(c)(3) nonprofit charitable corporation dedicated "
3100-
"to providing free high-quality, peer-reviewed, openly licensed textbooks "
3101-
"online."
3102-
msgstr ""
3103-
31043038
#: book_providers/runeberg_download_options.html
31053039
msgid "Download all scanned images from Project Runeberg"
31063040
msgstr ""
@@ -3145,13 +3079,6 @@ msgstr ""
31453079
msgid "Read eBook from Project Runeberg"
31463080
msgstr ""
31473081

3148-
#: book_providers/runeberg_read_button.html
3149-
msgid ""
3150-
"This book is available from <a href=\"https://runeberg.org/\">Project "
3151-
"Runeberg</a>. Project Runeberg is a trusted book provider of classic "
3152-
"Nordic (Scandinavian) literature in electronic form."
3153-
msgstr ""
3154-
31553082
#: book_providers/standard_ebooks_download_options.html
31563083
msgid "Download an HTML from Standard Ebooks"
31573084
msgstr ""
@@ -3192,15 +3119,6 @@ msgstr ""
31923119
msgid "Read eBook from Standard eBooks"
31933120
msgstr ""
31943121

3195-
#: book_providers/standard_ebooks_read_button.html
3196-
msgid ""
3197-
"This book is available from <a "
3198-
"href=\"https://standardebooks.org/\">Standard Ebooks</a>. Standard Ebooks"
3199-
" is a trusted book provider and a volunteer-driven project that produces "
3200-
"new editions of public domain ebooks that are lovingly formatted, open "
3201-
"source, free of copyright restrictions, and free of cost."
3202-
msgstr ""
3203-
32043122
#: book_providers/wikisource_download_options.html
32053123
msgid "Download PDF from Wikisource"
32063124
msgstr ""
@@ -3229,17 +3147,6 @@ msgstr ""
32293147
msgid "Read eBook on Wikisource"
32303148
msgstr ""
32313149

3232-
#: book_providers/wikisource_read_button.html
3233-
msgid ""
3234-
"This book is available from <a "
3235-
"href=\"https://wikisource.org/\">Wikisource</a>. Wikisource, a <a "
3236-
"href=\"https://www.wikimedia.org/\">Wikimedia Foundation</a> project, is "
3237-
"a trusted book provider of works available under the <a "
3238-
"href=\"https://creativecommons.org/licenses/by-sa/4.0/\">CC-BY-SA</a> "
3239-
"open content license, such as essays, historical documents, letters, "
3240-
"speeches, and public domain books."
3241-
msgstr ""
3242-
32433150
#: books/RelatedWorksCarousel.html
32443151
msgid "You might also like"
32453152
msgstr ""
@@ -7859,12 +7766,6 @@ msgstr ""
78597766
msgid "Choose a password"
78607767
msgstr ""
78617768

7862-
#: openlibrary/plugins/upstream/borrow.py
7863-
msgid ""
7864-
"Your account has hit a lending limit. Please try again later or contact "
7865-
7866-
msgstr ""
7867-
78687769
#: openlibrary/plugins/upstream/account.py
78697770
msgid "The email address you entered is invalid"
78707771
msgstr ""
@@ -7999,9 +7900,22 @@ msgstr ""
79997900
msgid "Notification preferences have been updated successfully."
80007901
msgstr ""
80017902

8002-
#: openlibrary/plugins/openlibrary/lists.py
8003-
#, python-format
8004-
msgid "Are you sure you want to remove <strong>%(title)s</strong> from your list?"
7903+
#: openlibrary/plugins/upstream/borrow.py
7904+
msgid ""
7905+
"Your account has hit a lending limit. Please try again later or contact "
7906+
7907+
msgstr ""
7908+
7909+
#: openlibrary/plugins/worksearch/code.py
7910+
msgid "eBook?"
7911+
msgstr ""
7912+
7913+
#: openlibrary/plugins/worksearch/code.py
7914+
msgid "First published"
7915+
msgstr ""
7916+
7917+
#: openlibrary/plugins/worksearch/code.py
7918+
msgid "Classic eBooks"
80057919
msgstr ""
80067920

80077921
#: openlibrary/plugins/openlibrary/code.py
@@ -8108,16 +8022,9 @@ msgstr ""
81088022
msgid "Science"
81098023
msgstr ""
81108024

8111-
#: openlibrary/plugins/worksearch/code.py
8112-
msgid "eBook?"
8113-
msgstr ""
8114-
8115-
#: openlibrary/plugins/worksearch/code.py
8116-
msgid "First published"
8117-
msgstr ""
8118-
8119-
#: openlibrary/plugins/worksearch/code.py
8120-
msgid "Classic eBooks"
8025+
#: openlibrary/plugins/openlibrary/lists.py
8026+
#, python-format
8027+
msgid "Are you sure you want to remove <strong>%(title)s</strong> from your list?"
81218028
msgstr ""
81228029

81238030
#: openlibrary/core/edits.py

openlibrary/macros/LoanStatus.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
$elif book_provider and book_provider.short_name != 'ia':
5858
$# Partner Trusted Book Provider Read Buttons
59-
$:book_provider.render_read_button(doc, analytics_attr)
59+
$:book_provider.render_read_button(edition_key, doc, analytics_attr)
6060

6161
$elif availability.get('is_readable') or availability.get('status') == 'open':
6262
$# Open / Publicly Readable (Unrestricted)

openlibrary/plugins/openlibrary/js/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ jQuery(function () {
518518
.then(module => module.initBreadcrumbSelect(crumbs));
519519
}
520520

521+
const interstitial = document.querySelector('.interstitial');
522+
if (interstitial) {
523+
import (/* webpackChunkName: "interstitial" */ './interstitial')
524+
.then(module => module.initInterstitial(interstitial));
525+
}
526+
521527
const leaveWaitlistLinks = document.querySelectorAll('a.leave');
522528
if (leaveWaitlistLinks.length && document.getElementById('leave-waitinglist-dialog')) {
523529
import(/* webpackChunkName: "waitlist" */ './waitlist')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function initInterstitial(elem) {
2+
let seconds = elem.dataset.wait
3+
const url = elem.dataset.url
4+
const timerElement = elem.querySelector('#timer')
5+
const countdown = setInterval(() => {
6+
seconds--
7+
timerElement.textContent = seconds
8+
if (seconds === 0) {
9+
clearInterval(countdown)
10+
window.location.href = url
11+
}
12+
}, 1000) // 1 second interval
13+
}

openlibrary/plugins/upstream/borrow.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from openlibrary import accounts
2727
from openlibrary.accounts.model import OpenLibraryAccount
28+
from openlibrary.app import render_template
2829
from openlibrary.core import (
2930
lending,
3031
models, # noqa: F401 side effects may be needed
@@ -143,11 +144,12 @@ def POST(self, key): # noqa: PLR0915
143144
and acquisitions[0].access == "open-access"
144145
):
145146
stats.increment('ol.loans.webbook')
146-
# Change this to a template call, e.g.
147-
# not sure if provider.name is a thing...
148-
# XXX The problem with this approach is it will not open in a new window (maybe that's okay)
149-
# render_template("interstitial", url=acquisitions[0].url, provider=provider.name, wait=5)
150-
raise web.seeother(acquisitions[0].url)
147+
# def with(url, provider_name="", wait=5)
148+
return render_template(
149+
"interstitial",
150+
url=acquisitions[0].url,
151+
provider_name=acquisitions[0].provider_name,
152+
)
151153

152154
archive_url = get_bookreader_stream_url(edition.ocaid) + '?ref=ol'
153155
if i._autoReadAloud is not None:
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
$def with(cita_press_id)
1+
$def with(edition_key, cita_press_id)
22

33
<div class="cta-button-group">
4-
<a
5-
href="https://citapress.org/$cita_press_id"
4+
<a href="/books/${edition_key}/-/borrow?action=read"
65
title="$_('Read eBook from Cita Press')"
76
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--cita-press"
87
target="_blank"
9-
aria-haspopup="true"
10-
aria-controls="cita-press-toast"
118
>$_('Read')</a>
129
</div>
13-
14-
$if render_once('cita-press-toast'):
15-
<div class="toast toast--book-provider" data-toast-trigger=".cta-btn--openstax" id="cita-press-toast" style="display:none">
16-
<div class="toast__body">
17-
$:_('This book is available from <a href="https://citapress.org/">Cita Press</a>. Cita Press is a trusted book provider of works written by women, pairing contemporary authors and designers with open access texts to make carefully designed books available for free and open source.')
18-
<a href="https://citapress.org/about/">$_('Learn more')</a>
19-
</div>
20-
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
21-
</div>

0 commit comments

Comments
 (0)