1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +01:00

fixes based on feedback from @ldko!

templates:
- add placeholder footer.html, head.html templates
- allow 'base_html', 'footer_html', 'head_html', 'header_html' to be added via wb-manager 'add-template' cmd
- automatically add 'base.html' when adding a copy of other templates, as jinja2 extends looks for templates locally

ui tweaks:
- vueui: support logo loaded from ui.logo
- make logo link to home page
- home page: don't show collection title if title is empty

documentation tweaks:
- clarify static_path is for loading path
- clarify footer and head templates are empty by default
- remove extra is_framed from top frame template documentation

bump to 2.7.0b1
This commit is contained in:
Ilya Kreymer 2022-01-23 17:55:24 -08:00
parent 18c09266e6
commit 613754307c
13 changed files with 57 additions and 18 deletions

View File

@ -60,6 +60,15 @@ When using the custom banner, it is possible to configure a logo by setting ``ui
If omitted, the standard pywb logo will be used by default. If omitted, the standard pywb logo will be used by default.
If set, the logo should point to a file in the static directory (default is ``static`` but can be changed via the ``static_dir`` config option).
For example, to use the file ``./static/my-logo.png`` as the logo, set:
.. code:: yaml
ui:
logo: my-logo.png
Updating the Vue UI Updating the Vue UI
------------------- -------------------

View File

@ -61,6 +61,9 @@ can also be overriden:
* ``footer.html`` -- Template for adding content as the "footer" of the ``<body>`` tag of the ``base`` template * ``footer.html`` -- Template for adding content as the "footer" of the ``<body>`` tag of the ``base`` template
Note: The default pywb ``head.html`` and ``footer.html`` are currently blank. They can be populated to customize the rendering, add analytics, etc... as needed.
The ``base.html`` template also provides five blocks that can be supplied by templates that extend it. The ``base.html`` template also provides five blocks that can be supplied by templates that extend it.
* ``title`` -- Block for supplying the title for the page * ``title`` -- Block for supplying the title for the page
@ -157,7 +160,7 @@ Template variables:
* ``{{ ui }}`` - an optional ``ui`` dictionary from ``config.yaml``, if any * ``{{ ui }}`` - an optional ``ui`` dictionary from ``config.yaml``, if any
* ``{{ static_prefix }}`` - the prefix from which static files will be accessed from, e.g. ``http://localhost:8080/static/`` * ``{{ static_prefix }}`` - the prefix from which static files will be accessed from, e.g. ``http://localhost:8080/static/``.
Replay and Banner Templates Replay and Banner Templates
@ -186,6 +189,8 @@ Template variables:
* ``{{ wb_prefix }}`` - the collection prefix, e.g. ``http://localhost:8080/pywb/`` * ``{{ wb_prefix }}`` - the collection prefix, e.g. ``http://localhost:8080/pywb/``
* ``{{ host_prefix }}`` - the pywb server origin, e.g. ``http://localhost:8080``
* ``{{ config }}`` - provides the contents of the ``config.yaml`` as a dictionary. * ``{{ config }}`` - provides the contents of the ``config.yaml`` as a dictionary.
* ``{{ ui }}`` - an optional ``ui`` dictionary from ``config.yaml``, if any. * ``{{ ui }}`` - an optional ``ui`` dictionary from ``config.yaml``, if any.
@ -232,10 +237,10 @@ Template variables:
* ``{{ wb_url }}`` - A complete ``WbUrl`` object, which contains the ``url``, ``timestamp`` and ``mod`` properties, representing the replay url. * ``{{ wb_url }}`` - A complete ``WbUrl`` object, which contains the ``url``, ``timestamp`` and ``mod`` properties, representing the replay url.
* ``{{ is_framed }}`` - true/false if currently in framed mode.
* ``{{ wb_prefix }}`` - the collection prefix, e.g. ``http://localhost:8080/pywb/`` * ``{{ wb_prefix }}`` - the collection prefix, e.g. ``http://localhost:8080/pywb/``
* ``{{ is_proxy }}`` - set to true if page is being loaded via an HTTP/S proxy (checks if WSGI env has ``wsgiprox.proxy_host`` set)
.. _custom-top-frame: .. _custom-top-frame:
@ -332,7 +337,7 @@ The following template variables are available to all templates.
* ``{{ env.pywb_proxy_magic }}`` - if set, indicates pywb is accessed via proxy. See :ref:`https-proxy` * ``{{ env.pywb_proxy_magic }}`` - if set, indicates pywb is accessed via proxy. See :ref:`https-proxy`
* ``{{ static_prefix }}`` - path to use for loading static files. * ``{{ static_prefix }}`` - URL path to use for loading static files.
UI Configuration UI Configuration

