|
| 1 | +<script lang="ts"> |
| 2 | + import { TextArea } from '$components/base'; |
| 3 | + import { CodeBlock } from '$components/markdown'; |
| 4 | + import { FilePicker } from '$components/pickers'; |
| 5 | + import api from '$endpoints'; |
| 6 | + import consts from '$lib/consts'; |
| 7 | + import DelayedUpdater from '$lib/delayedUpdate'; |
| 8 | + import itemId from '$lib/itemId'; |
| 9 | + import type { ConfigJson } from '$lib/server/data/config'; |
| 10 | + import { itemFileUrl } from '$lib/urls'; |
| 11 | +
|
| 12 | + type Props = { |
| 13 | + configJson: ConfigJson; |
| 14 | + imageFiles: string[]; |
| 15 | + }; |
| 16 | +
|
| 17 | + const { configJson, imageFiles }: Props = $props(); |
| 18 | +
|
| 19 | + // Yucky work-around to make values update |
| 20 | + const config = $state(configJson); |
| 21 | +
|
| 22 | + const updater = new DelayedUpdater( |
| 23 | + async (value: ConfigJson) => api().config.put(value), |
| 24 | + consts.EDIT_COMMIT_HESITATION, |
| 25 | + ); |
| 26 | +</script> |
| 27 | + |
| 28 | +<div> |
| 29 | + <h2>Public settings</h2> |
| 30 | + <form> |
| 31 | + <div> |
| 32 | + <label for="site-icon"><h3>Site icon</h3></label> |
| 33 | + <FilePicker |
| 34 | + bind:selected={config.siteIcon} |
| 35 | + files={imageFiles} |
| 36 | + onchange={() => updater.update(config)} |
| 37 | + /> |
| 38 | + {#if config.siteIcon} |
| 39 | + <p> |
| 40 | + Note: the image may be squashed/stretched by the browser when |
| 41 | + displayed in the address bar. |
| 42 | + </p> |
| 43 | + <div class="site-icon-preview"> |
| 44 | + <img |
| 45 | + src={itemFileUrl(itemId.ROOT, config.siteIcon)} |
| 46 | + alt={'Preview of site icon'} |
| 47 | + /> |
| 48 | + </div> |
| 49 | + {/if} |
| 50 | + </div> |
| 51 | + |
| 52 | + <label for="rel-me"><h3>Verification links</h3></label> |
| 53 | + <TextArea |
| 54 | + bind:value={() => config.relMe.join('\n'), |
| 55 | + (relMe: string) => (config.relMe = relMe.trim().split('\n'))} |
| 56 | + oninput={() => updater.update(config)} |
| 57 | + /> |
| 58 | + <p>Place each URL on a separate line.</p> |
| 59 | + <p>The links will be included as:</p> |
| 60 | + <CodeBlock |
| 61 | + language="html" |
| 62 | + code={config.relMe |
| 63 | + .map((me) => `<link rel="me" href="${me}" />`) |
| 64 | + .join('\n')} |
| 65 | + /> |
| 66 | + </form> |
| 67 | +</div> |
| 68 | + |
| 69 | +<style> |
| 70 | + .site-icon-preview { |
| 71 | + aspect-ratio: 1 / 1; |
| 72 | + max-width: 30%; |
| 73 | + margin: 10px; |
| 74 | + } |
| 75 | + .site-icon-preview > img { |
| 76 | + width: 100%; |
| 77 | + height: 100%; |
| 78 | + border-radius: 10px; |
| 79 | + } |
| 80 | +</style> |
0 commit comments