mirror of
https://github.com/allankoechke/mantisbase-admin.git
synced 2026-12-01 01:15:36 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90969110f7 | |||
| 5c96ed6770 | |||
| 367246f6ba | |||
| 0c8b9183f1 | |||
| 7134c7df5b | |||
| 3b227cb720 | |||
| 84333ea981 |
@@ -1,4 +1,5 @@
|
|||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
|
import { ScriptHeaders } from '@/lib/script-headers'
|
||||||
import './globals.css'
|
import './globals.css'
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@@ -16,6 +17,7 @@ export default function RootLayout({
|
|||||||
<head>
|
<head>
|
||||||
<link rel="icon" href="/mantisbase.svg" type="image/svg+xml" />
|
<link rel="icon" href="/mantisbase.svg" type="image/svg+xml" />
|
||||||
<link rel="alternate icon" href="/favicon.ico" />
|
<link rel="alternate icon" href="/favicon.ico" />
|
||||||
|
<ScriptHeaders />
|
||||||
</head>
|
</head>
|
||||||
<body>{children}</body>
|
<body>{children}</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
42
lib/script-headers.tsx
Normal file
42
lib/script-headers.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const HEAD_SCRIPTS =
|
||||||
|
process.env.HEAD_SCRIPTS?.trim() ??
|
||||||
|
process.env.NEXT_PUBLIC_HEAD_SCRIPTS?.trim() ??
|
||||||
|
''
|
||||||
|
|
||||||
|
function parseScriptTags(html: string) {
|
||||||
|
return html.match(/<script[\s\S]*?<\/script>/gi) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderScriptTag(tag: string, index: number) {
|
||||||
|
const src = tag.match(/\bsrc="([^"]+)"/)?.[1]
|
||||||
|
const defer = /\bdefer\b/.test(tag)
|
||||||
|
const dataDomain = tag.match(/\bdata-domain="([^"]+)"/)?.[1]
|
||||||
|
const inline = tag.match(/<script[^>]*>([\s\S]*?)<\/script>/i)?.[1]?.trim()
|
||||||
|
|
||||||
|
if (src) {
|
||||||
|
return (
|
||||||
|
<script
|
||||||
|
key={index}
|
||||||
|
defer={defer || undefined}
|
||||||
|
data-domain={dataDomain}
|
||||||
|
src={src}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inline) {
|
||||||
|
return (
|
||||||
|
<script key={index} dangerouslySetInnerHTML={{ __html: inline }} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ScriptHeaders() {
|
||||||
|
if (!HEAD_SCRIPTS) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{parseScriptTags(HEAD_SCRIPTS).map(renderScriptTag)}</>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user