View File

@ -66,7 +66,7 @@ It is possible to change these settings via ``config.yaml``:
* ``static_prefix`` - sets the URL path used in pywb to serve static content (default ``static``) * ``static_prefix`` - sets the URL path used in pywb to serve static content (default ``static``)
* ``static_dir`` - sets the directory name used to read static files (default ``static``) * ``static_dir`` - sets the directory name used to read static files on disk (default ``static``)
While pywb can serve static files, it is recommended to use an existing web server to serve static files, especially if already using it in production. While pywb can serve static files, it is recommended to use an existing web server to serve static files, especially if already using it in production.

View File

@ -15,6 +15,11 @@ banner_html: banner.html
head_insert_html: head_insert.html head_insert_html: head_insert.html
frame_insert_html: frame_insert.html frame_insert_html: frame_insert.html
base_html: base.html
header_html: header.html
footer_html: footer.html
head_html: head.html
query_html: query.html query_html: query.html
search_html: search.html search_html: search.html
not_found_html: not_found.html not_found_html: not_found.html
@ -39,6 +44,12 @@ html_templates:
- not_found_html - not_found_html
- home_html - home_html
- base_html
- header_html
- head_html
- footer_html
- error_html - error_html
- proxy_cert_download_html - proxy_cert_download_html
- proxy_select_html - proxy_select_html

View File

