Skip to content

Commit 7741726

Browse files
committed
updating comments about how this works
1 parent e051780 commit 7741726

2 files changed

Lines changed: 20 additions & 38 deletions

File tree

common/README

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ Both files are intentionally minimal:
1111
- `header.html` uses DocC's `custom-header` template hook to add a Swift logo
1212
linking to swift.org to the masthead, between the sidebar-toggle control
1313
and the page title. It targets the masthead rather than the Navigator
14-
sidebar itself because the masthead mounts once from data already known at
15-
page load and never gets torn down and rebuilt — unlike the sidebar, which
16-
swift-docc-render swaps from a loading-skeleton state to the real,
17-
populated one once the navigator index data has loaded, discarding
18-
whatever a script had inserted into the skeleton. The logo is appended as
19-
the last child of `.pre-title` (the toggle's own wrapper) rather than
20-
inserted as a sibling before `.nav-title`, because swift-docc-render's CSS
21-
assigns the title its grid placement via the adjacent-sibling selector
22-
`.pre-title + .nav-title`, which requires them to stay immediate siblings.
23-
Because it's part of the persistent masthead rather than the sidebar, the
24-
logo stays visible regardless of whether the sidebar is shown, hidden, or
25-
a mobile drawer, with no extra positioning or z-index logic needed. It
26-
also still reserves the `#version-switcher` div for a future
27-
documentation-version switcher — add the switcher UI there when that
28-
lands.
14+
sidebar because the sidebar gets torn down and rebuilt once its data
15+
loads (discarding anything inserted into its loading-skeleton state),
16+
while the masthead mounts once and stays. The logo is appended inside
17+
`.pre-title` rather than inserted as a sibling before `.nav-title`, since
18+
swift-docc-render positions the title via the adjacent-sibling CSS rule
19+
`.pre-title + .nav-title`, which needs them to stay adjacent. Being part
20+
of the masthead rather than the sidebar, it stays visible regardless of
21+
the sidebar's shown/hidden/drawer state. It also still reserves the
22+
`#version-switcher` div for a future documentation-version switcher — add
23+
the switcher UI there when that lands.
2924
- `footer.html` carries the copyright/trademark notice, the same legal links
3025
(License, Security, Privacy Policy, Cookies) swift.org's footer has, and
3126
an Adobe Analytics page-activation snippet mirroring swift.org's

common/header.html

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,18 @@
1212

1313
<script>
1414
(function () {
15-
// Sourced from swiftlang/swift-org-website's assets/images/icon-swift.svg
16-
// (the currentColor variant, meant for light/dark masthead use — the
17-
// upstream asset intentionally leaves fill unset so consumers apply their
18-
// own; fill="currentColor" below is added here to do that).
15+
// Sourced from swiftlang/swift-org-website's assets/images/icon-swift.svg,
16+
// the currentColor variant — fill="currentColor" below is added here since
17+
// the upstream asset leaves it unset for consumers to apply.
1918
var LOGO_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="22" height="22" aria-hidden="true"><path fill="currentColor" fill-rule="nonzero" transform="matrix(.351937 0 0 .351937 -1.96558 -2.00601)" d="m46.955 36.578c-.002-.002-.003-.003-.005-.005.066-.223.134-.445.191-.673 2.46-9.799-3.543-21.384-13.701-27.484 4.452 6.035 6.42 13.344 4.671 19.735-.156.571-.343 1.118-.55 1.65-.225-.148-.509-.316-.889-.526 0 0-10.104-6.238-21.055-17.273-.288-.29 5.839 8.757 12.793 16.104-3.276-1.839-12.406-8.482-18.186-13.772.71 1.185 1.555 2.325 2.483 3.423 4.827 6.121 11.121 13.673 18.662 19.473-5.298 3.242-12.785 3.494-20.239.003-1.844-.864-3.577-1.907-5.182-3.091 3.156 5.047 8.015 9.401 13.93 11.943 7.054 3.032 14.068 2.826 19.292.05l-.004.006c.024-.015.054-.031.079-.047.214-.115.427-.232.636-.356 2.51-1.303 7.467-2.625 10.129 2.553.651 1.267 2.036-5.448-3.055-11.713z"/></svg>';
2019

21-
// The masthead (.nav-content > .pre-title, .nav-title, .nav-menu) is
22-
// rendered client-side by swift-docc-render (Vue), not present in this
23-
// page's initial HTML, so it may not exist yet when this script runs —
24-
// retry via MutationObserver until it mounts. Unlike the Navigator
25-
// sidebar, the masthead has no loading-skeleton/real-content swap to
26-
// race against: it mounts once from data already known at page load and
27-
// stays, so this observer keeps running (harmlessly, guarded by the
28-
// .masthead-swift-logo check below) rather than needing to disconnect at
29-
// a precise moment.
30-
//
31-
// Appended as the last child of `.pre-title` rather than inserted as a
32-
// sibling between `.pre-title` and `.nav-title`: swift-docc-render's own
33-
// CSS assigns `.nav-title` its grid placement via the adjacent-sibling
34-
// selector `.pre-title + .nav-title`, which requires them to stay
35-
// immediate siblings. Landing inside `.pre-title` keeps that intact while
36-
// still sitting visually between the sidebar toggle and the title text —
37-
// and, being part of the persistent masthead rather than the sidebar
38-
// itself, it stays visible regardless of whether the sidebar is shown,
39-
// hidden, or a mobile drawer.
20+
// Appended inside `.pre-title` rather than inserted as a sibling before
21+
// `.nav-title`: swift-docc-render positions the title via the CSS rule
22+
// `.pre-title + .nav-title`, which needs them to stay adjacent siblings.
23+
// This keeps that intact while still landing between the sidebar toggle
24+
// and the title — and, being part of the masthead rather than the
25+
// sidebar, it stays visible regardless of the sidebar's own
26+
// shown/hidden/drawer state.
4027
function insertLogoLink() {
4128
var preTitle = document.querySelector('.pre-title');
4229
if (!preTitle || preTitle.querySelector('.masthead-swift-logo')) {

0 commit comments

Comments
 (0)