From 9147e9226a5c328a540be2b617d33cfc1afb7d37 Mon Sep 17 00:00:00 2001 From: Juan Lulkin Date: Mon, 8 Feb 2021 12:15:58 +0100 Subject: [PATCH] Adds script to verify sidebars navigation --- .github/workflows/microsite-build-check.yml | 4 ++ microsite/package.json | 3 +- microsite/scripts/verify-sidebars.js | 62 +++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 microsite/scripts/verify-sidebars.js diff --git a/.github/workflows/microsite-build-check.yml b/.github/workflows/microsite-build-check.yml index 45182229c9..a67efe9119 100644 --- a/.github/workflows/microsite-build-check.yml +++ b/.github/workflows/microsite-build-check.yml @@ -36,6 +36,10 @@ jobs: run: yarn install --frozen-lockfile working-directory: microsite + - name: verify sidebars + run: yarn verify:sidebars + working-directory: microsite + - name: prettier run: yarn prettier:check working-directory: microsite diff --git a/microsite/package.json b/microsite/package.json index cb82e6ec85..ea16fd8a32 100644 --- a/microsite/package.json +++ b/microsite/package.json @@ -11,7 +11,8 @@ "publish-gh-pages": "docusaurus-publish", "write-translations": "docusaurus-write-translations", "version": "docusaurus-version", - "rename-version": "docusaurus-rename-version" + "rename-version": "docusaurus-rename-version", + "verify:sidebars": "node ./scripts/verify-sidebars" }, "devDependencies": { "@spotify/prettier-config": "^9.0.0", diff --git a/microsite/scripts/verify-sidebars.js b/microsite/scripts/verify-sidebars.js new file mode 100755 index 0000000000..8a72d494ce --- /dev/null +++ b/microsite/scripts/verify-sidebars.js @@ -0,0 +1,62 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This script relies on docusaurus internals. It can be replaced in case + * docusaurus adds proper validation of the sidebar items. + */ + +require('@babel/polyfill'); +require('@babel/register')({ + babelrc: false, + only: [`${__dirname}/..`, `${process.cwd()}/core`], + plugins: [ + require('docusaurus/lib/server/translate-plugin.js'), + require('@babel/plugin-proposal-class-properties').default, + require('@babel/plugin-proposal-object-rest-spread').default, + ], + presets: [ + require('@babel/preset-react').default, + require('@babel/preset-env').default, + ], +}); + +const readMetadata = require('docusaurus/lib/server/readMetadata.js'); +readMetadata.generateMetadataDocs(); +const metadata = require('docusaurus/lib/core/metadata.js'); + +const errors = []; +const ids = Object.keys(metadata); +for (let id of ids) { + const { next, previous } = metadata[id]; + + if (next && !ids.includes(next)) { + errors.push(`Next ${next} does not exists in ${id}.`); + } + + if (previous && !ids.includes(previous)) { + errors.push(`Previous ${previous} does not exists in ${id}.`); + } +} + +if (errors.length) { + for (let error of errors) { + console.log(`❌ ${error}`); + } + process.exit(1); +} + +console.log('✅ All sidebar links are correct.');