mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
fuzzy match: modify existing params to ensure any custom params are preserved
templates: add ability to set custom global vars, such as 'static_path' for all templates
This commit is contained in:
parent
b0b0adb043
commit
e077c23de7
@ -104,10 +104,15 @@ class FuzzyQuery:
|
||||
if inx > 0:
|
||||
url = url[:inx + 1]
|
||||
|
||||
params = {'url': url,
|
||||
'matchType': 'prefix',
|
||||
'filter': filter_,
|
||||
'output': output}
|
||||
params = query.params
|
||||
params.update({'url': url,
|
||||
'matchType': 'prefix',
|
||||
'filter': filter_})
|
||||
try:
|
||||
del params['reverse']
|
||||
del params['closest']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return params
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!-- WB Insert -->
|
||||
{% if rule.js_rewrite_location %}
|
||||
<script src='{{ wbrequest.host_prefix }}/static/default/wombat.js'> </script>
|
||||
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wombat.js'> </script>
|
||||
<script>
|
||||
WB_wombat_init("{{wbrequest.wb_prefix}}",
|
||||
"{{cdx['timestamp']}}",
|
||||
@ -13,7 +13,7 @@
|
||||
wbinfo.capture_str = "{{ cdx.timestamp | format_ts }}";
|
||||
wbinfo.is_embed = {{"true" if wbrequest.is_embed else "false"}};
|
||||
</script>
|
||||
<script src='{{ wbrequest.host_prefix }}/static/default/wb.js'> </script>
|
||||
<link rel='stylesheet' href='{{ wbrequest.host_prefix }}/static/default/wb.css'/>
|
||||
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.js'> </script>
|
||||
<link rel='stylesheet' href='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.css'/>
|
||||
<!-- End WB Insert -->
|
||||
|
||||
|
@ -11,7 +11,7 @@ from pywb.warc.resolvingloader import ResolvingLoader
|
||||
from pywb.rewrite.rewrite_content import RewriteContent
|
||||
from pywb.rewrite.rewriterules import use_lxml_parser
|
||||
|
||||
from views import load_template_file, load_query_template
|
||||
from views import load_template_file, load_query_template, add_env_globals
|
||||
from replay_views import ReplayView
|
||||
|
||||
from query_handler import QueryHandler
|
||||
@ -37,6 +37,8 @@ DEFAULTS = {
|
||||
'home_html': 'ui/index.html',
|
||||
'error_html': 'ui/error.html',
|
||||
|
||||
'template_globals': {'static_path': 'static/default'},
|
||||
|
||||
'static_routes': {'static/default': 'pywb/static/'},
|
||||
|
||||
'domain_specific_rules': DEFAULT_RULES_FILE,
|
||||
@ -61,7 +63,8 @@ class DictChain:
|
||||
|
||||
|
||||
#=================================================================
|
||||
def create_wb_handler(query_handler, config, ds_rules_file=None):
|
||||
def create_wb_handler(query_handler, config,
|
||||
ds_rules_file=DEFAULT_RULES_FILE):
|
||||
|
||||
cookie_maker = config.get('cookie_maker')
|
||||
record_loader = ArcWarcRecordLoader(cookie_maker=cookie_maker)
|
||||
@ -71,6 +74,10 @@ def create_wb_handler(query_handler, config, ds_rules_file=None):
|
||||
resolving_loader = ResolvingLoader(paths=paths,
|
||||
record_loader=record_loader)
|
||||
|
||||
template_globals = config.get('template_globals')
|
||||
if template_globals:
|
||||
add_env_globals(template_globals)
|
||||
|
||||
head_insert_view = load_template_file(config.get('head_insert_html'),
|
||||
'Head Insert')
|
||||
|
||||
|
@ -35,9 +35,12 @@ class QueryHandler(object):
|
||||
ds_rules_file=DEFAULT_RULES_FILE,
|
||||
html_view=None):
|
||||
|
||||
perms_policy = config.get('perms_policy')
|
||||
perms_policy = None
|
||||
server_cls = None
|
||||
|
||||
server_cls = config.get('server_cls')
|
||||
if hasattr(config, 'get'):
|
||||
perms_policy = config.get('perms_policy')
|
||||
server_cls = config.get('server_cls')
|
||||
|
||||
cdx_server = create_cdx_server(config, ds_rules_file, server_cls)
|
||||
|
||||
|
@ -66,6 +66,8 @@ def is_wb_handler(obj):
|
||||
|
||||
#=================================================================
|
||||
class J2TemplateView:
|
||||
env_globals = {}
|
||||
|
||||
def __init__(self, filename):
|
||||
template_dir, template_file = path.split(filename)
|
||||
|
||||
@ -81,6 +83,7 @@ class J2TemplateView:
|
||||
|
||||
jinja_env = Environment(loader=loader, trim_blocks=True)
|
||||
jinja_env.filters.update(FILTERS)
|
||||
jinja_env.globals.update(self.env_globals)
|
||||
return jinja_env
|
||||
|
||||
def render_to_string(self, **kwargs):
|
||||
@ -99,6 +102,11 @@ class J2TemplateView:
|
||||
content_type=content_type)
|
||||
|
||||
|
||||
#=================================================================
|
||||
def add_env_globals(glb):
|
||||
J2TemplateView.env_globals.update(glb)
|
||||
|
||||
|
||||
#=================================================================
|
||||
def load_template_file(file, desc=None, view_class=J2TemplateView):
|
||||
if file:
|
||||
|
Loading…
x
Reference in New Issue
Block a user