Keep a discovered slug's case for a host with KEEP_CASE, and check only group 1 against the hosts' own path words
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9cb35ae785
commit
75a389d725
3 files changed
+45
-4
No files matched your search
+15
-4
@@ -106,6 +106,14 @@ def _hosts(modules: Mapping[str, ModuleType],
|
||||
#: joined by "/" (Lever's `eu/<site>`).
|
||||
HOSTS: tuple[tuple[str, re.Pattern[str]], ...] = _hosts(atshosts.HOSTS, _UNREADABLE)
|
||||
|
||||
#: The hosts whose slugs keep the case the URL wrote them in, by their
|
||||
#: module's `KEEP_CASE`: a Workday site is `LEGO_External`, and both its
|
||||
#: listing and its robots.txt paths are case-sensitive. Every other slug is
|
||||
#: lowercased, which is how a page that writes `BoschGroup` and one that
|
||||
#: writes `boschgroup` name one board.
|
||||
_KEEP_CASE = frozenset(name for name, module in atshosts.HOSTS.items()
|
||||
if getattr(module, "KEEP_CASE", False))
|
||||
|
||||
#: What a Teamtailor feed carries and a page that only looks like one does not:
|
||||
#: the namespace of `tt:locations`, declared on `<rss>` even when no role is open.
|
||||
TEAMTAILOR_FEED = "https://teamtailor.com/locations"
|
||||
@@ -128,7 +136,7 @@ _ANCHOR = re.compile(r"<a\b[^>]*href\s*=\s*[\"']([^\"'#][^\"']*)[\"'][^>]*>(.*?)
|
||||
re.IGNORECASE | re.DOTALL)
|
||||
_TAGS = re.compile(r"<[^>]+>")
|
||||
|
||||
#: Words a pattern's slug group can catch that name no board: the hosts'
|
||||
#: Words a pattern's group 1 can catch that name no board: the hosts'
|
||||
#: own path segments, the analytics subdomain Recruitee sites embed, and
|
||||
#: the CDN and the admin app Teamtailor sites load from (cdn.teamtailor.com,
|
||||
#: app.teamtailor.com).
|
||||
@@ -164,10 +172,13 @@ def boards_in(text: str) -> list[Found]:
|
||||
hits: list[tuple[int, str, str, str]] = []
|
||||
for host, pattern in HOSTS:
|
||||
for m in pattern.finditer(text):
|
||||
parts = [part.lower() for part in m.groups() if part]
|
||||
if any(part in _NOT_SLUGS for part in parts):
|
||||
# Only group 1 names a board or a host's own path word; a later
|
||||
# group may be anything, a Workday site called `jobs` included.
|
||||
if m.re.groups and (m.group(1) or "").lower() in _NOT_SLUGS:
|
||||
continue
|
||||
slug = "/".join(parts)
|
||||
slug = "/".join(part for part in m.groups() if part)
|
||||
if host not in _KEEP_CASE:
|
||||
slug = slug.lower()
|
||||
hits.append((m.start(), host, slug, m.group(0)))
|
||||
for _pos, host, slug, url in sorted(hits):
|
||||
if (host, slug) in seen:
|
||||
|
||||
Reference in new issue
Block a user