Skip to content

Commit 73c7f46

Browse files
committed
#60: Enable to customize favicon in Next.js
1 parent 055c9f7 commit 73c7f46

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/next-appdir/DsfrHead.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,26 @@ export type DsfrHeadProps = {
4141
* @default "react-dsfr"
4242
*/
4343
trustedTypesPolicyName?: string;
44+
45+
/**
46+
* Disable Marianne favicon import.
47+
* Enable this option if you want to use your own favicon.
48+
*
49+
* @default false
50+
*/
51+
doDisableFavicon?: boolean;
4452
};
4553

4654
const isProduction = process.env.NODE_ENV !== "development";
4755

4856
export function DsfrHead(props: DsfrHeadProps) {
49-
const { preloadFonts = [], Link, nonce, trustedTypesPolicyName = "react-dsfr" } = props;
57+
const {
58+
preloadFonts = [],
59+
Link,
60+
nonce,
61+
trustedTypesPolicyName = "react-dsfr",
62+
doDisableFavicon = false
63+
} = props;
5064

5165
assert(nonce !== "", "nonce cannot be an empty string");
5266

@@ -73,9 +87,13 @@ export function DsfrHead(props: DsfrHeadProps) {
7387
crossOrigin="anonymous"
7488
/>
7589
))}
76-
<link rel="apple-touch-icon" href={getAssetUrl(AppleTouchIcon)} />
77-
<link rel="icon" href={getAssetUrl(FaviconSvg)} type="image/svg+xml" />
78-
<link rel="shortcut icon" href={getAssetUrl(FaviconIco)} type="image/x-icon" />
90+
{!doDisableFavicon && (
91+
<>
92+
<link rel="apple-touch-icon" href={getAssetUrl(AppleTouchIcon)} />
93+
<link rel="icon" href={getAssetUrl(FaviconSvg)} type="image/svg+xml" />
94+
<link rel="shortcut icon" href={getAssetUrl(FaviconIco)} type="image/x-icon" />
95+
</>
96+
)}
7997
<script
8098
suppressHydrationWarning
8199
nonce={nonce}

src/next-pagesdir.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export type CreateNextDsfrIntegrationApiParams = {
5858
* @default "react-dsfr"
5959
*/
6060
trustedTypesPolicyName?: string;
61+
/**
62+
* Disable Marianne favicon import.
63+
* Enable this option if you want to use your own favicon.
64+
*
65+
* @default false
66+
*/
67+
doDisableFavicon?: boolean;
6168
};
6269

6370
function readIsDarkInCookie(cookie: string) {
@@ -106,7 +113,8 @@ export function createNextDsfrIntegrationApi(
106113
preloadFonts = [],
107114
doPersistDarkModePreferenceWithCookie = false,
108115
useLang,
109-
trustedTypesPolicyName = "react-dsfr"
116+
trustedTypesPolicyName = "react-dsfr",
117+
doDisableFavicon = false
110118
} = params;
111119

112120
let isAfterFirstEffect = false;
@@ -176,13 +184,21 @@ export function createNextDsfrIntegrationApi(
176184
crossOrigin="anonymous"
177185
/>
178186
))}
179-
<link rel="apple-touch-icon" href={getAssetUrl(AppleTouchIcon)} />
180-
<link rel="icon" href={getAssetUrl(FaviconSvg)} type="image/svg+xml" />
181-
<link
182-
rel="shortcut icon"
183-
href={getAssetUrl(FaviconIco)}
184-
type="image/x-icon"
185-
/>
187+
{!doDisableFavicon && (
188+
<>
189+
<link rel="apple-touch-icon" href={getAssetUrl(AppleTouchIcon)} />
190+
<link
191+
rel="icon"
192+
href={getAssetUrl(FaviconSvg)}
193+
type="image/svg+xml"
194+
/>
195+
<link
196+
rel="shortcut icon"
197+
href={getAssetUrl(FaviconIco)}
198+
type="image/x-icon"
199+
/>
200+
</>
201+
)}
186202
{!isBrowser && ( //NOTE: On browser we handle this manually
187203
<>
188204
<style id={rootColorSchemeStyleTagId}>{`:root { color-scheme: ${

0 commit comments

Comments
 (0)