-
Notifications
You must be signed in to change notification settings - Fork 11
/
+layout.svelte
62 lines (52 loc) · 1.6 KB
/
+layout.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import { element_data } from '$lib'
import { repository } from '$root/package.json'
import { Footer } from '$site'
import { demos } from '$site/stores'
import { CmdPalette } from 'svelte-multiselect'
import { GitHubCorner } from 'svelte-zoo'
import '../app.css'
const routes = Object.keys(import.meta.glob(`./**/+page.{svx,svelte,md}`)).map(
(filename) => {
const parts = filename.split(`/`).filter((part) => !part.startsWith(`(`)) // remove hidden route segments
return { route: `/${parts.slice(1, -1).join(`/`)}`, filename }
}
)
if (routes.length < 3) {
console.error(`Too few demo routes found: ${routes.length}`)
}
$demos = routes
.filter(({ filename }) => filename.includes(`/(demos)/`))
.map(({ route }) => route)
const actions = routes
.map(({ route }) => route)
.concat(element_data.map(({ name }) => `/${name.toLowerCase()}`))
.map((name) => {
return { label: name, action: () => goto(name) }
})
</script>
<CmdPalette {actions} placeholder="Go to..." />
<GitHubCorner href={repository} />
{#if !$page.error && $page.url.pathname !== `/`}
<a href="." aria-label="Back to index page">« home</a>
{/if}
<slot />
<Footer />
<style>
a[href='.'] {
font-size: 15pt;
position: absolute;
top: 2em;
left: 2em;
background-color: rgba(255, 255, 255, 0.1);
padding: 1pt 5pt;
border-radius: 3pt;
transition: 0.2s;
z-index: 1;
}
a[href='.']:hover {
background-color: rgba(255, 255, 255, 0.2);
}
</style>