Repository navigation
feat: author-fixed and hidden tutorial variables - #2856
Merged
Merged
Conversation
…t, no code change)
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.
Closes #2852.
What
Tutorial authors can now set a variable's value once and/or hide it from the reader, extending the #2811 tutorial-variables feature. Two new optional frontmatter fields on a variable:
value: <string>— an author-fixed literal, substituted everywhere. Change it in one place, it updates across the whole tutorial.display: <bool>— whether to show the reader-facing input. Defaults totrue(shown).falsehides the input; the value still substitutes into the body.Precedence for the substituted value:
value>default(regex) > reader input / stored > empty. A literalvalueoverrides a regexdefault.Behavior matrix
valuedisplayfalsevaluetrue/omittedvalue, overridable by readerfalsedefaultregex, else emptytrue/omittedExample (hidden author-fixed):
How
scripts/parsers/variables.ts—value?/display?onTutorialVariable; validate (displaymust be boolean,valuemust be string);labelnow optional whendisplay:false, still required when displayed.scripts/parsers/types.ts— source-frontmatter shape widened.render-frontmatter.tsemits the fields verbatim (no code change; guard test added).hugo-apps/src/tutorial-variables/— newresolveInitial()(value > default); island renders inputs only fordisplay !== falseand seeds every variable (hidden literal values substitute with no input).docs/authors/writing-tutorials.md§3.7 +variables.tsdoc-comment.Tests
71 passing across 5 variable suites (parser validation, compose carry-through, frontmatter emit, island pure helpers, island component mount). XSS-safe (
applyValueusestextContent), backward-compatible (no new field ⇒ unchanged behavior).Fresh whole-branch review (separate model): no Critical/Important findings.
Notes / follow-ups
value, the persisted value wins (reader-owned). An author who wants a value to always win should usedisplay: false.valueunconditionally wins only for hidden variables.value: ""(empty string) is treated as "no value" (falls through to default/empty) — deliberate, tested.use-variables-in-tutorials) is generated from thesap-tutorialssource repo; exercising a hidden/fixed variable there is a separate source-repo change.🤖 Generated with Claude Code