Skip to content

Merge interstitial branch into main branch #10605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
967c5e7
nonworking prototype of trusted book provider interstitial
mekarpeles Mar 11, 2025
3a9f135
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 11, 2025
9063d0a
fix i18n
mekarpeles Mar 14, 2025
142b054
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 14, 2025
970874f
Clean up interstitial template and add borrow API behavior for redire…
SivanC Mar 15, 2025
fc39e70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2025
bb82593
Remove toasts from most non-IA book provider templates
SivanC Mar 15, 2025
e2b9060
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2025
afa211b
Add interstitial for librivox and direct read previews
SivanC Mar 15, 2025
6672d7c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2025
0a13881
remove domain from url
mekarpeles Mar 15, 2025
5dda402
Improve appearance and text of interstitial
SivanC Mar 17, 2025
114cd61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 17, 2025
ac55366
Remove domains from remaining templates
SivanC Mar 17, 2025
141bc24
Remove toast related tags, move countdown to JS file
SivanC Mar 20, 2025
45ee297
Remove comments
jimchamp Mar 20, 2025
6978961
Merge pull request #10586 from SivanC/trustedbookprovider-interstitial
jimchamp Mar 20, 2025
124e9f2
Merge branch 'master' into trustedbookprovider-interstitial
jimchamp Mar 21, 2025
e06f960
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2025
9731176
Remove comment
jimchamp Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions openlibrary/book_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ def get_template_path(self, typ: Literal['read_button', 'download_options']) ->
return f"book_providers/{self.short_name}_{typ}.html"

def render_read_button(
self, ed_or_solr: Edition | dict, analytics_attr: Callable[[str], str]
self,
edition_key: str,
ed_or_solr: Edition | dict,
analytics_attr: Callable[[str], str],
) -> TemplateResult:
return render_template(
self.get_template_path('read_button'),
edition_key,
self.get_best_identifier(ed_or_solr),
analytics_attr,
)
Expand Down Expand Up @@ -495,7 +499,10 @@ def get_identifiers(self, ed_or_solr: Edition | dict) -> list[str]:
return []

