diff --git a/config/techreport.json b/config/techreport.json index 74c80088..4dfd6dce 100644 --- a/config/techreport.json +++ b/config/techreport.json @@ -930,7 +930,7 @@ }, "lighthouse_timeseries": { "title": "Lighthouse over time", - "description": "Lighthouse has audits for performance, accessibility, progressive web apps, SEO, and more. Based on the audits, a score is calculated. Currently, this section visualizes median scores, but in the future you'll also be able to explore the details of the audits here.", + "description": "Lighthouse has audits for performance, accessibility, SEO, and more. Based on the audits, a score is calculated. Currently, this section visualizes median scores, but in the future you'll also be able to explore the details of the audits here.", "id": "lighthouse_timeseries", "endpoint": "lighthouse", "metric": "median_score_pct", @@ -1305,7 +1305,7 @@ "metrics": { "lighthouse": { "general": { - "description": "Lighthouse has audits for performance, accessibility, progressive web apps, SEO, and more. Based on the audits, a score is calculated. Currently, this section visualizes median scores, but in the future you'll also be able to explore the details of the audits here." + "description": "Lighthouse has audits for performance, accessibility, SEO, and more. Based on the audits, a score is calculated. Currently, this section visualizes median scores, but in the future you'll also be able to explore the details of the audits here." }, "performance": { "title": "Performance", diff --git a/server/routes.py b/server/routes.py index f312cb51..59a975a2 100644 --- a/server/routes.py +++ b/server/routes.py @@ -1,6 +1,7 @@ import re from flask import abort, jsonify, redirect, request, send_from_directory +from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode from . import app from . import faq as faq_util @@ -21,6 +22,36 @@ def safe_int(value, default=1): return default +def _add_param_to_url(u: str, key: str, value: str) -> str: + """Add or update a single query param on a (possibly relative) URL string.""" + if not isinstance(u, str) or u == "": + return u # pragma: no cover + parts = urlsplit(u) # works for relative URLs like "?a=b#frag" or "#frag" + q = dict(parse_qsl(parts.query, keep_blank_values=True)) + q[key] = value # add or replace + new_query = urlencode(q, doseq=True) + return urlunsplit(parts._replace(query=new_query)) + + +def add_param_to_all_urls(obj, key: str, value: str) -> int: + """ + Recursively mutate `obj` in place, adding/updating `key=value` to all fields named "url". + """ + + if isinstance(obj, dict): + for k, v in obj.items(): + if k == "url" and isinstance(v, str): + obj[k] = _add_param_to_url(v, key, value) + else: + add_param_to_all_urls(v, key, value) + + elif isinstance(obj, list): + for item in obj: + add_param_to_all_urls(item, key, value) + + return + + @app.route("/") def index(): return render_template( @@ -192,6 +223,16 @@ def techreport(): active_tech_report["filters"] = filters active_tech_report["params"] = params + # If we're looking at a Drilldown report of a single technology + # then we have summary links which may reload the report. + # Update all the summary URLs to include filters + # See https://github.com/HTTPArchive/httparchive.org/issues/1148 + if page_id == "drilldown": + config = active_tech_report.get("config", {}) + add_param_to_all_urls(config, "geo", requested_geo) + add_param_to_all_urls(config, "rank", requested_rank) + add_param_to_all_urls(config, "tech", requested_technologies) + return render_template( "techreport/%s.html" % page_id, active_page=page_id, diff --git a/templates/techreport/components/summary_card.html b/templates/techreport/components/summary_card.html index 73600a17..843652b9 100644 --- a/templates/techreport/components/summary_card.html +++ b/templates/techreport/components/summary_card.html @@ -15,7 +15,7 @@ >
{% if summary.url %} - + {{ summary.label }} {% else %} diff --git a/templates/techreport/techreport.html b/templates/techreport/techreport.html index 3a5daf8d..f707cb0d 100644 --- a/templates/techreport/techreport.html +++ b/templates/techreport/techreport.html @@ -77,8 +77,7 @@
- We are still working on this dashboard. The design and functionality can still change, and we're working on accessibility improvements and bugfixes. - What you're seeing here is a snapshot of our latest GitHub commit, and are open for feedback. + Please raise a GitHub issue if you spot any problems, or for any feature requests.