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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Format: [Keep a Changelog](https://keepachangelog.com/) · [SemVer](https://semv

## [Unreleased]

### Fixed
- `G-DATES` no longer counts a date that appears only inside an HTML comment (for example `<!-- Published 2026-03-12 -->`) as a visible date. The 4.31.1 text-date check read comments by mistake; a page whose only date is in a comment goes back to the "Date only in structured data" warning. Pages that show the date as real text, a `<time datetime>` element or an `article:published_time` meta tag are unchanged.

---

## [4.31.1] — 2026-11-30
Expand Down
13 changes: 11 additions & 2 deletions src/geo_optimizer/core/audit_google_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from datetime import datetime, timedelta, timezone
from urllib.parse import urlsplit

from bs4.element import PreformattedString

from geo_optimizer.models.config import (
DATA_NOSNIPPET_FAIL_RATIO,
DATA_NOSNIPPET_WARN_RATIO,
Expand Down Expand Up @@ -160,9 +162,16 @@ def _parse_date(value) -> datetime | None:


def _has_visible_date_text(soup) -> bool:
"""True when the page text itself says when it was published or updated (script and style text is ignored)."""
"""True when the page text itself says when it was published or updated.

Script and style text is ignored, and so are HTML comments (and CDATA/doctype strings): a date in a comment is not shown.
"""
body = soup.body or soup
parts = (t for t in body.find_all(string=True) if t.parent is not None and t.parent.name not in _NON_TEXT_TAGS)
parts = (
t
for t in body.find_all(string=True)
if not isinstance(t, PreformattedString) and t.parent is not None and t.parent.name not in _NON_TEXT_TAGS
)
return bool(_VISIBLE_DATE_RE.search(" ".join(parts)))


Expand Down
5 changes: 5 additions & 0 deletions tests/test_audit_google_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ def test_a_date_that_only_exists_inside_a_script_does_not_count():
assert check_dates(page, [{"datePublished": "2026-09-12"}], NOW).status == "warn"


def test_a_date_that_only_exists_inside_an_html_comment_does_not_count():
page = soup(body="<!-- Published 12 September 2026 --><p>hello</p>")
assert check_dates(page, [{"datePublished": "2026-09-12"}], NOW).status == "warn"


def test_a_visible_date_without_structured_data_is_still_a_warning():
page = soup(body="<p>Published 12 September 2026</p>")
assert check_dates(page, [], NOW).status == "warn"