Skip to content

Commit 7696f8c

Browse files
authored
Merge pull request #10605 from internetarchive/trustedbookprovider-interstitial
Merge interstitial branch into main branch
2 parents 298fe55 + 9731176 commit 7696f8c

15 files changed

+104
-215
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: 28 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,33 @@ msgid ""
454454
"page</a>?"
455455
msgstr ""
456456

457+
#: interstitial.html
458+
msgid "You are being redirected to your book"
459+
msgstr ""
460+
461+
#: interstitial.html
462+
#, python-format
463+
msgid ""
464+
"This book is provided by %(book_provider)s, a third-party Open Library "
465+
"Trusted Book Provider"
466+
msgstr ""
467+
468+
#: interstitial.html
469+
#, python-format
470+
msgid "In %(time)s seconds, you will be automatically redirected to: %(url)s"
471+
msgstr ""
472+
473+
#: CreateListModal.html EditButtons.html account/notifications.html
474+
#: account/password/reset.html account/privacy.html admin/imports-add.html
475+
#: admin/permissions.html books/add.html databarEdit.html interstitial.html
476+
#: merge/authors.html my_books/dropdown_content.html type/tag/form.html
477+
msgid "Cancel"
478+
msgstr ""
479+
480+
#: interstitial.html
481+
msgid "Continue without waiting"
482+
msgstr ""
483+
457484
#: lib/nav_head.html library_explorer.html
458485
msgid "Library Explorer"
459486
msgstr ""
@@ -563,15 +590,7 @@ msgid "Thank you very much for improving that record!"
563590
msgstr ""
564591

565592
#: BookPreview.html CreateListModal.html DonateModal.html NotesModal.html
566-
#: ObservationsModal.html ShareModal.html
567-
#: book_providers/cita_press_read_button.html
568-
#: book_providers/direct_read_button.html
569-
#: book_providers/gutenberg_read_button.html
570-
#: book_providers/librivox_read_button.html
571-
#: book_providers/openstax_read_button.html
572-
#: book_providers/runeberg_read_button.html
573-
#: book_providers/standard_ebooks_read_button.html
574-
#: book_providers/wikisource_read_button.html covers/author_photo.html
593+
#: ObservationsModal.html ShareModal.html covers/author_photo.html
575594
#: covers/book_cover.html covers/book_cover_single_edition.html
576595
#: covers/book_cover_work.html covers/change.html lib/history.html
577596
#: my_books/dropdown_content.html native_dialog.html
@@ -1436,13 +1455,6 @@ msgstr ""
14361455
msgid "Save"
14371456
msgstr ""
14381457

1439-
#: CreateListModal.html EditButtons.html account/notifications.html
1440-
#: account/password/reset.html account/privacy.html admin/imports-add.html
1441-
#: admin/permissions.html books/add.html databarEdit.html merge/authors.html
1442-
#: my_books/dropdown_content.html type/tag/form.html
1443-
msgid "Cancel"
1444-
msgstr ""
1445-
14461458
#: EditionNavBar.html account/observations.html
14471459
#: books/mybooks_breadcrumb_select.html openlibrary/plugins/upstream/mybooks.py
14481460
msgid "Reviews"
@@ -2853,36 +2865,10 @@ msgstr ""
28532865
msgid "Read eBook from Cita Press"
28542866
msgstr ""
28552867

2856-
#: book_providers/cita_press_read_button.html
2857-
msgid ""
2858-
"This book is available from <a href=\"https://citapress.org/\">Cita "
2859-
"Press</a>. Cita Press is a trusted book provider of works written by "
2860-
"women, pairing contemporary authors and designers with open access texts "
2861-
"to make carefully designed books available for free and open source."
2862-
msgstr ""
2863-
2864-
#: book_providers/cita_press_read_button.html
2865-
#: book_providers/direct_read_button.html
2866-
#: book_providers/gutenberg_read_button.html
2867-
#: book_providers/librivox_read_button.html
2868-
#: book_providers/openstax_read_button.html
2869-
#: book_providers/runeberg_read_button.html
2870-
#: book_providers/standard_ebooks_read_button.html
2871-
#: book_providers/wikisource_read_button.html
2872-
msgid "Learn more"
2873-
msgstr ""
2874-
28752868
#: book_providers/direct_read_button.html
28762869
msgid "Read free online"
28772870
msgstr ""
28782871

