Skip to content

Commit

Permalink
Merge branch 'master' into slorber/add-to-team
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jul 28, 2020
2 parents 29295a9 + e1b2963 commit 00540fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion packages/docusaurus/src/client/exports/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {NavLink, Link as RRLink} from 'react-router-dom';
import isInternalUrl from './isInternalUrl';
import ExecutionEnvironment from './ExecutionEnvironment';
import {useLinksCollector} from '../LinksCollector';
import {useBaseUrlUtils} from './useBaseUrl';

declare global {
interface Window {
Expand All @@ -29,6 +30,13 @@ interface Props {
readonly 'data-noBrokenLinkCheck'?: boolean;
}

// TODO all this wouldn't be necessary if we used ReactRouter basename feature
// We don't automatically add base urls to all links,
// only the "safe" ones, starting with / (like /docs/introduction)
// this is because useBaseUrl() actually transforms relative links
// like "introduction" to "/baseUrl/introduction" => bad behavior to fix
const shouldAddBaseUrlAutomatically = (to: string) => to.startsWith('/');

function Link({
isNavLink,
to,
Expand All @@ -37,13 +45,27 @@ function Link({
'data-noBrokenLinkCheck': noBrokenLinkCheck,
...props
}: Props): JSX.Element {
const {withBaseUrl} = useBaseUrlUtils();
const linksCollector = useLinksCollector();

// IMPORTANT: using to or href should not change anything
// For example, MDX links will ALWAYS give us the href props
// Using one prop or the other should not be used to distinguish
// internal links (/docs/myDoc) from external links (https://github.com)
const targetLink = to || href;
const targetLinkUnprefixed = to || href;

function maybeAddBaseUrl(str: string) {
return shouldAddBaseUrlAutomatically(str)
? withBaseUrl(str)
: targetLinkUnprefixed;
}

// TODO we should use ReactRouter basename feature instead!
// Automatically apply base url in links that start with /
const targetLink =
typeof targetLinkUnprefixed !== 'undefined'
? maybeAddBaseUrl(targetLinkUnprefixed)
: undefined;

const isInternal = isInternalUrl(targetLink);
const preloaded = useRef(false);
Expand Down
2 changes: 1 addition & 1 deletion website/docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The `searchParameters` option used to be named `algoliaOptions` in Docusaurus v1

By default, DocSearch comes with a fine-tuned theme that was designed for accessibility, making sure that colors and contrasts respect standards.

Still, you can reuse the [Infima CSS variables](/docs/styling-layout/#styling-your-site-with-infima) from Docusaurus to style DocSearch by editing the `/src/css/custom.css` file.
Still, you can reuse the [Infima CSS variables](styling-layout#styling-your-site-with-infima) from Docusaurus to style DocSearch by editing the `/src/css/custom.css` file.

```css title="/src/css/custom.css"
html[data-theme='light'] .DocSearch {
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-2.0.0-alpha.59/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The `searchParameters` option used to be named `algoliaOptions` in Docusaurus v1

By default, DocSearch comes with a fine-tuned theme that was designed for accessibility, making sure that colors and contrasts respect standards.

Still, you can reuse the [Infima CSS variables](/docs/styling-layout/#styling-your-site-with-infima) from Docusaurus to style DocSearch by editing the `/src/css/custom.css` file.
Still, you can reuse the [Infima CSS variables](styling-layout#styling-your-site-with-infima) from Docusaurus to style DocSearch by editing the `/src/css/custom.css` file.

```css title="/src/css/custom.css"
html[data-theme='light'] .DocSearch {
Expand Down

0 comments on commit 00540fc

Please sign in to comment.