/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-plugin-client-redirects/src/createRedirectPageContent.ts
44 строки
1 KB
Sébastien Lorber
refactor: use `URL.parse()` instead of try/catch (#12263)
10 июл 2026, 17:44
Не верифицирован
10 июл 2026, 17:44
83d4efd
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import _ from 'lodash'; import * as eta from 'eta'; import redirectPageTemplate from './templates/redirectPage.template.html'; const getCompiledRedirectPageTemplate = _.memoize(() => eta.compile(redirectPageTemplate.trim()), ); function renderRedirectPageTemplate(data: { toUrl: string; searchAnchorForwarding: boolean; }) { const compiled = getCompiledRedirectPageTemplate(); return compiled(data, eta.defaultConfig); } // if the target url does not include ?search#anchor, // we forward search/anchor that the redirect page receives function searchAnchorForwarding(toUrl: string): boolean { const url = URL.parse(toUrl, 'https://example.com'); if (url === null) { return false; } const containsSearchOrAnchor = url.search || url.hash; return !containsSearchOrAnchor; } export default function createRedirectPageContent({ toUrl, }: { toUrl: string; }): string { return renderRedirectPageTemplate({ toUrl: encodeURI(toUrl), searchAnchorForwarding: searchAnchorForwarding(toUrl), }); }