-
Notifications
You must be signed in to change notification settings - Fork 0
/
layoutHelper.ts
38 lines (33 loc) · 976 Bytes
/
layoutHelper.ts
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
import type { CSSProperties } from 'vue';
/**
* Resolve urls from frontmatter and append with the base url
*/
export function resolveAssetUrl(url: string) {
if (url.startsWith('/')) {
return import.meta.env.BASE_URL + url.slice(1);
}
return url;
}
export function handleBackground(
background?: string,
dim = false,
): CSSProperties {
const isColor =
background && ['#', 'rgb', 'hsl'].some((v) => background.indexOf(v) === 0);
const style = {
background: isColor ? background : undefined,
color: background && !isColor ? 'white' : undefined,
backgroundImage: isColor
? undefined
: background
? dim
? `linear-gradient(#0005, #0008), url(${resolveAssetUrl(background)})`
: `url("${resolveAssetUrl(background)}")`
: undefined,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
};
if (!style.background) delete style.background;
return style;
}