Repository navigation
stage-site: --local-links, a consumer site's links to lectures it carries made links within it - #102
Merged
Merged
Conversation
…ries made links within it
dp's copies are byte for byte their sources', so 31 of their links
take a reader to another series' site for a lecture dp itself has: 5
prefixed {doc} links and 26 markdown links by address, 18 of them
through python-intro.quantecon.org. On the owner's "(b) rewrite at
staging" (2026-11-26, QuantEcon/project-monorepo#22), staging can now
rewrite them in the staged copy only:
- tools/stage-site --local-links, for a consumer site alone: a prefixed
{doc} link to a lecture the site carries, whose prefix the site maps,
loses its prefix; a markdown link to such a lecture's page on a host
the site maps, its own, or an older address that still forwards
becomes a link to the lecture's file. Prose only, never an address
with an anchor. Originals are kept under _build/ and --clean puts
them back by the record, as it removes a copy. On the pool today it
rewrites exactly dp's 31 links, in 13 lectures, and --clean restores
every byte.
- site.yml's optional local_links (true or false), which only a consumer
may set (pool-check's site-yml); tools/site-matrix passes it to the
leg, and site-build.yml stages with --local-links when it is true.
- No site sets it yet: it is what readers see, so dp turns it on at its
cutover.
- Tests for the rewrite and its clean-up, the refusals, the site.yml
rule and the matrix field; sites/README.md documents it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…l-links Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…se case
- site-build.yml: tools/stage-site needs PyYAML for --local-links, which
every leg's environment has, since Jupyter Book needs it too; without it,
--local-links fails with a plain error, not a traceback.
- --clean confines each lecture's original to _build/stage-site-originals/,
as it confines each path to lectures/, and checks every path the record
names before it touches anything.
- --clean's messages say where a kept lecture's original was left, and that
a lecture whose original is gone is kept as it is.
- Staging refuses when a lecture's original is left from an earlier --clean,
so it never replaces one.
- Tests: % comments; plain, language and tilde fences; a link in a {note}
body beside a nested code cell; a single-backtick literal; a line opening
with inline code; the site's own address; the site's own page; a nested
toc; --clean with the original gone, and with a record outside its folder.
- Docs: the docstring's "never overwrites" is now precise, and says that
{math} bodies, four-space blocks and ::: fences read as prose, as
pool-check reads them; README's tools table has a --local-links row;
sites/README.md dates its count of dp's links (31, in 13 lectures, on
2026-11-27).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues allow TOC paths to modify files outside the pool, rewrite literal content in multiline code spans, and restore deleted lectures during cleanup.
3 open issues
What changed in this PR
Adds opt-in staging-time link rewriting so consumer sites can keep readers on lectures they carry without permanently changing pool sources. No site enables the option in this PR.
Changes:
- Adds
stage-site --local-links, with original-file backups and guarded cleanup. - Validates
local_linksin site metadata and passes it through the build matrix and workflow. - Adds regression coverage and documents usage and rollout behavior.
| File | Description |
|---|---|
tools/tests/test_sites.py |
Tests rewriting, exclusions, cleanup, and consumer-only validation. |
tools/tests/test_site_matrix.py |
Tests option propagation, defaults, and invalid values. |
tools/stage-site |
Implements link rewriting, backups, and restoration. |
tools/site-matrix |
Includes local_links in build settings. |
tools/pool-check |
Validates the option and restricts enablement to consumers. |
sites/README.md |
Documents configuration and consumer-link behavior. |
README.md |
Documents staging and cleanup commands. |
.github/workflows/site-build.yml |
Conditionally stages with --local-links. |
Review effort: Balanced (adaptive)
- A lecture the site carries is a file directly in lectures/: a _toc.yml entry such as ../notes/page, a subfolder's page or a link in the pool that leads out is not read, so nothing outside the pool is rewritten. - Inline literals are read a paragraph at a time, as CommonMark reads them: one may run across a line break, not across a blank line, a heading or a fenced block. On the pool this changes the reading of 7 lines in 2 lectures, none with a link; dp's plan is the same 31 links in 13 lectures. - --clean leaves a rewritten lecture that is no longer a file as it is and keeps its original, as it does for one edited since staging. Each has a test that fails on the code before this commit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
- A lecture the site carries is a name in the pool's own listing, spelled as it is there, of a file that is not a link. A second name for one lecture (a link to it in the pool, or a case variant on a disk that ignores case) made two plan entries for one file, the second backup overwrote the first with rewritten bytes, and --clean put back the rewritten text. LECTURE_NAME_RE and the resolve check go: the listing covers both. - A paragraph also ends at a line that starts a block of its own: a list item (whose next lines continue it), a target, +++, a $$ line, a ::: fence, a thematic break or setext underline, besides a heading. What is still read together (a blockquote's start, table rows, HTML) can only mask more; the docstring says so, and no longer claims CommonMark's reading. - A literal opens at a whole run of backticks, as pool-check reads one. - --clean never restores through a link left in a lecture's place. On the pool the reading is the same as 1972dc5's, and dp's plan the same 31 links in 13 lectures. Each fix has a test that fails on 1972dc5. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…er way The docstring said that lines read together "can only mask more". That is false: a stray backtick in a joined line can shift the pairing either way, masking a link or leaving one inside a literal to be rewritten (a stray backtick, then a `>` line or a table row holding a literal with a link). It now says so, and that no pool lecture has a literal holding a link, as markdown-it reads them (2026-11-27). The tool's code is unchanged. Tests: an item's indented next lines continue it, literal and all; and the link-in-a-lecture's-place test links to a file holding the staged bytes, so it fails on 1972dc5 by writing the original through the link, not only on the message. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
mmcky
added a commit
that referenced
this pull request
Nov 27, 2026
…#106 (#108) ## Why The reviews of #102 (`tools/stage-site --local-links`) and #106 (the PDF) left points to take after their merges. This PR takes them. None changes what any site builds or publishes today. ## tools/stage-site (from the reviews of #102) - **A left-over original that changes nothing.** An earlier `--clean` that kept an edited lecture leaves its original under `_build/stage-site-originals/`, and staging refused while it was there. It now refuses only when the original differs from the pool's lecture as it is now. Once the lecture has been put back by hand, replacing the original loses nothing. - **The originals folder.** Staging refuses when `_build/stage-site-originals` is a link or a file. It also refuses when a lecture's place in that folder holds a link, dangling ones included. A dangling link is not `.exists()`, so copying the original would have written through it. The confinement `--clean` uses refuses a folder that is itself a link, whose target it would otherwise confine to. - **The paragraph reading is main's.** This PR first changed how `tools/stage-site` reads paragraphs, so that inline literals are found as CommonMark finds them. After four review rounds, that hand-written reading still disagreed with markdown-it on 9 of 62 cases, against 21 for main's. The maintainer chose to split it out (Matt, 2026-11-27, in the project-monorepo session: "Split; markdown-it next (Recommended)"). So `prose_mask` is main's again, and a separate PR will read paragraphs and code spans with markdown-it and MyST's plugins, exact by construction. ## site-build.yml (from the review of #106) - **The cache save** runs on `always()` with the outcome of the HTML build and of its execution report. A job that times out or is cancelled in a later step, the PDF build say, still keeps a cold build's execution. The header's cache paragraph and `sites/README.md` no longer say "after a green build". - **The PDF copy step's grep:** finding nothing (exit 1) is reported by the check after it. A real error (exit 2, such as an unreadable folder) now fails the step with grep's own message. `|| true` had let that pass green. - `sites/README.md`'s `publishes` row no longer says "the same way" twice, and a comment left short by rewrapping is rewrapped. ## Checked - **On the pool** (at `aa281d3`): the reading is main's, so every pool lecture reads as on main (0 lines differ), and dp's `--local-links` plan is the same 31 links in 13 lectures, byte for byte. - **Tests:** 361 passed and 1 skipped (at `5498ef2`). Each fix has a test that fails without it: the left-over original that matches (put back and staged again), a dangling link where an original goes, a folder there, and an originals folder that is a link or a file, at staging and at `--clean`. - **The copy step**, its script taken from the workflow and run under `bash --noprofile --norc -eo pipefail` on local cases: - a good build passes; - a wrong name fails with its message; - no link fails with its message; - an unreadable folder fails with grep's "Permission denied" (with `|| true` it passed). - actionlint is clean; pool-check is clean. This PR's site build runs all six sites, since it touches `tools/stage-site`. Every leg restores main's cache. Copilot: not requested (Matt, 2026-11-22). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
mmcky
added a commit
that referenced
this pull request
Nov 27, 2026
## Why `tools/stage-site --local-links` rewrites a consumer site's links to lectures it carries (#102). It must leave alone a link that isn't one, such as an address inside an inline literal or a code cell. Until now it found those with hand-written rules for paragraphs and code spans. Four review rounds of #108 each found new list-indentation cases where those rules and CommonMark disagree. On the 62 cases the reviews checked against markdown-it, main's reading disagrees on 21. The maintainer chose to split that work out of #108 and read pages with markdown-it itself (Matt, 2026-11-27, in the project-monorepo session: "Split; markdown-it next (Recommended)"). ## What it changes - **`Reader`** builds the parser MyST itself uses, myst-parser's markdown-it (`create_md_parser`), with the extensions the site's `_config.yml` enables (`parse: myst_enable_extensions`). It wraps the parser's `link` and `myst_role` inline rules so that each records where its link or role starts and ends. A link counts only where the parser makes one, so none comes from a code cell, a literal block, an inline literal, a `%` comment, raw HTML or maths. - **Placing back.** Each paragraph, heading or table cell the parser reads is found again in its source lines, one line for one, after any list indent or `>` it carried. Cells of one row are found left to right. A directive's body is read the same way, except for `LITERAL_DIRECTIVES` (code, math, raw). An edit is made only where the source holds, at the place found, exactly what the parser read there. Anything that can't be placed is left as it is, still linking out, as every link did before `--local-links`. - **Gone:** `prose_mask` and its fence, backtick and block-start rules. - **Dependencies:** `myst-parser` and `linkify-it-py` (for the sites' `linkify`) join the script's uv header and `tests.yml`. Every leg's environment has them, since Jupyter Book does (myst-parser 3.0.1, markdown-it-py 3.0.0). Without myst-parser, `--local-links` fails with a plain error. The site-build comment and `sites/README.md` say so. ## Checked - **Against markdown-it:** on all 62 cases from the two oracles of #108's reviews (`mdit-oracle.py` and the organiser's 41), the rewrite makes exactly the links markdown-it renders as links. Those 62, and four more (table cells, a list item's next line, a blockquote, a directive in a list), are now a test: 66 cases, 21 of which fail on main's `tools/stage-site`. - **On the pool** (at `4b0ab02`): dp's `--local-links` plan is the same 31 links in 13 lectures, byte for byte. - **Tests:** 428 passed and 1 skipped, including the existing prose cases and a test for the missing-parser error. actionlint and pool-check are clean. This PR's site build runs all six sites, since it touches `tools/stage-site`. No site sets `local_links`, so no page changes. Copilot: not requested (Matt, 2026-11-22). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