2879-
#: book_providers/direct_read_button.html
2880-
#, python-format
2881-
msgid ""
2882-
"This book is freely available from <a href=\"%s\">%s</a>, an external "
2883-
"third-party book provider."
2884-
msgstr ""
2885-
28862872
#: book_providers/gutenberg_download_options.html
28872873
msgid "Download an HTML from Project Gutenberg"
28882874
msgstr ""
@@ -2922,15 +2908,6 @@ msgstr ""
29222908
msgid "Read eBook from Project Gutenberg"
29232909
msgstr ""
29242910

2925-
#: book_providers/gutenberg_read_button.html
2926-
msgid ""
2927-
"This book is available from <a "
2928-
"href=\"https://www.gutenberg.org/\">Project Gutenberg</a>. Project "
2929-
"Gutenberg is a trusted book provider of classic ebooks, supporting "
2930-
"thousands of volunteers in the creation and distribution of over 60,000 "
2931-
"free eBooks."
2932-
msgstr ""
2933-
29342911
#: book_providers/ia_download_options.html
29352912
msgid "Download a PDF from Internet Archive"
29362913
msgstr ""
@@ -2987,14 +2964,6 @@ msgstr ""
29872964
msgid "Audiobook"
29882965
msgstr ""
29892966

2990-
#: book_providers/librivox_read_button.html
2991-
msgid ""
2992-
"This book is available from <a "
2993-
"href=\"https://librivox.org/\">LibriVox</a>. LibriVox is a trusted book "
2994-
"provider of public domain audiobooks, narrated by volunteers, distributed"
2995-
" for free on the internet."
2996-
msgstr ""
2997-
29982967
#: book_providers/openstax_download_options.html
29992968
msgid "Download PDF from OpenStax"
30002969
msgstr ""
@@ -3007,15 +2976,6 @@ msgstr ""
30072976
msgid "Read eBook from OpenStax"
30082977
msgstr ""
30092978

3010-
#: book_providers/openstax_read_button.html
3011-
msgid ""
3012-
"This book is available from <a "
3013-
"href=\"https://www.openstax.org/\">OpenStax</a>. OpenStax is a trusted "
3014-
"book provider and a 501(c)(3) nonprofit charitable corporation dedicated "
3015-
"to providing free high-quality, peer-reviewed, openly licensed textbooks "
3016-
"online."
3017-
msgstr ""
3018-
30192979
#: book_providers/runeberg_download_options.html
30202980
msgid "Download all scanned images from Project Runeberg"
30212981
msgstr ""
@@ -3060,13 +3020,6 @@ msgstr ""
30603020
msgid "Read eBook from Project Runeberg"
30613021
msgstr ""
30623022

3063-
#: book_providers/runeberg_read_button.html
3064-
msgid ""
3065-
"This book is available from <a href=\"https://runeberg.org/\">Project "
3066-
"Runeberg</a>. Project Runeberg is a trusted book provider of classic "
3067-
"Nordic (Scandinavian) literature in electronic form."
3068-
msgstr ""
3069-
30703023
#: book_providers/standard_ebooks_download_options.html
30713024
msgid "Download an HTML from Standard Ebooks"
30723025
msgstr ""
@@ -3107,15 +3060,6 @@ msgstr ""
31073060
msgid "Read eBook from Standard eBooks"
31083061
msgstr ""
31093062

3110-
#: book_providers/standard_ebooks_read_button.html
3111-
msgid ""
3112-
"This book is available from <a "
3113-
"href=\"https://standardebooks.org/\">Standard Ebooks</a>. Standard Ebooks"
3114-
" is a trusted book provider and a volunteer-driven project that produces "
3115-
"new editions of public domain ebooks that are lovingly formatted, open "
3116-
"source, free of copyright restrictions, and free of cost."
3117-
msgstr ""
3118-
31193063
#: book_providers/wikisource_download_options.html
31203064
msgid "Download PDF from Wikisource"
31213065
msgstr ""
@@ -3144,17 +3088,6 @@ msgstr ""
31443088
msgid "Read eBook on Wikisource"
31453089
msgstr ""
31463090

