feat: add jsFile option to include custom JavaScript

This commit is contained in:
Mathias Schopmans
2024-06-28 16:45:28 +02:00
committed by Stefan Rotsch
parent a443aef0f4
commit 6a5b8637f7
6 changed files with 25 additions and 8 deletions

View File

@@ -22,7 +22,12 @@ export function getAppName() {
}
export function getLogoUrl() {
return assetUrl("/" + config.logoFile);
return assetUrl(config.logoFile);
}
export function getJsUrl(): string {
if (!config.jsFile) return "";
return assetUrl(config.jsFile);
}
export function getChartConfig() {

View File

@@ -7,6 +7,8 @@ export function cn(...inputs: ClassValue[]) {
}
export function assetUrl(path: string) {
if (/^https?:/.test(path)) return path;
if (!config.basePath) return path;
if (!path.startsWith("/")) path = "/" + path;
return `${config.basePath}${path}`;
}

View File

@@ -1,8 +1,10 @@
import { NextPage } from "next";
import type { AppProps } from "next/app";
import Head from "next/head";
import Script from "next/script";
import { Layout, type LayoutClass } from "@/components/Layout/Layout";
import { getJsUrl } from "@/lib/data";
import { formatTitle } from "@/lib/format";
import { assetUrl } from "@/lib/utils";
import "@/styles/_globals.css";
@@ -18,6 +20,7 @@ type CustomAppProps = AppProps & {
};
export default function App({ Component, pageProps, router }: CustomAppProps) {
const jsUrl = getJsUrl();
return (
<>
<Head>
@@ -27,6 +30,7 @@ export default function App({ Component, pageProps, router }: CustomAppProps) {
</Head>
<Layout layoutClass={Component.layoutClass}>
<Component {...pageProps} />
{jsUrl && <Script src={jsUrl} />}
</Layout>
</>
);