On Matt's "(b) rewrite at staging" (2026-11-26, relayed by the organiser session), for QuantEcon/project-monorepo#22: a consumer site's links to lectures it carries become links within the site, in the staged copy only. No site turns it on in this pull request. It changes what readers see, so dp sets
local_links: trueat its cutover.Why
dp's copies are byte for byte their sources' own, so their links to the home series' sites take a reader away from dp for a lecture dp itself has. QuantEcon/project-monorepo#22's check counted 31: 5 prefixed
{doc}links ({doc}`intro:short_path`three times,{doc}`intermediate:perm_income_cons`twice) and 26 markdown links by address ([this lecture](https://python.quantecon.org/os_stochastic.html)), 18 of them through python-intro.quantecon.org. dp is the only site with such links.What it adds
tools/stage-site --local-links, for a consumer site alone (class: consumerinsync/manifest.yml; refused otherwise, with nothing copied). In the pool lectures the site's_toc.ymllists, it makes two rewrites:{doc}link to a lecture the site carries, whose prefix the site'sintersphinx_mappinghas, loses its prefix;OLD_ADDRESSES: python-intro.quantecon.org) becomes[text](<page>.md).It reads prose only: code cells, literal blocks, inline literals and
%comments are blanked before matching, as pool-check reads them. An address with an anchor is left alone. Each rewritten lecture's original goes to_build/stage-site-originals/and into the record, and--cleanputs it back only if its bytes are still the ones staging wrote, as it removes a copy. So the pool's copies stay verbatim, and the drift-check never sees a change.site.yml's optionallocal_links(trueorfalse). pool-check'ssite-ymlrule allowstrueon a consumer's site alone.tools/site-matrixpasses it to the leg, andsite-build.ymlstages with--local-linkswhen it istrue.Docs:
sites/README.mdgets a section and two table rows; the workflow's notes mention it.Checked
c792764, and again atfb579c7after the review fixes):tools/stage-site --local-links dprewrote exactly dp's 31 links, in 13 lectures. Each is a prefix dropped or an address made a.mdlink, and nothing else changed.--cleanthen put all 13 back, andgit statusshowed no pool file changed. A site that isn't a consumer is refused.31b7dbb). Twenty-seven are new; the first four: the rewrite of each form, with six forms left alone (a lecture the site doesn't carry, an anchor, an unmapped host, an inline literal, an unmapped prefix, a code cell), and--cleanrestoring the bytes; the consumer-only refusal, with a lecture edited after staging kept; thesite.ymlrule; the matrix field.tools/site-matrixgives every sitelocal_links: false.After review (
6980406)site-build.yml's note no longer saystools/stage-siteneeds the standard library alone: it needs PyYAML for--local-links, which every leg's environment has, since Jupyter Book needs it too. Without it,--local-linksnow fails with a plain error, not a traceback.--cleanconfines each lecture's original to_build/stage-site-originals/, as it confines every path tolectures/, and checks every path the record names before it touches anything.--clean's messages say where a kept lecture's original was left, and a lecture whose original is gone is reported as kept as it is (the old message contradicted itself).--clean, so it never replaces one.%comments; plain, language and tilde fences; a{code-block}fence; a link in a{note}body beside a nested code cell; a single-backtick literal with a link after it; a line opening with inline code; the site's own address, the site's own page ({doc}`intro:intro`stays) and a nested toc, through the tool;--cleanwith the original gone, and with a record naming a path outside its folder.{math}bodies, four-space blocks and:::fences read as prose, as pool-check reads them (no pool lecture has a link in one, 2026-11-27); README's tools table has a--local-linksrow;sites/README.mddates its count of dp's links.After Copilot's review (
1972dc5)lectures/. A_toc.ymlentry such as../notes/page, a subfolder's page, or a pool symlink that leads out is not read, so nothing outside the pool is ever rewritten.arellano.md).--cleanleaves a rewritten lecture that is no longer a file as it is and keeps its original, as it does for one edited since staging.6980406. dp's plan on the pool atfb579c7is unchanged: the same 31 links in 13 lectures, byte for byte.After the second review (
4dd284e, on main63d02d6)--cleanput the rewritten text back.+++, a$$line, a:::fence, a thematic break or setext underline, as well as a heading. This reading is close to CommonMark's but not the same. What is still read together (a blockquote's start, table rows, HTML, a deeply nested list item) can shift a stray backtick's pairing either way: it can mask a link, or leave one inside a literal to be rewritten. The docstring says so (corrected in31b7dbb, see below). No pool lecture has a literal that holds a link, as markdown-it reads them.--cleannever restores through a link left in a lecture's place.1972dc5. The pool reads exactly as at1972dc5, and dp's plan is unchanged.31b7dbb: that docstring fix, plus two tests. One checks that an item's indented next lines continue it. The other makes the link-in-a-lecture's-place test fail on1972dc5by writing through the link. 357 passed.Not yet tested here: a strict Jupyter Book build of dp with the rewrite on. That comes when dp turns it on; its shadow comparison (QuantEcon/project-monorepo#26) should then list the 31 links as its expected differences. If a rewritten
.mdlink didn't resolve under-n -W, that build would fail, not ship.Copilot: not requested by me (Matt, 2026-11-22). Its review at
6980406raised three points. Each is fixed in1972dc5, and its thread has a reply.🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG