Skip to content

Commit

Permalink
fix: build asset url
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Dec 3, 2024
1 parent d5dbefe commit 273f2c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/lib/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Builds a URL to an asset in the public directory.
*
* @param path The relative path to use.
* @returns An absolute url string.
*/
export function asset(...path: string[]) {
return [import.meta.env.BASE_URL, ...path]
.join('/')
.replace(/[/]{2,}/g, '/')
}
4 changes: 2 additions & 2 deletions src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import AppSettingsDialog from '@/components/AppSettingsDialog'
import AppTemplatesDialog from '@/components/AppTemplatesDialog'
import Devtools from '@/components/Devtools'
import { Toaster } from '@/components/ui/toaster'
import { asset } from '@/lib/url'
import { createRootRoute, Outlet } from '@tanstack/react-router'


export const Route = createRootRoute({
component: () => (<>
<header className="fixed inset-x-0 top-0 z-50 h-16 bg-mjml-500 text-white">
<div className="container mx-auto flex h-full flex-row flex-nowrap items-center gap-x-4">
<img src='/icon-192.png' className='size-12' />
<img src={asset('icon-192.png')} className='size-12' />
<p className="text-2xl font-bold">
mjml.app
</p>
Expand Down

0 comments on commit 273f2c8

Please sign in to comment.