Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): allow specify custom link for logo #2253

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 18 additions & 5 deletions packages/docusaurus-theme-classic/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ function Navbar() {
[setTheme],
);

const logoUrl = useBaseUrl(logo.src);
const logoLink = logo.link || baseUrl;
const isExternalLogoLink = /http/.test(logoLink);
const logoLinkProps = isExternalLogoLink
? {
rel: 'noopener noreferrer',
target: '_blank',
}
: null;
const logoImageUrl = useBaseUrl(logo.src);

return (
<nav
ref={navbarRef}
Expand Down Expand Up @@ -107,9 +116,9 @@ function Navbar() {
/>
</svg>
</div>
<Link className="navbar__brand" to={baseUrl}>
<Link className="navbar__brand" to={logoLink} {...logoLinkProps}>
{logo != null && (
<img className="navbar__logo" src={logoUrl} alt={logo.alt} />
<img className="navbar__logo" src={logoImageUrl} alt={logo.alt} />
)}
{title != null && (
<strong
Expand Down Expand Up @@ -151,9 +160,13 @@ function Navbar() {
/>
<div className="navbar-sidebar">
<div className="navbar-sidebar__brand">
<Link className="navbar__brand" onClick={hideSidebar} to={baseUrl}>
<Link
className="navbar__brand"
onClick={hideSidebar}
to={logoLink}
{...logoLinkProps}>
{logo != null && (
<img className="navbar__logo" src={logoUrl} alt={logo.alt} />
<img className="navbar__logo" src={logoImageUrl} alt={logo.alt} />
)}
{title != null && <strong>{title}</strong>}
</Link>
Expand Down
3 changes: 2 additions & 1 deletion website/docs/theme-classic.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {

### Navbar Title & Logo

You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md).
You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md). Logo URL is set to base URL of your site by default. Although you can specify your own URL for the logo, if it is an external link, it will open in a new tab.

```js
// docusaurus.config.js
Expand All @@ -57,6 +57,7 @@ module.exports = {
logo: {
alt: 'Site Logo',
src: 'img/logo.svg',
link: 'https://v2.docusaurus.io/', // default to siteConfig.baseUrl
lex111 marked this conversation as resolved.
Show resolved Hide resolved
},
},
...
Expand Down