Skip to content

Add permalink anchors to every example#25

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/add-anchored-links-to-examples
Closed

Add permalink anchors to every example#25
Copilot wants to merge 3 commits into
mainfrom
copilot/add-anchored-links-to-examples

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Each numbered example on principle pages lacked a stable URL fragment, making it impossible to link directly to a specific example.

Changes

  • examples/NN-*.md (all 12 files) — the numbered list of examples has been moved from the Markdown body into a structured examples: YAML front matter array. Each entry has a title and body key. The Markdown body retains only the # Principle N heading, blockquote, and ## 20 Practical Examples subheading.
  • _layouts/principle.html — iterates over page.examples using a Liquid {% for %} loop, generating id="example-N" on each <li> and appending a link-icon anchor at Jekyll build time. Enables deep links such as:
    /examples/01-make-the-right-thing-the-easy-thing/#example-5
    
  • assets/css/style.css — adds .example-anchor styles: hidden by default, revealed on li:hover / :focus, aligned to the far right of the flex row via margin-left: auto, using existing colour tokens.

Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using js? Jekyll must surely know how to iterate

@landro landro marked this pull request as ready for review May 5, 2026 04:14
Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using js? Jekyll must surely know how to iterate

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

Why are we using js? Jekyll must surely know how to iterate

Good call. Replaced the JavaScript with proper Jekyll/Liquid iteration (db0288b). The 20 examples in each of the 12 principle files are now stored as a structured examples: array in YAML front matter. The principle.html layout iterates over page.examples with {% for %}, generating id="example-N" and the anchor link at build time — no runtime JS needed.

Copilot finished work on behalf of landro May 5, 2026 04:22
Copilot AI requested a review from landro May 5, 2026 04:22
Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a screenshot of these changes @copilot

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

I need a screenshot of these changes @copilot

Here's the rendered result:

Normal state — examples render as numbered cards with the anchor hidden:
Normal state

Hover state — the link icon appears top-right of the card on hover, linking directly to e.g. #example-1:
Hover state

All IDs (example-1example-20) and anchors are generated at build time by Jekyll — no JavaScript involved.

Copilot finished work on behalf of landro May 5, 2026 04:33
Copilot AI requested a review from landro May 5, 2026 04:33
Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ok. The formatting of the example commands breaks everything. @copilot

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

This is not ok. The formatting of the example commands breaks everything.

Fixed in 14b5c91. The <li> uses display: flex, so inline <code> elements inside the body text were each becoming their own flex item. Wrapping the body in a <span> keeps the title, em-dash, text, and inline code as a single flex child.

Normal state:
Normal state

Hover state (anchor icon visible):
Hover state

Copilot finished work on behalf of landro May 5, 2026 04:41
Copilot AI requested a review from landro May 5, 2026 04:41
Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Could you add a diff for the generated page? I want to make sure the actual html/css stays more or less the same as before

Copy link
Copy Markdown
Owner

@landro landro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Could you add a diff for the generated page? I want to make sure the actual html/css stays more or less the same as before

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot Could you add a diff for the generated page? I want to make sure the actual html/css stays more or less the same as before

Here's the structural diff for one example item. The content is identical — the only additions are the id attribute on <li>, a <span> wrapper (to fix the flex layout), and the hidden anchor <a>:

Before — each <li> was a plain Markdown-generated <p>:

<ol>
  <li>
    <p><strong>Scaffold with security baked in</strong> — Provide a <code>create-service</code> CLI command …</p>
  </li></ol>

After — each <li> gets an id, the text is in a <span>, plus a hidden anchor link:

<ol>
  <li id="example-1">
    <span><strong>Scaffold with security baked in</strong> &mdash; Provide a <code>create-service</code> CLI command …</span>
    <a href="#example-1" class="example-anchor" aria-label="Permalink to example 1">
      <svg />
    </a>
  </li></ol>

The CSS adds .example-anchor (hidden by default, visible on li:hover/:focus) — no existing selectors were changed. All 20 items per page follow the same pattern.

Copilot finished work on behalf of landro May 5, 2026 05:33
Copilot AI requested a review from landro May 5, 2026 05:33
@landro landro closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants