-
Notifications
You must be signed in to change notification settings - Fork 21
/
+layout.svelte
60 lines (52 loc) · 1.49 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
<script lang="ts">
import { afterNavigate, goto } from '$app/navigation'
import { page } from '$app/stores'
import { Footer } from '$lib'
import { CmdPalette } from 'svelte-multiselect'
import { CopyButton } from 'svelte-zoo'
import '../app.css'
const actions = Object.keys(import.meta.glob(`./**/+page.{svx,svelte,md}`)).map(
(filename) => {
const parts = filename.split(`/`).filter((part) => !part.startsWith(`(`)) // remove hidden route segments
const route = `/${parts.slice(1, -1).join(`/`)}`
return { label: route, action: () => goto(route) }
},
)
afterNavigate(() => {
for (const node of document.querySelectorAll(`pre > code`)) {
// skip if <pre> already contains a button (presumably for copy)
const pre = node.parentElement
if (!pre || pre.querySelector(`button`)) continue
new CopyButton({
target: pre,
props: {
content: node.textContent ?? ``,
style: `position: absolute; top: 1ex; right: 1ex;`,
},
})
}
})
</script>
<CmdPalette {actions} placeholder="Go to..." />
{#if $page.url.pathname !== `/`}
<a href="/" aria-label="Back to index page">← home</a>
{/if}
<slot />
<Footer />
<style>
a[href='/'] {
font-size: 14pt;
position: absolute;
top: 2em;
left: 2em;
background-color: rgba(0, 0, 0, 0.5);
padding: 1pt 5pt;
border-radius: 3pt;
transition: 0.2s;
}
@media print {
a[href='/'] {
display: none;
}
}
</style>