Skip to content

Commit

Permalink
Merge pull request #10053 from cdrini/reenable-donations
Browse files Browse the repository at this point in the history
Re-enable donations banner
  • Loading branch information
cdrini authored Nov 20, 2024
2 parents 1425c88 + 07615c0 commit dedebe7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
27 changes: 0 additions & 27 deletions openlibrary/plugins/upstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,33 +1434,6 @@ def jsdef_get(obj, key, default=None):
return obj.get(key, default)


@public
def get_donation_include() -> str:
ia_host = get_ia_host(allow_dev=True)
# The following allows archive.org staff to test banners without
# needing to reload openlibrary services
if ia_host != "archive.org":
script_src = f"https://{ia_host}/includes/donate.js"
else:
script_src = "/cdn/archive.org/donate.js"

if 'ymd' in (web_input := web.input()):
# Should be eg 20220101 (YYYYMMDD)
if len(web_input.ymd) == 8 and web_input.ymd.isdigit():
script_src += '?' + urllib.parse.urlencode({'ymd': web_input.ymd})
else:
raise ValueError('?ymd should be 8 digits (eg 20220101)')

html = (
"""
<div id="donato"></div>
<script src="%s" data-platform="ol"></script>
"""
% script_src
)
return html


@public
def get_ia_host(allow_dev: bool = False) -> str:
if allow_dev:
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/templates/site/alert.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$if False and not is_bot():
$:get_donation_include()
$if not is_bot():
$:render_template('site/donation_banner')

$ lang = get_lang() or 'en'
$ supported_languages = get_supported_languages()
Expand Down
3 changes: 0 additions & 3 deletions openlibrary/templates/site/donate.html

This file was deleted.

13 changes: 13 additions & 0 deletions openlibrary/templates/site/donation_banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ ia_host = get_ia_host(allow_dev=True)

$# The following allows archive.org staff to test banners without
$# needing to reload openlibrary services
$# Note donate.js also reads the ?ymd=YYYYMMDD parameter and the
$# `variant` parameter.
$if ia_host != "archive.org":
$ script_src = "https://%s/includes/donate.js" % ia_host
$else:
$ script_src = "/cdn/archive.org/donate.js"

<div id="donato"></div>
<script src="$script_src" data-platform="ol"></script>

0 comments on commit dedebe7

Please sign in to comment.