Skip to content

Commit 5ea1943

Browse files
committed
Use SVG sprite for IconExternalLink
1 parent 884f93e commit 5ea1943

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/docusaurus-theme-classic/src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getAnnouncementBarInlineScript,
1515
DataAttributeQueryStringInlineJavaScript,
1616
} from './inlineScripts';
17+
import {SvgSpriteSymbols} from './inlineSvgSprites';
1718
import type {LoadContext, Plugin} from '@docusaurus/types';
1819
import type {ThemeConfig} from '@docusaurus/theme-common';
1920
import type {Plugin as PostCssPlugin} from 'postcss';
@@ -121,6 +122,14 @@ export default function themeClassic(
121122
injectHtmlTags() {
122123
return {
123124
preBodyTags: [
125+
{
126+
tagName: 'svg',
127+
attributes: {
128+
xmlns: 'http://www.w3.org/2000/svg',
129+
style: 'display: none;',
130+
},
131+
innerHTML: SvgSpriteSymbols,
132+
},
124133
{
125134
tagName: 'script',
126135
innerHTML: `
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// For icons that are heavily repeated in the static html output
9+
// See also https://github.com/facebook/docusaurus/issues/5865
10+
export const SvgSpriteSymbols = `
11+
<symbol id="theme-svg-external-link" viewBox="0 0 24 24"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" /></symbol>
12+
`;

packages/docusaurus-theme-classic/src/theme/Icon/ExternalLink/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import type {Props} from '@theme/Icon/ExternalLink';
1010

1111
import styles from './styles.module.css';
1212

13+
// References symbol in docusaurus-theme-classic/src/inlineSvgSprites.ts
14+
// See why: https://github.com/facebook/docusaurus/issues/5865
15+
const svgSprite = '#theme-svg-external-link';
16+
1317
export default function IconExternalLink({
1418
width = 13.5,
1519
height = 13.5,
@@ -19,12 +23,8 @@ export default function IconExternalLink({
1923
width={width}
2024
height={height}
2125
aria-hidden="true"
22-
viewBox="0 0 24 24"
2326
className={styles.iconExternalLink}>
24-
<path
25-
fill="currentColor"
26-
d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"
27-
/>
27+
<use href={svgSprite} />
2828
</svg>
2929
);
3030
}

0 commit comments

Comments
 (0)