docusaurus/assets/js/228a014d.54fea13f.js
2024-10-22 10:43:30 +00:00

1 line
No EOL
19 KiB
JavaScript

"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["35611"],{36287:function(e,t,r){r.r(t),r.d(t,{metadata:()=>n,contentTitle:()=>u,default:()=>f,assets:()=>d,toc:()=>h,frontMatter:()=>c});var n=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":1729593657000,"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"}}'),i=r("24246"),a=r("80980"),o=r("15398"),l=r("58636"),s=r("32240");let c={sidebar_position:4,slug:"/api/plugins/@docusaurus/plugin-client-redirects"},u="\uD83D\uDCE6 plugin-client-redirects",d={},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,a.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)(o.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"})})})]}),"\n",(0,i.jsx)(t.h2,{id:"configuration",children:"Configuration"}),"\n",(0,i.jsx)(t.p,{children:"Accepted fields:"}),"\n",(0,i.jsx)(s.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,a.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},58636:function(e,t,r){r.d(t,{Z:()=>o});var n=r("24246");r("27378");var i=r("90496");let a="tabItem_pnkT";function o(e){var t=e.children,r=e.hidden,o=e.className;return(0,n.jsx)("div",{role:"tabpanel",className:(0,i.Z)(a,o),hidden:r,children:t})}},15398:function(e,t,r){r.d(t,{Z:()=>S});var n=r("24246"),i=r("27378"),a=r("90496"),o=r("54947"),l=r("3620"),s=r("844"),c=r("97486"),u=r("32263"),d=r("16971");function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var a=[],o=!0,l=!1;try{for(i=i.call(e);!(o=(r=i.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){l=!0,n=e}finally{try{!o&&null!=i.return&&i.return()}finally{if(l)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return h(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e){var t,r;return null!==(r=null===(t=i.Children.toArray(e).filter(function(e){return"\n"!==e}).map(function(e){var t,r;if(!e||(0,i.isValidElement)(e)&&(t=e.props)&&(void 0===t?"undefined":(r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)=="object"&&"value"in t)return e;throw Error("Docusaurus error: Bad <Tabs> child <".concat("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.'))}))||void 0===t?void 0:t.filter(Boolean))&&void 0!==r?r:[]}function m(e){var t=e.value;return e.tabValues.some(function(e){return e.value===t})}var g=r("71607");let b="tabList_Qoir",y="tabItem_AQgk";function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n,i,a;n=e,i=t,a=r[t],i in n?Object.defineProperty(n,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[i]=a})}return e}function j(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function x(e){var t=e.className,r=e.block,i=e.selectedValue,l=e.selectValue,s=e.tabValues,c=[],u=(0,o.o5)().blockElementScrollPositionUntilNextRender,d=function(e){var t=e.currentTarget,r=s[c.indexOf(t)].value;r!==i&&(u(t),l(r))},h=function(e){var t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":var r,n=c.indexOf(e.currentTarget)+1;t=null!==(r=c[n])&&void 0!==r?r:c[0];break;case"ArrowLeft":var i,a=c.indexOf(e.currentTarget)-1;t=null!==(i=c[a])&&void 0!==i?i:c[c.length-1]}null==t||t.focus()};return(0,n.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:s.map(function(e){var t=e.value,r=e.label,o=e.attributes;return(0,n.jsx)("li",j(v({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,ref:function(e){return c.push(e)},onKeyDown:h,onClick:d},o),{className:(0,a.Z)("tabs__item",y,null==o?void 0:o.className,{"tabs__item--active":i===t}),children:null!=r?r:t}),t)})})}function w(e){var t=e.lazy,r=e.children,o=e.selectedValue,l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){var s=l.find(function(e){return e.props.value===o});return s?(0,i.cloneElement)(s,{className:(0,a.Z)("margin-top--md",s.props.className)}):null}return(0,n.jsx)("div",{className:"margin-top--md",children:l.map(function(e,t){return(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==o})})})}function O(e){var t=function(e){var t,r,n,a,o,h,g,b,y,v,j,x,w,O,S=e.defaultValue,k=e.queryString,T=e.groupId;var P=(r=(t=e).values,n=t.children,(0,i.useMemo)(function(){var e=null!=r?r:f(n).map(function(e){var t=e.props;return{value:t.value,label:t.label,attributes:t.attributes,default:t.default}});return!function(e){var t=(0,u.lx)(e,function(e,t){return e.value===t.value});if(t.length>0)throw Error('Docusaurus error: Duplicate values "'.concat(t.map(function(e){return e.value}).join(", "),'" found in <Tabs>. Every value needs to be unique.'))}(e),e},[r,n])),D=p((0,i.useState)(function(){return function(e){var t,r=e.defaultValue,n=e.tabValues;if(0===n.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(r){if(!m({value:r,tabValues:n}))throw Error('Docusaurus error: The <Tabs> has a defaultValue "'.concat(r,'" but none of its children has the corresponding value. Available values are: ').concat(n.map(function(e){return e.value}).join(", "),". If you intend to show no default tab, use defaultValue={null} instead."));return r}var i=null!==(t=n.find(function(e){return e.default}))&&void 0!==t?t:n[0];if(!i)throw Error("Unexpected error: 0 tabValues");return i.value}({defaultValue:S,tabValues:P})}),2),R=D[0],E=D[1];var I=p((o=(a={queryString:void 0!==k&&k,groupId:T}).queryString,h=a.groupId,g=(0,l.k6)(),b=function(e){var t=e.queryString,r=void 0!==t&&t,n=e.groupId;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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 null!=n?n:null}({queryString:void 0!==o&&o,groupId:h}),[(0,c._X)(b),(0,i.useCallback)(function(e){if(!!b){var t,r,n=new URLSearchParams(g.location.search);n.set(b,e),g.replace((t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n,i,a;n=e,i=t,a=r[t],i in n?Object.defineProperty(n,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[i]=a})}return e}({},g.location),r=(r={search:n.toString()},r),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t))}},[b,g])]),2),A=I[0],C=I[1];var N=p((v=(y=({groupId:T}).groupId)?"docusaurus.tab.".concat(y):null,x=(j=p((0,d.Nk)(v),2))[0],w=j[1],[x,(0,i.useCallback)(function(e){if(!!v)w.set(e)},[v,w])]),2),V=N[0],Z=N[1];var q=m({value:O=null!=A?A:V,tabValues:P})?O:null;return(0,s.Z)(function(){q&&E(q)},[q]),{selectedValue:R,selectValue:(0,i.useCallback)(function(e){if(!m({value:e,tabValues:P}))throw Error("Can't select invalid tab value=".concat(e));E(e),C(e),Z(e)},[C,Z,P]),tabValues:P}}(e);return(0,n.jsxs)("div",{className:(0,a.Z)("tabs-container",b),children:[(0,n.jsx)(x,v({},t,e)),(0,n.jsx)(w,v({},t,e))]})}function S(e){var t=(0,g.Z)();return(0,n.jsx)(O,j(v({},e),{children:f(e.children)}),String(t))}},32240:function(e,t,r){r.d(t,{Z:()=>d});var n=r("24246"),i=r("27378"),a=r("96700"),o=r("3620");let l="apiTable_e8hp";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var a=[],o=!0,l=!1;try{for(i=i.call(e);!(o=(r=i.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){l=!0,n=e}finally{try{!o&&null!=i.return&&i.return()}finally{if(l)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var u=i.forwardRef(function(e,t){var r=e.name,l=e.children,s=function(e){for(var t=e;(0,i.isValidElement)(t);)t=c(i.Children.toArray(t.props.children),1)[0];if("string"!=typeof t)throw Error("Could not extract APITable row name from JSX tree:\n".concat(JSON.stringify(e,null,2)));return t}(l),u=r?"".concat(r,"-").concat(s):s,d="#".concat(u),h=(0,o.k6)();return(0,a.Z)().collectAnchor(u),(0,n.jsx)("tr",{id:u,tabIndex:0,ref:h.location.hash===d?t:void 0,onClick:function(e){var t,r="TD"===e.target.tagName.toUpperCase(),n=!!(null===(t=window.getSelection())||void 0===t?void 0:t.toString());r&&!n&&h.push(d)},onKeyDown:function(e){"Enter"===e.key&&h.push(d)},children:l.props.children})});function d(e){var t=e.children,r=e.name;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.");var a=c(i.Children.toArray(t.props.children),2),o=a[0],s=a[1],d=(0,i.useRef)(null);(0,i.useEffect)(function(){var e;null===(e=d.current)||void 0===e||e.focus()},[d]);var h=i.Children.map(s.props.children,function(e){return(0,n.jsx)(u,{name:r,ref:d,children:e})});return(0,n.jsxs)("table",{className:l,children:[o,(0,n.jsx)("tbody",{children:h})]})}},80980:function(e,t,r){r.d(t,{Z:function(){return l},a:function(){return o}});var n=r(27378);let i={},a=n.createContext(i);function o(e){let t=n.useContext(a);return n.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:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]);