Skip to content

Commit

Permalink
fix: resolve asset url from frontmatter, close #108
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 14, 2021
1 parent a53dc94 commit 53c47ed
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/client/layoutHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { 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 && background[0] === '#' && background.startsWith('rgb')

Expand All @@ -14,8 +23,8 @@ export function handleBackground(background?: string, dim = false): CSSPropertie
? undefined
: background
? dim
? `linear-gradient(#0005, #0008), url(${background})`
: `url("${background}")`
? `linear-gradient(#0005, #0008), url(${resolveAssetUrl(background)})`
: `url("${resolveAssetUrl(background)}")`
: undefined,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
Expand Down

0 comments on commit 53c47ed

Please sign in to comment.