def render_read_button(
self, ed_or_solr: Edition | dict, analytics_attr: Callable[[str], str]
self,
edition_key: str,
ed_or_solr: Edition | dict,
analytics_attr: Callable[[str], str],
) -> TemplateResult | str:
acq_sorted = sorted(
(
Expand All @@ -519,7 +526,7 @@ def render_read_button(
parsed_url = parse.urlparse(url)
domain = parsed_url.netloc
return render_template(
self.get_template_path('read_button'), acquisition, domain
self.get_template_path('read_button'), edition_key, acquisition, domain
)

def render_download_options(self, edition: Edition, extra_args: list | None = None):
Expand Down
123 changes: 28 additions & 95 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,33 @@ msgid ""
"page</a>?"
msgstr ""

#: interstitial.html
msgid "You are being redirected to your book"
msgstr ""

#: interstitial.html
#, python-format
msgid ""
"This book is provided by %(book_provider)s, a third-party Open Library "
"Trusted Book Provider"
msgstr ""

#: interstitial.html
#, python-format
msgid "In %(time)s seconds, you will be automatically redirected to: %(url)s"
msgstr ""

#: CreateListModal.html EditButtons.html account/notifications.html
#: account/password/reset.html account/privacy.html admin/imports-add.html
#: admin/permissions.html books/add.html databarEdit.html interstitial.html
#: merge/authors.html my_books/dropdown_content.html type/tag/form.html
msgid "Cancel"
msgstr ""

#: interstitial.html
msgid "Continue without waiting"
msgstr ""

#: lib/nav_head.html library_explorer.html
msgid "Library Explorer"
msgstr ""
Expand Down Expand Up @@ -563,15 +590,7 @@ msgid "Thank you very much for improving that record!"
msgstr ""

#: BookPreview.html CreateListModal.html DonateModal.html NotesModal.html
#: ObservationsModal.html ShareModal.html
#: book_providers/cita_press_read_button.html
#: book_providers/direct_read_button.html
#: book_providers/gutenberg_read_button.html
#: book_providers/librivox_read_button.html
#: book_providers/openstax_read_button.html
#: book_providers/runeberg_read_button.html
#: book_providers/standard_ebooks_read_button.html
#: book_providers/wikisource_read_button.html covers/author_photo.html
#: ObservationsModal.html ShareModal.html covers/author_photo.html
#: covers/book_cover.html covers/book_cover_single_edition.html
#: covers/book_cover_work.html covers/change.html lib/history.html
#: my_books/dropdown_content.html native_dialog.html
Expand Down Expand Up @@ -1436,13 +1455,6 @@ msgstr ""
msgid "Save"
msgstr ""

#: CreateListModal.html EditButtons.html account/notifications.html
#: account/password/reset.html account/privacy.html admin/imports-add.html
#: admin/permissions.html books/add.html databarEdit.html merge/authors.html
#: my_books/dropdown_content.html type/tag/form.html
msgid "Cancel"
msgstr ""

#: EditionNavBar.html account/observations.html
#: books/mybooks_breadcrumb_select.html openlibrary/plugins/upstream/mybooks.py
msgid "Reviews"
Expand Down Expand Up @@ -2853,36 +2865,10 @@ msgstr ""
msgid "Read eBook from Cita Press"
msgstr ""

#: book_providers/cita_press_read_button.html
msgid ""
"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."
msgstr ""

#: book_providers/cita_press_read_button.html
#: book_providers/direct_read_button.html
#: book_providers/gutenberg_read_button.html
#: book_providers/librivox_read_button.html
#: book_providers/openstax_read_button.html
#: book_providers/runeberg_read_button.html
#: book_providers/standard_ebooks_read_button.html
#: book_providers/wikisource_read_button.html
msgid "Learn more"
msgstr ""

#: book_providers/direct_read_button.html
msgid "Read free online"
msgstr ""

#: book_providers/direct_read_button.html
#, python-format
msgid ""
"This book is freely available from <a href=\"%s\">%s</a>, an external "
"third-party book provider."
msgstr ""

#: book_providers/gutenberg_download_options.html
msgid "Download an HTML from Project Gutenberg"
msgstr ""
Expand Down Expand Up @@ -2922,15 +2908,6 @@ msgstr ""
msgid "Read eBook from Project Gutenberg"
msgstr ""

#: book_providers/gutenberg_read_button.html
msgid ""
"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."
msgstr ""

#: book_providers/ia_download_options.html
msgid "Download a PDF from Internet Archive"
msgstr ""
Expand Down Expand Up @@ -2987,14 +2964,6 @@ msgstr ""
msgid "Audiobook"
msgstr ""

#: book_providers/librivox_read_button.html
msgid ""
"This book is available from <a "
"href=\"https://librivox.org/\">LibriVox</a>. LibriVox is a trusted book "
"provider of public domain audiobooks, narrated by volunteers, distributed"
" for free on the internet."
msgstr ""

#: book_providers/openstax_download_options.html
msgid "Download PDF from OpenStax"
msgstr ""
Expand All @@ -3007,15 +2976,6 @@ msgstr ""
msgid "Read eBook from OpenStax"
msgstr ""

#: book_providers/openstax_read_button.html
msgid ""
"This book is available from <a "
"href=\"https://www.openstax.org/\">OpenStax</a>. OpenStax is a trusted "
"book provider and a 501(c)(3) nonprofit charitable corporation dedicated "
"to providing free high-quality, peer-reviewed, openly licensed textbooks "
"online."
msgstr ""

#: book_providers/runeberg_download_options.html
msgid "Download all scanned images from Project Runeberg"
msgstr ""
Expand Down Expand Up @@ -3060,13 +3020,6 @@ msgstr ""
msgid "Read eBook from Project Runeberg"
msgstr ""

#: book_providers/runeberg_read_button.html
msgid ""
"This book is available from <a href=\"https://runeberg.org/\">Project "
"Runeberg</a>. Project Runeberg is a trusted book provider of classic "
"Nordic (Scandinavian) literature in electronic form."
msgstr ""

#: book_providers/standard_ebooks_download_options.html
msgid "Download an HTML from Standard Ebooks"
msgstr ""
Expand Down Expand Up @@ -3107,15 +3060,6 @@ msgstr ""
msgid "Read eBook from Standard eBooks"
msgstr ""

#: book_providers/standard_ebooks_read_button.html
msgid ""
"This book is available from <a "
"href=\"https://standardebooks.org/\">Standard Ebooks</a>. Standard Ebooks"
" is a trusted book provider and a volunteer-driven project that produces "
"new editions of public domain ebooks that are lovingly formatted, open "
"source, free of copyright restrictions, and free of cost."
msgstr ""

#: book_providers/wikisource_download_options.html
msgid "Download PDF from Wikisource"
msgstr ""
Expand Down Expand Up @@ -3144,17 +3088,6 @@ msgstr ""
msgid "Read eBook on Wikisource"
msgstr ""

#: book_providers/wikisource_read_button.html
msgid ""
"This book is available from <a "
"href=\"https://wikisource.org/\">Wikisource</a>. Wikisource, a <a "
"href=\"https://www.wikimedia.org/\">Wikimedia Foundation</a> project, is "
"a trusted book provider of works available under the <a "
"href=\"https://creativecommons.org/licenses/by-sa/4.0/\">CC-BY-SA</a> "
"open content license, such as essays, historical documents, letters, "
"speeches, and public domain books."
msgstr ""

#: books/RelatedWorksCarousel.html
msgid "You might also like"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/macros/LoanStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

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

$elif availability.get('is_readable') or availability.get('status') == 'open':
$# Open / Publicly Readable (Unrestricted)
Expand Down
6 changes: 6 additions & 0 deletions openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ jQuery(function () {
.then(module => module.initBreadcrumbSelect(crumbs));
}

const interstitial = document.querySelector('.interstitial');
if (interstitial) {
import (/* webpackChunkName: "interstitial" */ './interstitial')
.then(module => module.initInterstitial(interstitial));
}

const leaveWaitlistLinks = document.querySelectorAll('a.leave');
if (leaveWaitlistLinks.length && document.getElementById('leave-waitinglist-dialog')) {
import(/* webpackChunkName: "waitlist" */ './waitlist')
Expand Down
13 changes: 13 additions & 0 deletions openlibrary/plugins/openlibrary/js/interstitial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function initInterstitial(elem) {
let seconds = elem.dataset.wait
const url = elem.dataset.url
const timerElement = elem.querySelector('#timer')
const countdown = setInterval(() => {
seconds--
timerElement.textContent = seconds
if (seconds === 0) {
clearInterval(countdown)
window.location.href = url
}
}, 1000) // 1 second interval
}
7 changes: 6 additions & 1 deletion openlibrary/plugins/upstream/borrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from openlibrary import accounts
from openlibrary.accounts.model import OpenLibraryAccount
from openlibrary.app import render_template
from openlibrary.core import (
lending,
models, # noqa: F401 side effects may be needed
Expand Down Expand Up @@ -143,7 +144,11 @@ def POST(self, key): # noqa: PLR0915
and acquisitions[0].access == "open-access"
):
stats.increment('ol.loans.webbook')
raise web.seeother(acquisitions[0].url)
return render_template(
"interstitial",
url=acquisitions[0].url,
provider_name=acquisitions[0].provider_name,
)

archive_url = get_bookreader_stream_url(edition.ocaid) + '?ref=ol'
if i._autoReadAloud is not None:
Expand Down
16 changes: 2 additions & 14 deletions openlibrary/templates/book_providers/cita_press_read_button.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
$def with(cita_press_id)
$def with(edition_key, cita_press_id)

<div class="cta-button-group">
<a
href="https://citapress.org/$cita_press_id"
<a href="/books/${edition_key}/-/borrow?action=read"
title="$_('Read eBook from Cita Press')"
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--cita-press"
target="_blank"
aria-haspopup="true"
aria-controls="cita-press-toast"
>$_('Read')</a>
</div>

$if render_once('cita-press-toast'):
<div class="toast toast--book-provider" data-toast-trigger=".cta-btn--openstax" id="cita-press-toast" style="display:none">
<div class="toast__body">
$:_('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.')
<a href="https://citapress.org/about/">$_('Learn more')</a>
</div>
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
</div>
26 changes: 5 additions & 21 deletions openlibrary/templates/book_providers/direct_read_button.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
$def with(acquisition, domain)
$def with(edition_key, acquisition, domain)
$# :param edition_key str:
$# :param Acquisition acquisition:
$# :param domain str:
$ clean_domain = domain.replace(".", "")

$if acquisition.access == 'open-access':
<div class="cta-button-group">
<a
href="$(acquisition.url)"
<a href="/books/${edition_key}/-/borrow?action=read"
title="$_('Read free online')"
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--direct"
target="_blank"
aria-haspopup="true"
aria-controls="direct-provider-toast-$(clean_domain)"
>$_('Read')</a>
</div>

$elif acquisition.access == 'sample':
<div class="cta-button-group">
<a class="cta-btn cta-btn--shell cta-btn--external"
<a href="http://openlibrary.org/books/${edition_key}/-/borrow?action=read"
class="cta-btn cta-btn--shell cta-btn--external"
data-ol-link-track="CTAClick|Preview"
target="_blank"
href="$(acquisition.url)"
>$_('Preview')</a>
</div>

$if render_once('direct-provider-toast-' + clean_domain):
<div
class="toast toast--book-provider"
data-toast-trigger="[aria-controls=direct-provider-toast-$(clean_domain)]"
id="direct-provider-toast-$(clean_domain)"
style="display:none"
>
<div class="toast__body">
$:_('This book is freely available from <a href="%s">%s</a>, an external third-party book provider.', acquisition.url, domain)
<a href="/trusted-book-providers#web-books">$_('Learn more')<a>
</div>
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
</div>
16 changes: 2 additions & 14 deletions openlibrary/templates/book_providers/gutenberg_read_button.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
$def with(gutenberg_id, analytics_attr)
$def with(edition_key, gutenberg_id, analytics_attr)

<div class="cta-button-group">
<a
href="https://www.gutenberg.org/ebooks/$gutenberg_id"
<a href="/books/${edition_key}/-/borrow?action=read"
title="$_('Read eBook from Project Gutenberg')"
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--gutenberg"
target="_blank"
$:analytics_attr('Read')
aria-haspopup="true"
aria-controls="gutenberg-toast"
>$_('Read')</a>
</div>

$if render_once('gutenberg-toast'):
<div class="toast toast--book-provider" data-toast-trigger=".cta-btn--gutenberg" id="gutenberg-toast" style="display:none">
<div class="toast__body">
$:_('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.')
<a href="https://www.gutenberg.org/about/">$_("Learn more")</a>
</div>
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
</div>
Loading
Loading