misc: add theme color to meta
This commit is contained in:
1 parent
6b78827239
commit
02dcd0a06d
2 files changed
+37
-1
No files matched your search
@@ -57,6 +57,28 @@ export function hexToRgb(value: string) {
|
|||||||
return `${r} ${g} ${b}`
|
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(
|
function themeStore(
|
||||||
data: Writable<ThemeData>,
|
data: Writable<ThemeData>,
|
||||||
fn: (
|
fn: (
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
|
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { pwaInfo } from 'virtual:pwa-info'
|
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 { userSettings } from '$lib/settings.js'
|
||||||
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
@@ -21,6 +26,7 @@
|
|||||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
||||||
import { locale } from '$lib/translations'
|
import { locale } from '$lib/translations'
|
||||||
|
import { getDefaultColors } from '$lib/ui/presets'
|
||||||
|
|
||||||
nProgress.configure({
|
nProgress.configure({
|
||||||
minimum: 0.4,
|
minimum: 0.4,
|
||||||
@@ -63,6 +69,14 @@
|
|||||||
<svelte:head>
|
<svelte:head>
|
||||||
{#if $site?.site_view}
|
{#if $site?.site_view}
|
||||||
<title>{$site?.site_view.site.name}</title>
|
<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}
|
{#if LINKED_INSTANCE_URL}
|
||||||
<link rel="icon" href={$site?.site_view?.site.icon} />
|
<link rel="icon" href={$site?.site_view?.site.icon} />
|
||||||
<meta name="description" content={$site?.site_view?.site.description} />
|
<meta name="description" content={$site?.site_view?.site.description} />
|
||||||
|
|||||||
Reference in new issue
Block a user