3147-
#: book_providers/wikisource_read_button.html
3148-
msgid ""
3149-
"This book is available from <a "
3150-
"href=\"https://wikisource.org/\">Wikisource</a>. Wikisource, a <a "
3151-
"href=\"https://www.wikimedia.org/\">Wikimedia Foundation</a> project, is "
3152-
"a trusted book provider of works available under the <a "
3153-
"href=\"https://creativecommons.org/licenses/by-sa/4.0/\">CC-BY-SA</a> "
3154-
"open content license, such as essays, historical documents, letters, "
3155-
"speeches, and public domain books."
3156-
msgstr ""
3157-
31583091
#: books/RelatedWorksCarousel.html
31593092
msgid "You might also like"
31603093
msgstr ""

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: 6 additions & 1 deletion
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,7 +144,11 @@ def POST(self, key): # noqa: PLR0915
143144
and acquisitions[0].access == "open-access"
144145
):
145146
stats.increment('ol.loans.webbook')
146-
raise web.seeother(acquisitions[0].url)
147+
return render_template(
148+
"interstitial",
149+
url=acquisitions[0].url,
150+
provider_name=acquisitions[0].provider_name,
151+
)
147152

148153
archive_url = get_bookreader_stream_url(edition.ocaid) + '?ref=ol'
149154
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>
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
$def with(acquisition, domain)
1+
$def with(edition_key, acquisition, domain)
2+
$# :param edition_key str:
23
$# :param Acquisition acquisition:
34
$# :param domain str:
45
$ clean_domain = domain.replace(".", "")
56

67
$if acquisition.access == 'open-access':
78
<div class="cta-button-group">
8-
<a
9-
href="$(acquisition.url)"
9+
<a href="/books/${edition_key}/-/borrow?action=read"
1010
title="$_('Read free online')"
1111
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--direct"
1212
target="_blank"
13-
aria-haspopup="true"
14-
aria-controls="direct-provider-toast-$(clean_domain)"
1513
>$_('Read')</a>
1614
</div>
1715

1816
$elif acquisition.access == 'sample':
1917
<div class="cta-button-group">
20-
<a class="cta-btn cta-btn--shell cta-btn--external"
18+
<a href="http://openlibrary.org/books/${edition_key}/-/borrow?action=read"
19+
class="cta-btn cta-btn--shell cta-btn--external"
2120
data-ol-link-track="CTAClick|Preview"
2221
target="_blank"
23-
href="$(acquisition.url)"
2422
>$_('Preview')</a>
2523
</div>
26-
27-
$if render_once('direct-provider-toast-' + clean_domain):
28-
<div
29-
class="toast toast--book-provider"
30-
data-toast-trigger="[aria-controls=direct-provider-toast-$(clean_domain)]"
31-
id="direct-provider-toast-$(clean_domain)"
32-
style="display:none"
33-
>
34-
<div class="toast__body">
35-
$:_('This book is freely available from <a href="%s">%s</a>, an external third-party book provider.', acquisition.url, domain)
36-
<a href="/trusted-book-providers#web-books">$_('Learn more')<a>
37-
</div>
38-
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
39-
</div>
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
$def with(gutenberg_id, analytics_attr)
1+
$def with(edition_key, gutenberg_id, analytics_attr)
22

33
<div class="cta-button-group">
4-
<a
5-
href="https://www.gutenberg.org/ebooks/$gutenberg_id"
4+
<a href="/books/${edition_key}/-/borrow?action=read"
65
title="$_('Read eBook from Project Gutenberg')"
76
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--gutenberg"
87
target="_blank"
98
$:analytics_attr('Read')
10-
aria-haspopup="true"
11-
aria-controls="gutenberg-toast"
129
>$_('Read')</a>
1310
</div>
14-
15-
$if render_once('gutenberg-toast'):
16-
<div class="toast toast--book-provider" data-toast-trigger=".cta-btn--gutenberg" id="gutenberg-toast" style="display:none">
17-
<div class="toast__body">
18-
$:_('This book is available from <a href="https://www.gutenberg.org/">Project Gutenberg</a>. Project Gutenberg is a trusted book provider of classic ebooks, supporting thousands of volunteers in the creation and distribution of over 60,000 free eBooks.')
19-
<a href="https://www.gutenberg.org/about/">$_("Learn more")</a>
20-
</div>
21-
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
22-
</div>

0 commit comments

Comments
 (0)