-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:NDLANO/ndla-frontend into learnin…
…gpath-enter-selects-resource-resorucePicker
- Loading branch information
Showing
46 changed files
with
668 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
e2e/apiMocks/unauthenticated_learningpath.spec.ts_contains_content.har
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Copyright (c) 2025-present, NDLA. | ||
* | ||
* This source code is licensed under the GPLv3 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import { ReactNode } from "react"; | ||
import type { ManifestChunk } from "vite"; | ||
import config from "./config"; | ||
|
||
interface Props { | ||
language: string; | ||
children?: ReactNode; | ||
chunks?: ManifestChunk[]; | ||
devEntrypoint: string; | ||
} | ||
|
||
const getUniqueCss = (chunks: ManifestChunk[]) => { | ||
const uniq = chunks.reduce((acc, curr) => { | ||
curr.css?.forEach((css) => acc.add(css)); | ||
return acc; | ||
}, new Set<string>()); | ||
return Array.from(uniq); | ||
}; | ||
|
||
export const Document = ({ language, children, chunks = [], devEntrypoint }: Props) => { | ||
const faviconEnvironment = config.ndlaEnvironment === "dev" ? "test" : config.ndlaEnvironment; | ||
const locale = language === "nb" || language === "nn" ? "no" : language; | ||
|
||
const [entryPoint, ...importedChunks] = chunks; | ||
const css = getUniqueCss(chunks); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<link rel="icon" type="image/png" sizes="32x32" href={`/static/favicon-${faviconEnvironment}-32x32.png`} /> | ||
<link rel="icon" type="image/png" sizes="16x16" href={`/static/favicon-${faviconEnvironment}-16x16.png`} /> | ||
<link | ||
rel="apple-touch-icon" | ||
type="image/png" | ||
sizes="180x180" | ||
href={`/static/apple-touch-icon-${faviconEnvironment}.png`} | ||
/> | ||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta charSet="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1 viewport-fit=cover" /> | ||
<link href="https://api.fontshare.com/v2/css?f[]=satoshi@1&display=swap" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
<script | ||
type="text/javascript" | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
window.dataLayer = window.dataLayer || []; | ||
window._mtm = window._mtm || []; | ||
window.originalLocation = { | ||
originalLocation: | ||
document.location.protocol + | ||
"//" + | ||
document.location.hostname + | ||
document.location.pathname + | ||
document.location.search, | ||
}; | ||
window.dataLayer.push(window.originalLocation); | ||
`, | ||
}} | ||
></script> | ||
{config.runtimeType === "development" && ( | ||
<> | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
import RefreshRuntime from "/@react-refresh"; | ||
RefreshRuntime.injectIntoGlobalHook(window); | ||
window.$RefreshReg$ = () => {}; | ||
window.$RefreshSig$ = () => (type) => type; | ||
window.__vite_plugin_react_preamble_installed__ = true; | ||
`, | ||
}} | ||
type="module" | ||
/> | ||
<script src="/@vite/client" type="module" /> | ||
<script type="module" src={`/${devEntrypoint}`}></script> | ||
</> | ||
)} | ||
<script | ||
// We're hydrating the entire document. Our config differentiates between server and client, so it's necessary to suppress any hydration warnings here. TODO: Find a better workaround for this | ||
suppressHydrationWarning | ||
dangerouslySetInnerHTML={{ | ||
__html: config.isClient ? "" : `window.DATA = "$WINDOW_DATA"`, | ||
}} | ||
></script> | ||
{!!entryPoint && <script type="module" src={`/${entryPoint.file}`}></script>} | ||
{css.map((file) => ( | ||
<link rel="stylesheet" href={`/${file}`} key={file} /> | ||
))} | ||
{importedChunks.map((chunk) => ( | ||
<link rel="modulepreload" href={`/${chunk.file}`} key={chunk.file}></link> | ||
))} | ||
<div id="root">{children}</div> | ||
</body> | ||
</html> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.