Skip to content

Commit 530347d

Browse files
peers8862claude
andcommitted
Fix /site dropping links to other Telegraph accounts' pages on rebuild
read_external() decided what to carry forward across a rebuild using "telegra.ph" in href - true for this account's own pages, but also true for a /link entry pointing at a DIFFERENT Telegraph account's page (the observer's status page, published under telepatch-ops). That looked like an own page and got excluded from preservation, and it was never in this account's own scan either, so it silently vanished on every /site rebuild. read_external() now takes the account's own known paths and only treats a telegra.ph href as "ours" - left for the ordinary scan to regenerate - when its path is actually in that set. Everything else, GitHub links included, is preserved verbatim as before. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent ce71a55 commit 530347d

2 files changed

Lines changed: 82 additions & 7 deletions

File tree

‎bot.py‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,16 +3099,32 @@ def keep(node):
30993099
)
31003100

31013101

3102-
def read_external(content):
3102+
# Used only to decide "is this href even a candidate for being one of our
3103+
# own pages" before comparing its path against own_paths in read_external.
3104+
# Deliberately narrower than a general URL check - a false match here just
3105+
# means one more href gets a (cheap) path comparison, but a false miss
3106+
# would treat a genuine telegra.ph page as an outward link.
3107+
TELEGRAPH_HOST_RE = re.compile(r"^https?://(www\.)?telegra\.ph/", re.IGNORECASE)
3108+
3109+
3110+
def read_external(content, own_paths=None):
31033111
"""
3104-
Index entries that are not Telegraph pages, kept verbatim.
3112+
Index entries that point outside this account, kept verbatim.
31053113
31063114
/site regenerates the list from getPageList, which only knows this
3107-
account's Telegraph pages. A GitHub link added by hand would be wiped
3108-
on the next rebuild, so it is read back first — the same read-before-
3109-
write the dates, masthead and footer already need.
3115+
account's Telegraph pages. A GitHub link added by hand, or a /link
3116+
entry pointing at a *different* Telegraph account's page - another
3117+
Telepatch publication, say - would be wiped on the next rebuild
3118+
otherwise, so both are read back first, the same read-before-write the
3119+
dates, masthead and footer already need.
3120+
3121+
A telegra.ph href only counts as "ours" - and so is left for the
3122+
ordinary scan to regenerate, not kept here - when its path is actually
3123+
in own_paths. Any other telegra.ph page is exactly as external as a
3124+
GitHub link; the host alone was never a safe test for that.
31103125
"""
31113126

3127+
own_paths = own_paths or set()
31123128
kept = []
31133129

31143130
for node in split_master(content)[1]:
@@ -3134,7 +3150,10 @@ def read_external(content):
31343150

31353151
href = (anchor.get("attrs") or {}).get("href", "")
31363152

3137-
if not href or href.startswith("/") or "telegra.ph" in href:
3153+
if not href or href.startswith("/"):
3154+
continue
3155+
3156+
if TELEGRAPH_HOST_RE.match(href) and telegraph_path(href) in own_paths:
31383157
continue
31393158

31403159
text = "".join(k for k in kids if isinstance(k, str))
@@ -3494,10 +3513,11 @@ async def rebuild_site(message, token, master_path=None, title=None,
34943513

34953514
else:
34963515
filed = claimed_paths(scanned)
3516+
own_paths = {page["path"] for page, _ in scanned}
34973517

34983518
entries, content = build_index(
34993519
scanned, master_path, known_dates, masthead, footer,
3500-
read_byline(old), read_external(old), filed, recorded
3520+
read_byline(old), read_external(old, own_paths), filed, recorded
35013521
)
35023522

35033523
# Said out loud, always. A page quietly missing from a rebuild that

‎tests/test_index.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,58 @@ def test_entry_href(bot, curated):
183183
assert bot.entry_href(listing[0]) == "/Filed-07-28"
184184
assert bot.entry_href(listing[2]) == "https://github.com/babbworks/telepatch"
185185
assert bot.entry_href(p("not an entry")) is None
186+
187+
188+
def test_read_external_keeps_a_foreign_telegraph_page(bot):
189+
"""
190+
A /link entry pointing at a DIFFERENT Telegraph account's page - the
191+
observer's status page, say, published under telepatch-ops rather than
192+
this account - is not one of this account's own pages. A rebuild must
193+
not wipe it, exactly as it must not wipe a GitHub link.
194+
"""
195+
content = [
196+
{"tag": "ul", "children": [
197+
li("https://telegra.ph/telepatch-server-performance-08-01",
198+
"Server status", " — 2026-08-01"),
199+
]},
200+
p("Index generated by Telepatch. byline=linked"),
201+
]
202+
203+
kept = bot.read_external(content, own_paths={"One-07-28", "Two-07-28"})
204+
205+
assert len(kept) == 1
206+
assert bot.entry_href(kept[0]["node"]) == \
207+
"https://telegra.ph/telepatch-server-performance-08-01"
208+
209+
210+
def test_read_external_distinguishes_own_pages_from_foreign_ones(bot, curated):
211+
"""
212+
A real account mixes all three shapes: its own page linked with a
213+
relative href, its own page linked with an absolute telegra.ph href,
214+
and a plain outward link. Only the two "own page" shapes should ever
215+
be dropped as "the ordinary scan already has this one" - the host
216+
alone was never a safe test for that.
217+
"""
218+
own_paths = {"Filed-07-28", "Also-Filed-07-28"}
219+
220+
kept = bot.read_external(curated, own_paths)
221+
hrefs = {bot.entry_href(k["node"]) for k in kept}
222+
223+
assert hrefs == {"https://github.com/babbworks/telepatch"}
224+
225+
226+
def test_read_external_defaults_to_treating_absolute_telegraph_as_foreign(bot, curated):
227+
"""
228+
Guards the default: calling read_external without own_paths must not
229+
silently drop nothing. An empty own_paths means every *absolute*
230+
telegra.ph href looks foreign - the safe failure direction - while a
231+
relative href is still recognised as this account's own regardless,
232+
since only this account's own pages are ever written that way.
233+
"""
234+
kept = bot.read_external(curated)
235+
hrefs = {bot.entry_href(k["node"]) for k in kept}
236+
237+
assert hrefs == {
238+
"https://telegra.ph/Also-Filed-07-28",
239+
"https://github.com/babbworks/telepatch",
240+
}

0 commit comments

Comments
 (0)