Skip to content

Commit

Permalink
refactor(v2): inline unnecessary method
Browse files Browse the repository at this point in the history
  • Loading branch information
teikjun committed Jun 29, 2020
1 parent 1e54f13 commit 727ebea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {PluginContext, UserPluginOptions} from '../types';
import collectRedirects from '../collectRedirects';
import normalizePluginOptions from '../normalizePluginOptions';
import {removeTrailingSlash} from '@docusaurus/utils';
import {trimBaseUrls} from '..';

function createTestPluginContext(
options?: UserPluginOptions,
Expand All @@ -24,11 +23,6 @@ function createTestPluginContext(
}

describe('collectRedirects', () => {
test('should trim baseUrl properly to get correct relativeRoutesPath', () => {
const routePaths = ['/myBaseUrl/', '/myBaseUrl/path'];
expect(trimBaseUrls(routePaths, '/myBaseUrl/')).toEqual(['/', '/path']);
});

test('should collect no redirect for undefined config', () => {
expect(
collectRedirects(createTestPluginContext(undefined, ['/', '/path'])),
Expand Down
8 changes: 3 additions & 5 deletions packages/docusaurus-plugin-client-redirects/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default function pluginClientRedirectsPages(
name: 'docusaurus-plugin-client-redirects',
async postBuild(props: Props) {
const pluginContext: PluginContext = {
relativeRoutesPaths: trimBaseUrls(props.routesPaths, props.baseUrl),
relativeRoutesPaths: props.routesPaths.map(
(path) => `/${removePrefix(path, props.baseUrl)}`,
),
baseUrl: props.baseUrl,
outDir: props.outDir,
options,
Expand All @@ -44,7 +46,3 @@ export default function pluginClientRedirectsPages(
},
};
}

export function trimBaseUrls(paths: string[], baseUrl: string): string[] {
return paths.map((path) => `/${removePrefix(path, baseUrl)}`);
}

0 comments on commit 727ebea

Please sign in to comment.