Skip to content

Commit

Permalink
⚡ Improve footer logo when no dark src
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Sep 26, 2023
1 parent 72e5413 commit b880e92
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
47 changes: 31 additions & 16 deletions packages/theme-nonepress/src/theme/Footer/Logo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import React from "react";

import Link from "@docusaurus/Link";
import { useBaseUrlUtils } from "@docusaurus/useBaseUrl";
import useBaseUrl from "@docusaurus/useBaseUrl";

import type { Props } from "@theme/Footer/Logo";
import ThemedImage from "@theme/ThemedImage";

function LogoImage({ logo }: Props) {
const { withBaseUrl } = useBaseUrlUtils();
const sources = {
light: withBaseUrl(logo.src),
dark: withBaseUrl(logo.srcDark ?? logo.src),
};
return (
<ThemedImage
className={logo.className}
alt={logo.alt}
sources={sources}
width={logo.width}
height={logo.height}
style={logo.style}
/>
);
const lightSrc = useBaseUrl(logo.src);
const darkSrc = useBaseUrl(logo.srcDark ?? logo.src);

if (logo.srcDark == null) {
return (
<img
className={logo.className}
src={lightSrc}
alt={logo.alt}
width={logo.width}
height={logo.height}
style={logo.style}
/>
);
} else {
const sources = {
light: lightSrc,
dark: darkSrc,
};
return (
<ThemedImage
className={logo.className}
alt={logo.alt}
sources={sources}
width={logo.width}
height={logo.height}
style={logo.style}
/>
);
}
}

export default function FooterLogo({ logo }: Props): JSX.Element {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-nonepress/src/theme/Logo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function LogoThemedImage({
imageClassName?: string;
}): JSX.Element {
const lightSrc = useBaseUrl(logo.src);
const darkSrc = useBaseUrl(logo.srcDark || logo.src);
const darkSrc = useBaseUrl(logo.srcDark ?? logo.src);

// Is this extra div really necessary?
// introduced in https://github.com/facebook/docusaurus/pull/5666
Expand Down

0 comments on commit b880e92

Please sign in to comment.