feat: add jsFile option to include custom JavaScript
This commit is contained in:
committed by
Stefan Rotsch
parent
a443aef0f4
commit
6a5b8637f7
@@ -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() {
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user