diff --git a/STRUCTURE.md b/STRUCTURE.md index 2ab1b8d..9769788 100644 --- a/STRUCTURE.md +++ b/STRUCTURE.md @@ -184,6 +184,35 @@ they're after instead of landing on the page and hunting. anchor/link it can't resolve; treat a clean build as the actual pass/fail check for this list, since hand-checked slugs are easy to get subtly wrong (trailing punctuation, duplicate-heading suffixes, etc). +- **Marking content "advanced" for the Simplify toggle** — the header's "Essentials" / "Advanced" + segmented control (both labels always visible, on every page) hides content marked + `data-advanced="true"`, at one of two granularities. Each spot that should hide is marked + directly, in its own markdown source — there's no derived/shared list, so a new advanced entry + needs tagging in every place it should disappear from: + - **A homepage keyword-link row** — the bolded keyword plus its row of related links (e.g. + `functions.md#decorators` or `collections.md#sets`, in `index.md`) — append + `{: data-advanced="true" }` on its own line directly after the row, at the same indentation, + with no blank line before it (attr_list attaches it to that paragraph, which + `.simplify-active [data-advanced]` then hides). + - **The matching heading on the actual content page** — e.g. `functions.md`'s + `## Decorators { data-advanced="true" }` — append `{ data-advanced="true" }` directly on the + heading line (same attr_list convention as `data-card-link="skip"` above). This hides that + heading, everything up to the next heading of the same or higher level, and its + integrated-TOC sidebar entry, on that page specifically. Tag the homepage row and the + content-page heading independently — `docs/javascripts/essentials_toggle.js` doesn't infer one + from the other, by design (simpler and more robust than deriving a map at runtime). + - **A whole homepage card** (e.g. the OpenCV card) — append `{: data-advanced="card" }` the + same way, right after the card's first paragraph (the icon + title link, e.g. + `[__OpenCV__](...)`). `.simplify-active .grid.cards > ul > li:has(> p[data-advanced="card"])` + in `extra.css` walks up from that paragraph to hide the whole enclosing `
FIG: print() checkpoints along a running program
-FIG: the parts of a print() statement
-FIG: the parts of an input() statement
-FIG: when to use AI while learning to program
- -??? info "What is Python, and what is this guide?" - - **Readable, and quick to write.** *Python* is a general-purpose language built for code that's easy to read back later — even by someone who didn't write it. No compiling: write a `.py` file, run it directly. - - - **Shows up everywhere** — web backends, data analysis and machine learning, automating repetitive tasks, scientific computing, quick glue scripts. Several of these are covered on this site's [Libraries](#utilities) pages. - - **The skills transfer.** Variables, conditionals, loops, functions, classes — the fundamentals every language shares — read closer to plain English here, so you spend your effort learning to *think* like a programmer instead of fighting a stricter syntax. Once solid, those fundamentals carry over to whatever language you pick up next. - - **Often the fastest language to write *correct* code in** — even though it's not the fastest to *run* — which is why it's such a common first choice for a new project. - - **This guide.** *Python Field Guide* is a free, in-browser reference — most code blocks are editable and runnable directly on the page. - - - **For learners** — self-taught, students in an intro course, or anyone who wants one combined reference to work through start to finish, instead of a scattered pile of search results. diff --git a/docs/javascripts/essentials_toggle.js b/docs/javascripts/essentials_toggle.js new file mode 100644 index 0000000..b672de8 --- /dev/null +++ b/docs/javascripts/essentials_toggle.js @@ -0,0 +1,254 @@ +(function () { + // "Essentials / Advanced" toggle: hides data-advanced content. On a + // homepage row, data-advanced="true" hides that row; the same attribute + // on a content page's own heading (e.g. functions.md's `## Decorators`) + // hides that section plus its TOC entry — marked independently in each + // place, no shared map. data-advanced="card" hides a whole homepage + // card (see extra.css); no content-page equivalent, since it marks a + // linked page rather than a section. Shows on every page; state + // persists via localStorage. + const STORAGE_KEY = "pt-simplify-active"; + + // pt-lib--N sizes each library box for its full card count; hiding cards + // in Essentials mode leaves boxes too wide. Recompute the visible count + // into --pt-lib-span so extra.css can override pt-lib--N while active. + function updateLibrarySpans() { + document.querySelectorAll(".pt-category--wide").forEach(function (box) { + const cards = box.querySelectorAll(".grid.cards > ul > li"); + let visible = 0; + cards.forEach(function (li) { + if (getComputedStyle(li).display !== "none") visible++; + }); + if (visible > 0) box.style.setProperty("--pt-lib-span", Math.min(visible, 4)); + }); + } + + // Hides/restores a heading and its whole section — every sibling up to + // the next heading of the same or higher level. + function setSectionHidden(heading, hidden) { + heading.hidden = hidden; + const level = Number(heading.tagName[1]); + let el = heading.nextElementSibling; + while (el && !(/^H[1-6]$/.test(el.tagName) && Number(el.tagName[1]) <= level)) { + el.hidden = hidden; + el = el.nextElementSibling; + } + + // Many pages wrap a whole ## section in