mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-07 20:07:59 +02:00
refactor(utils): remove duplicated function
This commit is contained in:
parent
8d115a9e0d
commit
50347c77e7
14 changed files with 18 additions and 25 deletions
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {addTrailingSlash, removeTrailingSlash} from '@docusaurus/utils';
|
import {removeTrailingSlash} from '@docusaurus/utils';
|
||||||
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
import {applyTrailingSlash, addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import {
|
import {
|
||||||
createFromExtensionsRedirects,
|
createFromExtensionsRedirects,
|
||||||
createToExtensionsRedirects,
|
createToExtensionsRedirects,
|
||||||
|
|
|
@ -5,11 +5,8 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {removeSuffix, removeTrailingSlash} from '@docusaurus/utils';
|
||||||
addTrailingSlash,
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
removeSuffix,
|
|
||||||
removeTrailingSlash,
|
|
||||||
} from '@docusaurus/utils';
|
|
||||||
import type {RedirectItem} from './types';
|
import type {RedirectItem} from './types';
|
||||||
|
|
||||||
const ExtensionAdditionalMessage =
|
const ExtensionAdditionalMessage =
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
"@docusaurus/module-type-aliases": "3.0.0",
|
"@docusaurus/module-type-aliases": "3.0.0",
|
||||||
"@docusaurus/types": "3.0.0",
|
"@docusaurus/types": "3.0.0",
|
||||||
"@docusaurus/utils": "3.0.0",
|
"@docusaurus/utils": "3.0.0",
|
||||||
|
"@docusaurus/utils-common": "3.0.0",
|
||||||
"@docusaurus/utils-validation": "3.0.0",
|
"@docusaurus/utils-validation": "3.0.0",
|
||||||
"@types/react-router-config": "^5.0.7",
|
"@types/react-router-config": "^5.0.7",
|
||||||
"combine-promises": "^1.1.0",
|
"combine-promises": "^1.1.0",
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {addTrailingSlash} from '@docusaurus/utils';
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
||||||
import type {
|
import type {
|
||||||
SidebarItemDoc,
|
SidebarItemDoc,
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addLeadingSlash,
|
addLeadingSlash,
|
||||||
addTrailingSlash,
|
|
||||||
isValidPathname,
|
isValidPathname,
|
||||||
resolvePathname,
|
resolvePathname,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import {
|
import {
|
||||||
DefaultNumberPrefixParser,
|
DefaultNumberPrefixParser,
|
||||||
stripPathNumberPrefixes,
|
stripPathNumberPrefixes,
|
||||||
|
|
|
@ -12,6 +12,10 @@ export type ApplyTrailingSlashParams = Pick<
|
||||||
'trailingSlash' | 'baseUrl'
|
'trailingSlash' | 'baseUrl'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export function addTrailingSlash(str: string): string {
|
||||||
|
return str.endsWith('/') ? str : `${str}/`;
|
||||||
|
}
|
||||||
|
|
||||||
// Trailing slash handling depends in some site configuration options
|
// Trailing slash handling depends in some site configuration options
|
||||||
export default function applyTrailingSlash(
|
export default function applyTrailingSlash(
|
||||||
path: string,
|
path: string,
|
||||||
|
@ -24,10 +28,6 @@ export default function applyTrailingSlash(
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deduplicate: also present in @docusaurus/utils
|
|
||||||
function addTrailingSlash(str: string): string {
|
|
||||||
return str.endsWith('/') ? str : `${str}/`;
|
|
||||||
}
|
|
||||||
function removeTrailingSlash(str: string): string {
|
function removeTrailingSlash(str: string): string {
|
||||||
return str.endsWith('/') ? str.slice(0, -1) : str;
|
return str.endsWith('/') ? str.slice(0, -1) : str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ export const blogPostContainerID = '__blog-post-container';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
default as applyTrailingSlash,
|
default as applyTrailingSlash,
|
||||||
|
addTrailingSlash,
|
||||||
type ApplyTrailingSlashParams,
|
type ApplyTrailingSlashParams,
|
||||||
} from './applyTrailingSlash';
|
} from './applyTrailingSlash';
|
||||||
export {getErrorCausalChain} from './errorUtils';
|
export {getErrorCausalChain} from './errorUtils';
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docusaurus/logger": "3.0.0",
|
"@docusaurus/logger": "3.0.0",
|
||||||
|
"@docusaurus/utils-common": "3.0.0",
|
||||||
"@svgr/webpack": "^6.5.1",
|
"@svgr/webpack": "^6.5.1",
|
||||||
"escape-string-regexp": "^4.0.0",
|
"escape-string-regexp": "^4.0.0",
|
||||||
"file-loader": "^6.2.0",
|
"file-loader": "^6.2.0",
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import {
|
import {
|
||||||
normalizeUrl,
|
normalizeUrl,
|
||||||
getEditUrl,
|
getEditUrl,
|
||||||
fileToPath,
|
fileToPath,
|
||||||
isValidPathname,
|
isValidPathname,
|
||||||
addTrailingSlash,
|
|
||||||
addLeadingSlash,
|
addLeadingSlash,
|
||||||
removeTrailingSlash,
|
removeTrailingSlash,
|
||||||
resolvePathname,
|
resolvePathname,
|
||||||
|
|
|
@ -51,7 +51,6 @@ export {
|
||||||
parseURLPath,
|
parseURLPath,
|
||||||
serializeURLPath,
|
serializeURLPath,
|
||||||
addLeadingSlash,
|
addLeadingSlash,
|
||||||
addTrailingSlash,
|
|
||||||
removeTrailingSlash,
|
removeTrailingSlash,
|
||||||
hasSSHProtocol,
|
hasSSHProtocol,
|
||||||
buildHttpsUrl,
|
buildHttpsUrl,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import resolvePathnameUnsafe from 'resolve-pathname';
|
import resolvePathnameUnsafe from 'resolve-pathname';
|
||||||
import {addPrefix, addSuffix, removeSuffix} from './jsUtils';
|
import {addPrefix, removeSuffix} from './jsUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
||||||
|
@ -237,12 +237,6 @@ export function addLeadingSlash(str: string): string {
|
||||||
return addPrefix(str, '/');
|
return addPrefix(str, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
||||||
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
||||||
export function addTrailingSlash(str: string): string {
|
|
||||||
return addSuffix(str, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Removes the trailing slash from `str`. */
|
/** Removes the trailing slash from `str`. */
|
||||||
export function removeTrailingSlash(str: string): string {
|
export function removeTrailingSlash(str: string): string {
|
||||||
return removeSuffix(str, '/');
|
return removeSuffix(str, '/');
|
||||||
|
|
|
@ -69,8 +69,8 @@
|
||||||
"del": "^6.1.1",
|
"del": "^6.1.1",
|
||||||
"detect-port": "^1.5.1",
|
"detect-port": "^1.5.1",
|
||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
"eval": "^0.1.8",
|
|
||||||
"eta": "^2.2.0",
|
"eta": "^2.2.0",
|
||||||
|
"eval": "^0.1.8",
|
||||||
"file-loader": "^6.2.0",
|
"file-loader": "^6.2.0",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.1.1",
|
||||||
"html-minifier-terser": "^7.2.0",
|
"html-minifier-terser": "^7.2.0",
|
||||||
|
|
|
@ -9,12 +9,12 @@ import _ from 'lodash';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {matchRoutes as reactRouterMatchRoutes} from 'react-router-config';
|
import {matchRoutes as reactRouterMatchRoutes} from 'react-router-config';
|
||||||
import {
|
import {
|
||||||
addTrailingSlash,
|
|
||||||
parseURLPath,
|
parseURLPath,
|
||||||
removeTrailingSlash,
|
removeTrailingSlash,
|
||||||
serializeURLPath,
|
serializeURLPath,
|
||||||
type URLPath,
|
type URLPath,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import {getAllFinalRoutes} from './routes';
|
import {getAllFinalRoutes} from './routes';
|
||||||
import type {RouteConfig, ReportingSeverity} from '@docusaurus/types';
|
import type {RouteConfig, ReportingSeverity} from '@docusaurus/types';
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ import {
|
||||||
DEFAULT_STATIC_DIR_NAME,
|
DEFAULT_STATIC_DIR_NAME,
|
||||||
DEFAULT_I18N_DIR_NAME,
|
DEFAULT_I18N_DIR_NAME,
|
||||||
addLeadingSlash,
|
addLeadingSlash,
|
||||||
addTrailingSlash,
|
|
||||||
removeTrailingSlash,
|
removeTrailingSlash,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
import {Joi, printWarning} from '@docusaurus/utils-validation';
|
import {Joi, printWarning} from '@docusaurus/utils-validation';
|
||||||
|
import {addTrailingSlash} from '@docusaurus/utils-common';
|
||||||
import type {
|
import type {
|
||||||
DocusaurusConfig,
|
DocusaurusConfig,
|
||||||
I18nConfig,
|
I18nConfig,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue