๐ฆ plugin-client-redirects
Docusaurus Plugin to generate client-side redirects.
ํ๋ฌ๊ทธ์ธ์์๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ง๋ ๋ํ์ฌ์ฐ๋ฃจ์ค ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธํ ์ ์๋๋ก ์ฌ๋ฌ๋ถ์ ์ ์ ์ธ ์ฌ์ดํธ์ HTML ํ์ด์ง๋ฅผ ์ถ๊ฐ๋ก ๋ง๋ญ๋๋ค.
This plugin is always inactive in development and only active in production because it works on the build output.
๊ฐ๋ฅํ๋ค๋ฉด ์๋ฒ ์ธก ๋ฆฌ๋ค์ด๋ ํธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๊ธฐ ์ ์ ์ฌ๋ฌ๋ถ์ ํธ์คํธ ์๋น์ค ์ ์ฒด๊ฒ ์ด ๊ธฐ๋ฅ์ ์ง์ํ์ง ์๋์ง ๋จผ์ ํ์ธํด๋ณด์ธ์.
Installationโ
- npm
- Yarn
- pnpm
npm install --save @docusaurus/plugin-client-redirects
yarn add @docusaurus/plugin-client-redirects
pnpm add @docusaurus/plugin-client-redirects
Configurationโ
์ค์ ํ ์ ์๋ ํ๋
์ต์ | ํ์ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
fromExtensions | string[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ํ ๊ฒฝ๋ก์์ ์ ๊ฑฐํ ํ์ฅ์์ ๋๋ค. |
toExtensions | string[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ํ ๊ฒฝ๋ก์ ์ถ๊ฐํ ํ์ฅ์์ ๋๋ค. |
redirects | RedirectRule[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ๊ท์น ๋ชฉ๋ก์ ๋๋ค. |
createRedirects | CreateRedirectsFn | undefined | ๋ฆฌ๋ค์ด๋ ํธ ๊ท์น์ ๋ง๋ค๊ธฐ ์ํ ์ฝ๋ฐฑ์ ๋๋ค. ๋ํ์ฌ์ฐ๋ฃจ์ค๋ ์์ฑํ ๋ชจ๋ ๊ฒฝ๋ก์ ๋ํด ์ฝ๋ฐฑ์ ์์ฒญํ๊ณ ๋ฐํ๊ฐ์ ์ฌ์ฉํด ๋ ๋ง์ ๊ฒฝ๋ก๋ฅผ ์ถ๋ ฅํฉ๋๋ค. |
This plugin will also read the siteConfig.onDuplicateRoutes
config to adjust its logging level when multiple files will be emitted to the same location.
Typesโ
RedirectRule
โ
type RedirectRule = {
to: string;
from: string | string[];
};
"from"๊ณผ "to"์ ๊ฐ๋ ์ ์ด ํ๋ฌ๊ทธ์ธ์ ํต์ฌ์ ๋๋ค. "From" means a path that you want to create, i.e. an extra HTML file that will be written; "to" means a path to want to redirect to, usually a route that Docusaurus already knows about.
์ด ๋๋ฌธ์ ๊ฐ์ "to"์ ๋ํด ์ฌ๋ฌ ๊ฐ์ "from"์ ๊ฐ์ง ์ ์์ต๋๋ค. ๋ชจ๋ ๊ฐ์ ๋ชฉ์ ์ง๋ก ๋ฆฌ๋ค์ด๋ ํธ๋๋ ์ฌ๋ฌ ๊ฐ์ HTML ํ์ผ์ ์์ฑํฉ๋๋ค. ๋ฐ๋ฉด์ "from"์ ํ๋๋ณด๋ค ๋ง์ "to"๋ฅผ ๊ฐ์ง ์ ์์ต๋๋ค. ์์ฑ๋ HTML ํ์ผ์ ๋ช ํํ ๋ชฉ์ ์ง๊ฐ ์์ด์ผ ํฉ๋๋ค.
CreateRedirectsFn
โ
// The parameter `path` is a route that Docusaurus has already created. It can
// be seen as the "to", and your return value is the "from". Returning a falsy
// value will not create any redirect pages for this particular path.
type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;
Example configurationโ
๋ค์์ ์ค์ ์์์ ๋๋ค:
export default {
plugins: [
[
'@docusaurus/plugin-client-redirects',
{
fromExtensions: ['html', 'htm'], // /myPage.html -> /myPage
toExtensions: ['exe', 'zip'], // /myAsset -> /myAsset.zip (if latter exists)
redirects: [
// /docs/oldDoc -> /docs/newDoc
{
to: '/docs/newDoc',
from: '/docs/oldDoc',
},
// Redirect from multiple old paths to the new path
{
to: '/docs/newDoc2',
from: ['/docs/oldDocFrom2019', '/docs/legacyDocFrom2016'],
},
],
createRedirects(existingPath) {
if (existingPath.includes('/community')) {
// Redirect from /docs/team/X to /community/X and /docs/support/X to /community/X
return [
existingPath.replace('/community', '/docs/team'),
existingPath.replace('/community', '/docs/support'),
];
}
return undefined; // Return a falsy value: no redirect created
},
},
],
],
};