-
-
Notifications
You must be signed in to change notification settings - Fork 74
docs: add cross-site announcement banner #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7792edc
docs: add cross-site announcement banner
jdx 8be55d1
docs: validate banner link scheme to prevent javascript: URLs
jdx 1015829
docs: fix banner double-offset by using position: fixed
jdx 9b7a45d
docs: improve banner contrast and bump z-index above nav
jdx 240c4d7
docs: add en.dev footer
jdx dea56f9
docs: center banner text and drop noreferrer
jdx 741a9db
docs: fix asymmetric banner padding so text is truly centered
jdx 6851fce
docs: drop cache: no-cache from banner fetch
jdx 93d7361
docs: fix banner fallback color to match brand
jdx 622e8db
docs: keep --vp-layout-top-height in sync via ResizeObserver
jdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| .jdx-banner { | ||
| position: relative; | ||
| z-index: 60; | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| display: flex; | ||
| gap: 0.75rem; | ||
| align-items: center; | ||
| padding: 0.5rem 1rem; | ||
| background: var(--vp-c-brand-1, #3451b2); | ||
| color: #fff; | ||
| font-size: 0.9rem; | ||
| line-height: 1.4; | ||
| } | ||
| .jdx-banner a { | ||
| color: #fff; | ||
| text-decoration: underline; | ||
| font-weight: 500; | ||
| } | ||
| .jdx-banner button { | ||
| margin-left: auto; | ||
| background: transparent; | ||
| border: 0; | ||
| color: #fff; | ||
| font-size: 1.25rem; | ||
| cursor: pointer; | ||
| line-height: 1; | ||
| padding: 0 0.25rem; | ||
| opacity: 0.85; | ||
| } | ||
| .jdx-banner button:hover { | ||
| opacity: 1; | ||
| } | ||
| @media (max-width: 640px) { | ||
| .jdx-banner { | ||
| font-size: 0.85rem; | ||
| padding: 0.4rem 0.75rem; | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import './banner.css' | ||
|
|
||
| interface BannerData { | ||
| id: string | ||
| enabled: boolean | ||
| message: string | ||
| link?: string | ||
| linkText?: string | ||
| } | ||
|
|
||
| const ENDPOINT = 'https://jdx.dev/banner.json' | ||
| const STORAGE_KEY = 'jdx-banner-dismissed' | ||
|
|
||
| export function initBanner(): void { | ||
| if (typeof window === 'undefined') return | ||
| fetch(ENDPOINT, { cache: 'no-cache' }) | ||
| .then((r) => (r.ok ? (r.json() as Promise<BannerData>) : null)) | ||
| .then((b) => { | ||
| if (!b || !b.enabled) return | ||
| if (localStorage.getItem(STORAGE_KEY) === b.id) return | ||
| render(b) | ||
| }) | ||
| .catch(() => {}) | ||
| } | ||
|
|
||
| function render(b: BannerData): void { | ||
| const el = document.createElement('div') | ||
| el.className = 'jdx-banner' | ||
| el.setAttribute('role', 'region') | ||
| el.setAttribute('aria-label', 'Site announcement') | ||
|
|
||
| const msg = document.createElement('span') | ||
| msg.textContent = b.message | ||
| el.appendChild(msg) | ||
|
|
||
| if (b.link) { | ||
| const a = document.createElement('a') | ||
| a.href = b.link | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
| a.target = '_blank' | ||
| a.rel = 'noopener' | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
| a.textContent = b.linkText || 'Learn more' | ||
| el.appendChild(a) | ||
| } | ||
|
|
||
| const btn = document.createElement('button') | ||
| btn.type = 'button' | ||
| btn.setAttribute('aria-label', 'Dismiss') | ||
| btn.textContent = '\u00d7' | ||
| btn.addEventListener('click', () => { | ||
| localStorage.setItem(STORAGE_KEY, b.id) | ||
| el.remove() | ||
| document.documentElement.style.removeProperty('--vp-layout-top-height') | ||
| }) | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
| el.appendChild(btn) | ||
|
|
||
| document.body.prepend(el) | ||
|
|
||
| requestAnimationFrame(() => { | ||
| document.documentElement.style.setProperty( | ||
| '--vp-layout-top-height', | ||
| `${el.offsetHeight}px`, | ||
| ) | ||
| }) | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.