Skip to content

Commit

Permalink
Add new custom_banner to head_insert template
Browse files Browse the repository at this point in the history
For use in frameless replay only
  • Loading branch information
tw4l committed Oct 17, 2022
1 parent a251082 commit 92d757e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pywb/apps/rewriterapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ def __init__(self, framed_replay=False, jinja_env=None, config=None, paths=None)
self.redirect_to_exact = config.get('redirect_to_exact')

self.banner_view = BaseInsertView(self.jinja_env, self._html_templ('banner_html'))
self.custom_banner_view = BaseInsertView(self.jinja_env, self._html_templ('custom_banner_html'))

self.head_insert_view = HeadInsertView(self.jinja_env,
self._html_templ('head_insert_html'),
self.banner_view)
self.custom_banner_view)

self.frame_insert_view = TopFrameView(self.jinja_env,
self._html_templ('frame_insert_html'),
Expand Down
2 changes: 2 additions & 0 deletions pywb/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ templates_dir: templates

# Template HTML
banner_html: banner.html
custom_banner_html: custom_banner.html
head_insert_html: head_insert.html
frame_insert_html: frame_insert.html

Expand All @@ -36,6 +37,7 @@ info_json: collinfo.json
# HTML Templates List
html_templates:
- banner_html
- custom_banner_html
- head_insert_html
- frame_insert_html

Expand Down
2 changes: 1 addition & 1 deletion pywb/rewrite/templateview.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def make_head_insert(rule, cdx):

if self.banner_view:
banner_html = self.banner_view.render_to_string(env, cdx=cdx, **params)
params['banner_html'] = banner_html
params['custom_banner_html'] = banner_html

return self.render_to_string(env, cdx=cdx, **params)

Expand Down
1 change: 1 addition & 0 deletions pywb/templates/custom_banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- Add custom banner here. Used only in non-framed replay. -->
6 changes: 6 additions & 0 deletions pywb/templates/head_insert.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@

{% endif %}

{% if not is_framed %}

{{ custom_banner_html }}

{% endif %}

{% endautoescape %}

<!-- End WB Insert -->
Expand Down
16 changes: 8 additions & 8 deletions tests/test_auto_colls.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,19 @@ def test_custom_template_search(self):
assert 'pywb custom search page' in resp.text

def test_add_custom_banner(self):
""" Test adding custom banner.html per-collection template
""" Test adding custom_banner.html per-collection template
"""

banner_file = os.path.join(self.root_dir, COLLECTIONS, 'test',
'templates', 'banner.html')
'templates', 'custom_banner.html')

with open(banner_file, 'w+b') as fh:
fh.write(b'<div>Custom Banner Here!</div>')
fh.write(b'\n{{ metadata | tojson }}')

def test_add_custom_banner_replay(self, fmod):
resp = self.get('/test/20140103030321/http://example.com/?example=1', fmod)
def test_add_custom_banner_replay(self):
"""Test custom banner appears in unframed replay."""
resp = self.get('/test/20140103030321/http://example.com/?example=1', None)
assert '<div>Custom Banner Here!</div>' in resp.text

def test_more_custom_templates(self):
Expand Down Expand Up @@ -316,10 +317,9 @@ def test_more_custom_templates(self):
#assert '"some":"value"' in resp.text, resp.text
assert '{&#34;some&#34;:&#34;value&#34;}' in resp.text, resp.text

def test_replay_banner_metadata(self, fmod):
""" Test adding metadata in replay banner (both framed and non-frame)
"""
resp = self.get('/test/20140103030321{0}/http://example.com/?example=1', fmod)
def test_replay_banner_metadata(self):
"""Test adding metadata in custom banner for unframed replay."""
resp = self.get('/test/20140103030321/http://example.com/?example=1', None)
assert '<div>Custom Banner Here!</div>' in resp.text
#assert '"some":"value"' in resp.text
assert '{&#34;some&#34;:&#34;value&#34;}' in resp.text, resp.text
Expand Down
1 change: 0 additions & 1 deletion tests/test_prefixed_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_replay_content(self, fmod):

assert '"20140127171238"' in resp.text, resp.text
assert "'http://localhost:80/prefix/static/wombat.js'" in resp.text
assert "http://localhost:80/prefix/static/vue/vueui.js" in resp.text
assert '"http://localhost:80/prefix/static/"' in resp.text
assert '"http://localhost:80/prefix/pywb/"' in resp.text
assert 'WBWombatInit' in resp.text, resp.text
Expand Down

0 comments on commit 92d757e

Please sign in to comment.