Skip to content

Commit

Permalink
feat: add jsFile option to include custom JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasschopmans authored and srotsch committed Jul 1, 2024
1 parent a443aef commit 6a5b863
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Open the `config.json` file and configure the radar to your needs.
| basePath | Set if hosting under a sub-path, otherwise set it to `/`. Default is `/techradar` |
| baseUrl | Set to the full URL, where the radar will be hosted. Will be used for sitemap.xml. `https://www.aoe.com/techradar` |
| logoFile | (optional) Filepath in public folder. Default is `logo.svg` |
| jsFile | (optional) Filepath in public folder or URL to enable include of custom script |
| toggles | (optional) Modify the behaviour and contents of the radar. See config below. |
| sections | (optional) Modify the order of sections (`radar`, `tags`, `list`) |
| colors | A map of colors for the radar. Can be any valid CSS color value |
Expand Down
1 change: 1 addition & 0 deletions data/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"baseUrl": "",
"editUrl": "https://github.dev/AOEpeople/techradar/blob/main/radar/{release}/{id}.md",
"logoFile": "logo.svg",
"jsFile": "",
"toggles": {
"showChart": true,
"showTagFilter": true,
Expand Down
18 changes: 11 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
4 changes: 4 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,6 +20,7 @@ type CustomAppProps = AppProps & {
};

export default function App({ Component, pageProps, router }: CustomAppProps) {
const jsUrl = getJsUrl();
return (
<>
<Head>
Expand All @@ -27,6 +30,7 @@ export default function App({ Component, pageProps, router }: CustomAppProps) {
</Head>
<Layout layoutClass={Component.layoutClass}>
<Component {...pageProps} />
{jsUrl && <Script src={jsUrl} />}
</Layout>
</>
);
Expand Down

0 comments on commit 6a5b863

Please sign in to comment.