diff --git a/scripts/check_growth_live.py b/scripts/check_growth_live.py index 36c32dd9..ca1be0c0 100644 --- a/scripts/check_growth_live.py +++ b/scripts/check_growth_live.py @@ -82,6 +82,26 @@ def check(path, key, valid): len({key for _, key in links}) == 2 and all(key in SLUGS and key != slug and href == f"/support/{key}/" for href, key in links)) + canonical = re.findall(r']*name="robots"[^>]*noindex', html, re.I)) + scripts = re.findall( + r'([\s\S]*?)', html + ) + try: + parsed = [json.loads(raw) for raw in scripts] + nodes = [] + for item in parsed: + nodes.extend(item.get("@graph", [item])) + types = {node.get("@type") for node in nodes if isinstance(node, dict)} + structured = bool({"WebPage", "SoftwareApplication", "MobileApplication"} & types) + structured = structured and any( + "Android" in json.dumps(node) for node in nodes) + except (TypeError, ValueError, AttributeError): + structured = False + check(path, "valid_app_jsonld", structured) check(path, "analytics", "related_app_click" in html and "download_click" in html) check(path, "play_cta", 'data-position="hero"' in html and 'data-position="details"' in html) diff --git a/scripts/test_growth_live.py b/scripts/test_growth_live.py index 69b448fc..fac63f2a 100644 --- a/scripts/test_growth_live.py +++ b/scripts/test_growth_live.py @@ -35,7 +35,17 @@ def valid_pages(): "instant-judge": ("twotaku", "debate-me")} for slug in SLUGS: other = related[slug] + canonical = f"https://appdevelopsk.com/support/{slug}/" + schema = json.dumps({ + "@context": "https://schema.org", + "@type": "SoftwareApplication", + "name": slug, + "operatingSystem": "Android", + "url": canonical, + }) pages[f"/support/{slug}/"] = ( + f'' + + '' + "related_app_click download_click " + 'data-position="hero" data-position="details" ' + " ".join(f'' for x in other)) @@ -64,6 +74,24 @@ def test_twotaku_missing_related_link_fails(self): 'data-related-app="instant-judge"', "") self.assertFalse(inspect(data)["passed"]) + def test_wrong_canonical_fails(self): + data = valid_pages() + data["/support/twotaku/"] = data["/support/twotaku/"].replace( + 'rel="canonical" href="https://appdevelopsk.com/support/twotaku/"', + 'rel="canonical" href="https://appdevelopsk.com/support/other/"') + self.assertFalse(inspect(data)["passed"]) + + def test_noindex_fails(self): + data = valid_pages() + data["/support/debate-me/"] += '' + self.assertFalse(inspect(data)["passed"]) + + def test_invalid_app_jsonld_fails(self): + data = valid_pages() + data["/support/instant-judge/"] = data["/support/instant-judge/"].replace( + '"SoftwareApplication"', '"SomethingOther"', 1) + self.assertFalse(inspect(data)["passed"]) + def test_missing_instant_judge_page_fails(self): data = valid_pages() del data["/support/instant-judge/"] diff --git a/support/instant-judge/index.html b/support/instant-judge/index.html index 0e597dba..bd5da3a9 100644 --- a/support/instant-judge/index.html +++ b/support/instant-judge/index.html @@ -2,6 +2,18 @@ +