@ -237,17 +237,20 @@ directory structure expected by pywb
v = defaults[n] v = defaults[n]
print('- {0}: (pywb/{1})'.format(n, v)) print('- {0}: (pywb/{1})'.format(n, v))
def _confirm_overwrite(self, full_path, msg): def _confirm_overwrite(self, full_path, msg, ignore=False):
if not os.path.isfile(full_path): if not os.path.isfile(full_path):
return True return True
if ignore:
return False
res = get_input(msg) res = get_input(msg)
try: try:
res = strtobool(res) res = strtobool(res)
except ValueError: except ValueError:
res = False res = False
if not res: if not res and not ignore:
raise IOError('Skipping, {0} already exists'.format(full_path)) raise IOError('Skipping, {0} already exists'.format(full_path))
def _get_template_path(self, template_name, verb): def _get_template_path(self, template_name, verb):
@ -268,7 +271,7 @@ directory structure expected by pywb
return full_path, filename return full_path, filename
def add_template(self, template_name, force=False): def add_template(self, template_name, force=False, ignore=False):
full_path, filename = self._get_template_path(template_name, 'add') full_path, filename = self._get_template_path(template_name, 'add')
msg = ('Template file "{0}" ({1}) already exists. ' + msg = ('Template file "{0}" ({1}) already exists. ' +
@ -276,7 +279,11 @@ directory structure expected by pywb
msg = msg.format(full_path, template_name) msg = msg.format(full_path, template_name)
if not force: if not force:
self._confirm_overwrite(full_path, msg) res = self._confirm_overwrite(full_path, msg, ignore)
if ignore and not res:
return
os.makedirs(os.path.dirname(full_path), exist_ok=True)
data = resource_string('pywb', filename) data = resource_string('pywb', filename)
with open(full_path, 'w+b') as fh: with open(full_path, 'w+b') as fh:
@ -286,6 +293,9 @@ directory structure expected by pywb
msg = 'Copied default template "{0}" to "{1}"' msg = 'Copied default template "{0}" to "{1}"'
print(msg.format(filename, full_path)) print(msg.format(filename, full_path))
if template_name != "base_html":
self.add_template("base_html", force=False, ignore=True)
def remove_template(self, template_name, force=False): def remove_template(self, template_name, force=False):
full_path, filename = self._get_template_path(template_name, 'remove') full_path, filename = self._get_template_path(template_name, 'remove')

View File

@ -0,0 +1,2 @@
## place content to be added at the very end of the <body> tag here

1
pywb/templates/head.html Normal file
View File

@ -0,0 +1 @@
## place optional content to be injected into the <head> of every page here

View File

@ -1,3 +1,4 @@
## place content to be added at the very beginning of the <body> tag here
<header> <header>
{% if not err_msg and locales|length > 1 %} {% if not err_msg and locales|length > 1 %}
<div class="language-select"> <div class="language-select">

View File

@ -10,7 +10,7 @@
{% for route in routes %} {% for route in routes %}
<li> <li>
<a href="{{ env['pywb.app_prefix'] + ('/' + env.pywb_lang if env.pywb_lang else '') + '/' + route }}">{{ '/' + route }}</a> <a href="{{ env['pywb.app_prefix'] + ('/' + env.pywb_lang if env.pywb_lang else '') + '/' + route }}">{{ '/' + route }}</a>
{% if all_metadata and all_metadata[route] %} {% if all_metadata and all_metadata[route] and all_metadata[route].title %}
({{ all_metadata[route].title }}) ({{ all_metadata[route].title }})
{% endif %} {% endif %}
</li> </li>

View File

@ -66,7 +66,7 @@
renderCal.init(); renderCal.init();
{% else %} {% else %}
VueUI.main("{{ static_prefix }}", "{{ url }}", "{{ prefix }}"); VueUI.main("{{ static_prefix }}", "{{ url }}", "{{ prefix }}", "{{ ui.logo }}");
{% endif %} {% endif %}

View File

@ -1,4 +1,4 @@
__version__ = '2.7.0b0' __version__ = '2.7.0b1'
if __name__ == '__main__': if __name__ == '__main__':
print(__version__) print(__version__)

View File

@ -2,7 +2,7 @@
<div class="app" :class="{expanded: showTimelineView}" data-app="webrecorder-replay-app"> <div class="app" :class="{expanded: showTimelineView}" data-app="webrecorder-replay-app">
<div class="banner"> <div class="banner">
<div class="line"> <div class="line">
<div class="logo"><img :src="config.logoImg" /></div> <div class="logo"><a href="/"><img :src="config.logoImg" /></a></div>
<div class="timeline-wrap"> <div class="timeline-wrap">
<div class="line"> <div class="line">
<div class="breadcrumbs-wrap"> <div class="breadcrumbs-wrap">

View File

@ -6,16 +6,17 @@ import Vue from "vue/dist/vue.esm.browser";
// =========================================================================== // ===========================================================================
export function main(staticPrefix, url, prefix, timestamp) { export function main(staticPrefix, url, prefix, timestamp, logoUrl) {
new CDXLoader(staticPrefix, url, prefix, timestamp); new CDXLoader(staticPrefix, url, prefix, timestamp, logoUrl);
} }
// =========================================================================== // ===========================================================================
class CDXLoader { class CDXLoader {
constructor(staticPrefix, url, prefix, timestamp) { constructor(staticPrefix, url, prefix, timestamp, logoUrl) {
this.opts = {}; this.opts = {};
this.prefix = prefix; this.prefix = prefix;
this.staticPrefix = staticPrefix; this.staticPrefix = staticPrefix;
this.logoUrl = logoUrl;
this.isReplay = (timestamp !== undefined); this.isReplay = (timestamp !== undefined);
@ -44,8 +45,7 @@ class CDXLoader {
this.opts.initialView = {url, timestamp}; this.opts.initialView = {url, timestamp};
// TODO: make configurable this.opts.logoImg = this.staticPrefix + (this.logoUrl ? this.logoUrl : "/pywb-logo-sm.png");
this.opts.logoImg = staticPrefix + "/pywb-logo-sm.png";
this.loadCDX(queryURL).then((cdxList) => { this.loadCDX(queryURL).then((cdxList) => {
this.app = this.initApp(cdxList, this.opts, (snapshot) => this.loadSnapshot(snapshot)); this.app = this.initApp(cdxList, this.opts, (snapshot) => this.loadSnapshot(snapshot));