mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-11 23:32:30 +02:00
2 lines
No EOL
15 KiB
JavaScript
2 lines
No EOL
15 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["35611"],{55701:function(e,t,n){n.d(t,{Z:()=>r});let r={tabItem:"tabItem_pnkT"}},93195:function(e,t,n){n.d(t,{Z:()=>r});let r={tabList:"tabList_Qoir",tabItem:"tabItem_AQgk"}},5759:function(e,t,n){n.d(t,{Z:()=>r});let r={apiTable:"apiTable_e8hp"}},78769:function(e,t,n){n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>d,default:()=>f,frontMatter:()=>c,metadata:()=>r,toc:()=>h});var r=n(46543),i=n(85893),s=n(80980),a=n(4575),l=n(54636),o=n(7450);let c={sidebar_position:4,slug:"/api/plugins/@docusaurus/plugin-client-redirects"},d="\uD83D\uDCE6 plugin-client-redirects",u={},h=[{value:"Installation",id:"installation",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Types",id:"types",level:3},{value:"<code>RedirectRule</code>",id:"RedirectRule",level:4},{value:"<code>CreateRedirectsFn</code>",id:"CreateRedirectsFn",level:4},{value:"Example configuration",id:"ex-config",level:3}];function p(e){let t={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.header,{children:(0,i.jsx)(t.h1,{id:"-plugin-client-redirects",children:"\uD83D\uDCE6 plugin-client-redirects"})}),"\n","\n",(0,i.jsxs)(t.p,{children:["Docusaurus Plugin to generate ",(0,i.jsx)(t.strong,{children:"client-side redirects"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"This plugin will write additional HTML pages to your static site that redirect the user to your existing Docusaurus pages with JavaScript."}),"\n",(0,i.jsx)(t.admonition,{title:"production only",type:"warning",children:(0,i.jsxs)(t.p,{children:["This plugin is always inactive in development and ",(0,i.jsx)(t.strong,{children:"only active in production"})," because it works on the build output."]})}),"\n",(0,i.jsxs)(t.admonition,{type:"warning",children:[(0,i.jsx)(t.p,{children:"It is better to use server-side redirects whenever possible."}),(0,i.jsx)(t.p,{children:"Before using this plugin, you should look if your hosting provider doesn't offer this feature."})]}),"\n",(0,i.jsx)(t.h2,{id:"installation",children:"Installation"}),"\n",(0,i.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,i.jsx)(l.Z,{value:"npm",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"npm install --save @docusaurus/plugin-client-redirects\n"})})}),(0,i.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"yarn add @docusaurus/plugin-client-redirects\n"})})}),(0,i.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"pnpm add @docusaurus/plugin-client-redirects\n"})})}),(0,i.jsx)(l.Z,{value:"bun",label:"Bun",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"bun add @docusaurus/plugin-client-redirects\n"})})})]}),"\n",(0,i.jsx)(t.h2,{id:"configuration",children:"Configuration"}),"\n",(0,i.jsx)(t.p,{children:"Accepted fields:"}),"\n",(0,i.jsx)(o.Z,{children:(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{children:"Option"}),(0,i.jsx)(t.th,{children:"Type"}),(0,i.jsx)(t.th,{children:"Default"}),(0,i.jsx)(t.th,{children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"fromExtensions"})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"string[]"})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"[]"})}),(0,i.jsx)(t.td,{children:"The extensions to be removed from the route after redirecting."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"toExtensions"})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"string[]"})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"[]"})}),(0,i.jsx)(t.td,{children:"The extensions to be appended to the route after redirecting."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"redirects"})}),(0,i.jsx)(t.td,{children:(0,i.jsxs)("code",{children:[(0,i.jsx)(t.a,{href:"#RedirectRule",children:"RedirectRule"}),"[]"]})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"[]"})}),(0,i.jsx)(t.td,{children:"The list of redirect rules."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"createRedirects"})}),(0,i.jsx)(t.td,{children:(0,i.jsx)("code",{children:(0,i.jsx)(t.a,{href:"#CreateRedirectsFn",children:"CreateRedirectsFn"})})}),(0,i.jsx)(t.td,{children:(0,i.jsx)(t.code,{children:"undefined"})}),(0,i.jsx)(t.td,{children:"A callback to create a redirect rule. Docusaurus query this callback against every path it has created, and use its return value to output more paths."})]})]})]})}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["This plugin will also read the ",(0,i.jsx)(t.a,{href:"/docs/api/docusaurus-config#onDuplicateRoutes",children:(0,i.jsx)(t.code,{children:"siteConfig.onDuplicateRoutes"})})," config to adjust its logging level when multiple files will be emitted to the same location."]})}),"\n",(0,i.jsx)(t.h3,{id:"types",children:"Types"}),"\n",(0,i.jsx)(t.h4,{id:"RedirectRule",children:(0,i.jsx)(t.code,{children:"RedirectRule"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"type RedirectRule = {\n to: string;\n from: string | string[];\n};\n"})}),"\n",(0,i.jsxs)(t.admonition,{type:"note",children:[(0,i.jsxs)(t.p,{children:['The idea of "from" and "to" is central in this plugin. "From" means a path that you want to ',(0,i.jsx)(t.em,{children:"create"}),', i.e. an extra HTML file that will be written; "to" means a path to want to redirect ',(0,i.jsx)(t.em,{children:"to"}),", usually a route that Docusaurus already knows about."]}),(0,i.jsx)(t.p,{children:'This is why you can have multiple "from" for the same "to": we will create multiple HTML files that all redirect to the same destination. On the other hand, one "from" can never have more than one "to": the written HTML file needs to have a determinate destination.'})]}),"\n",(0,i.jsx)(t.h4,{id:"CreateRedirectsFn",children:(0,i.jsx)(t.code,{children:"CreateRedirectsFn"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:'// The parameter `path` is a route that Docusaurus has already created. It can\n// be seen as the "to", and your return value is the "from". Returning a falsy\n// value will not create any redirect pages for this particular path.\ntype CreateRedirectsFn = (path: string) => string[] | string | null | undefined;\n'})}),"\n",(0,i.jsx)(t.h3,{id:"ex-config",children:"Example configuration"}),"\n",(0,i.jsx)(t.p,{children:"Here's an example configuration:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="docusaurus.config.js"',children:"export default {\n plugins: [\n [\n '@docusaurus/plugin-client-redirects',\n // highlight-start\n {\n fromExtensions: ['html', 'htm'], // /myPage.html -> /myPage\n toExtensions: ['exe', 'zip'], // /myAsset -> /myAsset.zip (if latter exists)\n redirects: [\n // /docs/oldDoc -> /docs/newDoc\n {\n to: '/docs/newDoc',\n from: '/docs/oldDoc',\n },\n // Redirect from multiple old paths to the new path\n {\n to: '/docs/newDoc2',\n from: ['/docs/oldDocFrom2019', '/docs/legacyDocFrom2016'],\n },\n ],\n createRedirects(existingPath) {\n if (existingPath.includes('/community')) {\n // Redirect from /docs/team/X to /community/X and /docs/support/X to /community/X\n return [\n existingPath.replace('/community', '/docs/team'),\n existingPath.replace('/community', '/docs/support'),\n ];\n }\n return undefined; // Return a falsy value: no redirect created\n },\n },\n // highlight-end\n ],\n ],\n};\n"})})]})}function f(e={}){let{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},54636:function(e,t,n){n.d(t,{Z:()=>a});var r=n(85893);n(67294);var i=n(90496),s=n(55701);function a(e){let{children:t,hidden:n,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,i.Z)(s.Z.tabItem,a),hidden:n,children:t})}},4575:function(e,t,n){n.d(t,{Z:()=>p});var r=n(85893),i=n(67294),s=n(90496),a=n(54947),l=n(30623),o=n(71607),c=n(93195);function d(e){let{className:t,block:n,selectedValue:i,selectValue:l,tabValues:o}=e,d=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.o5)(),h=e=>{let t=e.currentTarget,n=o[d.indexOf(t)].value;n!==i&&(u(t),l(n))},p=e=>{let t=null;switch(e.key){case"Enter":h(e);break;case"ArrowRight":{let n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{let n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1]}}t?.focus()};return(0,r.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},t),children:o.map(e=>{let{value:t,label:n,attributes:a}=e;return(0,r.jsx)("li",{role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,ref:e=>{d.push(e)},onKeyDown:p,onClick:h,...a,className:(0,s.Z)("tabs__item",c.Z.tabItem,a?.className,{"tabs__item--active":i===t}),children:n??t},t)})})}function u(e){let{lazy:t,children:n,selectedValue:a}=e,l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){let e=l.find(e=>e.props.value===a);return e?(0,i.cloneElement)(e,{className:(0,s.Z)("margin-top--md",e.props.className)}):null}return(0,r.jsx)("div",{className:"margin-top--md",children:l.map((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))})}function h(e){let t=(0,l.Y)(e);return(0,r.jsxs)("div",{className:(0,s.Z)("tabs-container",c.Z.tabList),children:[(0,r.jsx)(d,{...t,...e}),(0,r.jsx)(u,{...t,...e})]})}function p(e){let t=(0,o.Z)();return(0,r.jsx)(h,{...e,children:(0,l.h)(e.children)},String(t))}},30623:function(e,t,n){n.d(t,{Y:()=>u,h:()=>c});var r=n(67294),i=n(3620),s=n(844),a=n(97486),l=n(32263),o=n(16971);function c(e){return r.Children.toArray(e).filter(e=>"\n"!==e).map(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){let{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function d(e){let{value:t,tabValues:n}=e;return n.some(e=>e.value===t)}function u(e){let{defaultValue:t,queryString:n=!1,groupId:u}=e,h=function(e){let{values:t,children:n}=e;return(0,r.useMemo)(()=>{let e=t??c(n).map(e=>{let{props:{value:t,label:n,attributes:r,default:i}}=e;return{value:t,label:n,attributes:r,default:i}}),r=(0,l.lx)(e,(e,t)=>e.value===t.value);if(r.length>0)throw Error(`Docusaurus error: Duplicate values "${r.map(e=>e.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[t,n])}(e),[p,f]=(0,r.useState)(()=>(function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(t){if(!d({value:t,tabValues:n}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}let r=n.find(e=>e.default)??n[0];if(!r)throw Error("Unexpected error: 0 tabValues");return r.value})({defaultValue:t,tabValues:h})),[m,x]=function(e){let{queryString:t=!1,groupId:n}=e,s=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,a._X)(l),(0,r.useCallback)(e=>{if(!l)return;let t=new URLSearchParams(s.location.search);t.set(l,e),s.replace({...s.location,search:t.toString()})},[l,s])]}({queryString:n,groupId:u}),[g,j]=function(e){let{groupId:t}=e,n=t?`docusaurus.tab.${t}`:null,[i,s]=(0,o.Nk)(n);return[i,(0,r.useCallback)(e=>{n&&s.set(e)},[n,s])]}({groupId:u}),b=(()=>{let e=m??g;return d({value:e,tabValues:h})?e:null})();return(0,s.Z)(()=>{b&&f(b)},[b]),{selectedValue:p,selectValue:(0,r.useCallback)(e=>{if(!d({value:e,tabValues:h}))throw Error(`Can't select invalid tab value=${e}`);f(e),x(e),j(e)},[x,j,h]),tabValues:h}}},7450:function(e,t,n){n.d(t,{Z:()=>c});var r=n(85893),i=n(67294),s=n(30576),a=n(3620),l=n(5759);let o=i.forwardRef(function(e,t){let{name:n,children:l}=e,o=function(e){let t=e;for(;(0,i.isValidElement)(t);)[t]=i.Children.toArray(t.props.children);if("string"!=typeof t)throw Error(`Could not extract APITable row name from JSX tree:
|
|
${JSON.stringify(e,null,2)}`);return t}(l),c=n?`${n}-${o}`:o,d=`#${c}`,u=(0,a.k6)();return(0,s.Z)().collectAnchor(c),(0,r.jsx)("tr",{id:c,tabIndex:0,ref:u.location.hash===d?t:void 0,onClick:e=>{let t="TD"===e.target.tagName.toUpperCase(),n=!!window.getSelection()?.toString();t&&!n&&u.push(d)},onKeyDown:e=>{"Enter"===e.key&&u.push(d)},children:l.props.children})});function c(e){let{children:t,name:n}=e;if("table"!==t.type)throw Error("Bad usage of APITable component.\nIt is probably that your Markdown table is malformed.\nMake sure to double-check you have the appropriate number of columns for each table row.");let[s,a]=i.Children.toArray(t.props.children),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{c.current?.focus()},[c]);let d=i.Children.map(a.props.children,e=>(0,r.jsx)(o,{name:n,ref:c,children:e}));return(0,r.jsxs)("table",{className:l.Z.apiTable,children:[s,(0,r.jsx)("tbody",{children:d})]})}},80980:function(e,t,n){n.d(t,{Z:()=>l,a:()=>a});var r=n(67294);let i={},s=r.createContext(i);function a(e){let t=r.useContext(s);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),r.createElement(s.Provider,{value:t},e.children)}},46543:function(e){e.exports=JSON.parse('{"id":"api/plugins/plugin-client-redirects","title":"\uD83D\uDCE6 plugin-client-redirects","description":"Docusaurus Plugin to generate client-side redirects.","source":"@site/docs/api/plugins/plugin-client-redirects.mdx","sourceDirName":"api/plugins","slug":"/api/plugins/@docusaurus/plugin-client-redirects","permalink":"/docs/api/plugins/@docusaurus/plugin-client-redirects","draft":false,"unlisted":false,"editUrl":"https://github.com/facebook/docusaurus/edit/main/website/docs/api/plugins/plugin-client-redirects.mdx","tags":[],"version":"current","lastUpdatedBy":"S\xe9bastien Lorber","lastUpdatedAt":1748882647000,"sidebarPosition":4,"frontMatter":{"sidebar_position":4,"slug":"/api/plugins/@docusaurus/plugin-client-redirects"},"sidebar":"api","previous":{"title":"\uD83D\uDCE6 plugin-content-pages","permalink":"/docs/api/plugins/@docusaurus/plugin-content-pages"},"next":{"title":"\uD83D\uDCE6 plugin-debug","permalink":"/docs/api/plugins/@docusaurus/plugin-debug"}}')}}]); |