mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-20 01:57:52 +02:00
refactor: remove unnecessary undefined & use optional chain (#11192)
This commit is contained in:
parent
abd04a2b71
commit
5d858f5e66
3 changed files with 4 additions and 5 deletions
|
@ -480,7 +480,7 @@ Available document ids are:
|
||||||
|
|
||||||
export function toDocNavigationLink(
|
export function toDocNavigationLink(
|
||||||
doc: DocMetadataBase,
|
doc: DocMetadataBase,
|
||||||
options?: {sidebarItemLabel?: string | undefined},
|
options?: {sidebarItemLabel?: string},
|
||||||
): PropNavigationLink {
|
): PropNavigationLink {
|
||||||
const {
|
const {
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -86,7 +86,7 @@ export const bytesToSize = (bytes) => {
|
||||||
const detectWebpSupport = () => {
|
const detectWebpSupport = () => {
|
||||||
if (ssr) return false;
|
if (ssr) return false;
|
||||||
const elem = document.createElement('canvas');
|
const elem = document.createElement('canvas');
|
||||||
if (elem.getContext && elem.getContext('2d')) {
|
if (elem.getContext?.('2d')) {
|
||||||
// was able or not to get WebP representation
|
// was able or not to get WebP representation
|
||||||
return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
|
return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,8 +97,7 @@ const detectWebpSupport = () => {
|
||||||
|
|
||||||
export const supportsWebp = detectWebpSupport();
|
export const supportsWebp = detectWebpSupport();
|
||||||
|
|
||||||
const isWebp = (x) =>
|
const isWebp = (x) => x.format === 'webp' || x.src?.match(/\.webp($|\?.*)/i);
|
||||||
x.format === 'webp' || (x.src && x.src.match(/\.webp($|\?.*)/i));
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
export const selectSrc = ({srcSet, maxImageWidth, supportsWebp}) => {
|
export const selectSrc = ({srcSet, maxImageWidth, supportsWebp}) => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export type DocsVersionPersistence = 'localStorage' | 'none';
|
||||||
|
|
||||||
// TODO improve types, use unions
|
// TODO improve types, use unions
|
||||||
export type NavbarItem = {
|
export type NavbarItem = {
|
||||||
type?: string | undefined;
|
type?: string;
|
||||||
items?: NavbarItem[];
|
items?: NavbarItem[];
|
||||||
label?: string;
|
label?: string;
|
||||||
position?: 'left' | 'right';
|
position?: 'left' | 'right';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue