Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apify-docs-theme/src/theme/Logo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,27 @@ function LogoThemedImage({ logo, alt, imageClassName }) {
}
export default function Logo(props) {
const {
siteConfig: { title },
siteConfig: { title, url: siteUrl, baseUrl: baseUrlConfig },
} = useDocusaurusContext();
const {
navbar: { title: navbarTitle, logo },
} = useThemeConfig();
const { imageClassName, titleClassName, ...propsRest } = props;
const logoLink = useBaseUrl(logo?.href || '/');
const homeLink = useBaseUrl('/');

// When the logo href points to the site's own URL (e.g. https://docs.apify.com
// on the docs.apify.com site), use client-side routing instead of a full page
// navigation. This avoids redirect issues when the site is served behind a
// reverse proxy (nginx -> GitHub Pages) where the upstream URL can leak through.
const siteOrigin = siteUrl?.replace(/\/$/, '');
const isOwnSiteUrl = logo?.href && siteOrigin
&& (logo.href === siteOrigin || logo.href === `${siteOrigin}/`)
&& baseUrlConfig === '/';

const resolvedLink = isOwnSiteUrl ? homeLink : logoLink;
const isExternalLink = !isOwnSiteUrl && /^https?:\/\//.test(resolvedLink);

// If visible title is shown, fallback alt text should be
// an empty string to mark the logo as decorative.
const fallbackAlt = navbarTitle ? '' : title;
Expand All @@ -45,7 +59,7 @@ export default function Logo(props) {
const alt = logo?.alt ?? fallbackAlt;
return (
<Link
to={logoLink}
{...(isExternalLink ? { href: resolvedLink } : { to: resolvedLink })}
{...propsRest}
{...(logo?.target && { target: logo.target })}>
{logo && (
Expand Down
Loading