Skip to content

Commit cf3938a

Browse files
authored
Fix summary links (#1150)
1 parent 7e59855 commit cf3938a

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

config/techreport.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@
930930
},
931931
"lighthouse_timeseries": {
932932
"title": "Lighthouse over time",
933-
"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.",
933+
"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.",
934934
"id": "lighthouse_timeseries",
935935
"endpoint": "lighthouse",
936936
"metric": "median_score_pct",
@@ -1305,7 +1305,7 @@
13051305
"metrics": {
13061306
"lighthouse": {
13071307
"general": {
1308-
"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."
1308+
"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."
13091309
},
13101310
"performance": {
13111311
"title": "Performance",

server/routes.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22

33
from flask import abort, jsonify, redirect, request, send_from_directory
4+
from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode
45

56
from . import app
67
from . import faq as faq_util
@@ -21,6 +22,36 @@ def safe_int(value, default=1):
2122
return default
2223

2324

25+
def _add_param_to_url(u: str, key: str, value: str) -> str:
26+
"""Add or update a single query param on a (possibly relative) URL string."""
27+
if not isinstance(u, str) or u == "":
28+
return u # pragma: no cover
29+
parts = urlsplit(u) # works for relative URLs like "?a=b#frag" or "#frag"
30+
q = dict(parse_qsl(parts.query, keep_blank_values=True))
31+
q[key] = value # add or replace
32+
new_query = urlencode(q, doseq=True)
33+
return urlunsplit(parts._replace(query=new_query))
34+
35+
36+
def add_param_to_all_urls(obj, key: str, value: str) -> int:
37+
"""
38+
Recursively mutate `obj` in place, adding/updating `key=value` to all fields named "url".
39+
"""
40+
41+
if isinstance(obj, dict):
42+
for k, v in obj.items():
43+
if k == "url" and isinstance(v, str):
44+
obj[k] = _add_param_to_url(v, key, value)
45+
else:
46+
add_param_to_all_urls(v, key, value)
47+
48+
elif isinstance(obj, list):
49+
for item in obj:
50+
add_param_to_all_urls(item, key, value)
51+
52+
return
53+
54+
2455
@app.route("/")
2556
def index():
2657
return render_template(
@@ -192,6 +223,16 @@ def techreport():
192223
active_tech_report["filters"] = filters
193224
active_tech_report["params"] = params
194225

226+
# If we're looking at a Drilldown report of a single technology
227+
# then we have summary links which may reload the report.
228+
# Update all the summary URLs to include filters
229+
# See https://github.com/HTTPArchive/httparchive.org/issues/1148
230+
if page_id == "drilldown":
231+
config = active_tech_report.get("config", {})
232+
add_param_to_all_urls(config, "geo", requested_geo)
233+
add_param_to_all_urls(config, "rank", requested_rank)
234+
add_param_to_all_urls(config, "tech", requested_technologies)
235+
195236
return render_template(
196237
"techreport/%s.html" % page_id,
197238
active_page=page_id,

templates/techreport/components/summary_card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
<p class="summary-linked-label">
1717
{% if summary.url %}
18-
<a href="{{ summary.url }}{{ filters }}" data-slot="label">
18+
<a href="{{ summary.url }}" data-slot="label">
1919
{{ summary.label }}
2020
</a>
2121
{% else %}

templates/techreport/techreport.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
<div class="block-m">
7878
<h2><a href="#section-feedback" class="anchor">Feedback?</a></h2>
7979
<p>
80-
We are still working on this dashboard. The design and functionality can still change, and we're working on accessibility improvements and bugfixes.
81-
What you're seeing here is a snapshot of our latest GitHub commit, and are <a href="https://github.com/HTTPArchive/httparchive.org/issues/new?template=tech-report.md">open for feedback</a>.
80+
Please raise a <a href="https://github.com/HTTPArchive/httparchive.org/issues/new?template=tech-report.md">GitHub issue</a> if you spot any problems, or for any feature requests.
8281
</p>
8382
</div>
8483
</div>

0 commit comments

Comments
 (0)