docs: use a number of documented versions for indexing (#9424)

This PR allows Algolia to index on the number of documented versions
rather than on the global version of packages.

Fixed: #9329
This commit is contained in:
jrandolf 2022-12-16 14:01:19 +01:00 committed by GitHub
parent 68c53df75f
commit f0951aaf3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 502 additions and 476 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,9 @@
"archive": "node archive.js" "archive": "node archive.js"
}, },
"dependencies": { "dependencies": {
"@docusaurus/core": "2.1.0", "@docusaurus/core": "2.2.0",
"@docusaurus/plugin-client-redirects": "2.1.0", "@docusaurus/plugin-client-redirects": "2.2.0",
"@docusaurus/preset-classic": "2.1.0", "@docusaurus/preset-classic": "2.2.0",
"@mdx-js/react": "1.6.22", "@mdx-js/react": "1.6.22",
"clsx": "1.2.1", "clsx": "1.2.1",
"prism-react-renderer": "1.3.5", "prism-react-renderer": "1.3.5",
@ -25,7 +25,7 @@
"react-dom": "17.0.2" "react-dom": "17.0.2"
}, },
"devDependencies": { "devDependencies": {
"@docusaurus/module-type-aliases": "2.1.0", "@docusaurus/module-type-aliases": "2.2.0",
"swc-loader": "0.2.3" "swc-loader": "0.2.3"
}, },
"browserslist": { "browserslist": {

View File

@ -0,0 +1,26 @@
import React from 'react';
import Head from '@docusaurus/Head';
// Tracks the global package version as a local, monotonic counter. This
// prevents Algolia from deleting based on differing package versions and
// instead delete based on the number of versions we intend to keep documented.
let globalCounter = -1;
const versionToCounter = new Map();
export default function SearchMetadata({locale, version}) {
const language = locale;
let counter;
if (version) {
counter = versionToCounter.get(version);
if (!counter) {
counter = ++globalCounter;
versionToCounter.set(version, counter);
}
}
return (
<Head>
{language && <meta name="docsearch:language" content={language} />}
{counter && <meta name="docsearch:counter" content={counter} />}
</Head>
);
}