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): automatically add base url to logo link #2818

Merged
merged 2 commits into from
May 27, 2020

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented May 27, 2020

Motivation

This is a request from Discord chat, I think we should take care to add the base url to the logo link automatically, this is the expected behavior I suppose.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Set document id to navbar.logo.href and make sure base url has been added to it.

By default a slash (/) will be added (standard base url).

Nevertheless, this is BC, because previously users had to manually specify the base url (in the case of using non-standard base url)

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added pr: new feature This PR adds a new API or behavior. pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. labels May 27, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 27, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented May 27, 2020

Deploy preview for docusaurus-2 ready!

Built with commit ca2f8e3

https://deploy-preview-2818--docusaurus-2.netlify.app

@@ -15,7 +15,7 @@ const useLogo = () => {
siteConfig: {baseUrl, themeConfig: {navbar: {logo = {}} = {}}} = {},
} = useDocusaurusContext();
const {isDarkTheme} = useThemeContext();
const logoLink = logo.href || baseUrl;
const logoLink = useBaseUrl(logo.href || baseUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the useBaseUrl(baseUrl) case result in duplication in the case of non-/ baseUrls?

Copy link
Contributor

@yangshun yangshun May 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just be wrapping around logo.href?

const logoLink = logo.href ? useBaseUrl(logo.href) : baseUrl;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed.
I set / as the default value which will be processed by useBaseUrl

if (url.startsWith('/')) {
return baseUrl + url.slice(1);
}

@yangshun yangshun merged commit 90db536 into master May 27, 2020
@lex111 lex111 deleted the lex111/base-url-to-logo branch May 27, 2020 14:29
@lex111 lex111 added this to the v2.0.0-alpha.56 milestone May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants