misc: add theme color to meta

This commit is contained in:
Xylight committed 2024-07-25 12:01:15 -07:00
1 parent 6b78827239
commit 02dcd0a06d
2 files changed
+37 -1

No files matched your search

+22
View File
@@ -57,6 +57,28 @@ export function hexToRgb(value: string) {
return `${r} ${g} ${b}`
}
export function rgbToHex(rgbString: string): string {
const rgb = rgbString.split(' ')
if (rgb.length !== 3) {
return rgbString
}
const [r, g, b] = rgb.map((val) => {
const num = parseInt(val, 10)
if (isNaN(num) || num < 0 || num > 255) {
return 0
}
return num
})
// Convert to hex and pad with zeros if necessary
const toHex = (n: number) => n.toString(16).padStart(2, '0')
// Return the hex color code
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
}
function themeStore(
data: Writable<ThemeData>,
fn: (
+15 -1
View File
@@ -8,7 +8,12 @@
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
// @ts-ignore
import { pwaInfo } from 'virtual:pwa-info'
import { colorScheme } from '$lib/ui/colors.js'
import {
colorScheme,
inDarkColorScheme,
rgbToHex,
theme,
} from '$lib/ui/colors.js'
import { userSettings } from '$lib/settings.js'
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
import { onMount } from 'svelte'
@@ -21,6 +26,7 @@
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
import { LINKED_INSTANCE_URL } from '$lib/instance'
import { locale } from '$lib/translations'
import { getDefaultColors } from '$lib/ui/presets'
nProgress.configure({
minimum: 0.4,
@@ -63,6 +69,14 @@
<svelte:head>
{#if $site?.site_view}
<title>{$site?.site_view.site.name}</title>
<meta
name="theme-color"
content={rgbToHex(
$colorScheme && inDarkColorScheme()
? $theme.colors.zinc?.[925] ?? getDefaultColors().zinc[925]
: $theme.colors.slate?.[25] ?? getDefaultColors().slate[25]
)}
/>
{#if LINKED_INSTANCE_URL}
<link rel="icon" href={$site?.site_view?.site.icon} />
<meta name="description" content={$site?.site_view?.site.description} />