Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/techreport.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions server/routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion templates/techreport/components/summary_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
>
<p class="summary-linked-label">
{% if summary.url %}
<a href="{{ summary.url }}{{ filters }}" data-slot="label">
<a href="{{ summary.url }}" data-slot="label">
{{ summary.label }}
</a>
{% else %}
Expand Down
3 changes: 1 addition & 2 deletions templates/techreport/techreport.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
<div class="block-m">
<h2><a href="#section-feedback" class="anchor">Feedback?</a></h2>
<p>
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 <a href="https://github.com/HTTPArchive/httparchive.org/issues/new?template=tech-report.md">open for feedback</a>.
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.
</p>
</div>
</div>
Expand Down
Loading