-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Push * Add changeset * Banners * Explicitly type
- Loading branch information
Showing
4 changed files
with
101 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@sveltejs/site-kit': patch | ||
--- | ||
|
||
feat: Time-bound banner |
This file contains 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
This file contains 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,34 @@ | ||
<script context="module"> | ||
/** | ||
* Only to be used on non svelte.dev sites. Shouldn't be used inside svelte.dev codebase itself | ||
* @param {import('./Banner.svelte').BannerScope} scope | ||
* @param {import('@sveltejs/kit').RequestEvent['fetch']} fetch | ||
* @returns {Promise<import('./Banner.svelte').BannerData>} | ||
*/ | ||
export async function fetchBanner(scope = 'svelte.dev', fetch) { | ||
if (scope === 'svelte.dev') return fetch('/banner.json').then((r) => r.json()); | ||
const req = await fetch('https://svelte.dev/banner.json'); | ||
if (!req.ok) { | ||
console.warn('There was an error fetching the banner data. Check svelte.dev/banner.json'); | ||
return []; | ||
} | ||
return /** @type {import('./Banner.svelte').BannerData} */ (await req.json()).filter( | ||
(banner) => !banner.scope || banner.scope?.includes(scope) | ||
); | ||
} | ||
</script> | ||
<script> | ||
import Banner from './Banner.svelte'; | ||
/** @type {import('./Banner.svelte').BannerData} */ | ||
export let data; | ||
</script> | ||
{#each data as { content, href, id, start, arrow, end }} | ||
<Banner {id} start={new Date(start)} end={end ? new Date(end) : undefined} {arrow} {href}> | ||
{@html content} | ||
</Banner> | ||
{/each} |
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export { default as Banners, fetchBanner } from './Banners.svelte'; | ||
export { default as Icon } from './Icon.svelte'; | ||
export { default as Icons } from './Icons.svelte'; | ||
export { default as Section } from './Section.svelte'; | ||
export { default as Shell } from './Shell.svelte'; | ||
export { default as ThemeToggle } from './ThemeToggle.svelte'; | ||
export { default as Banner } from './Banner.svelte'; |