From 2f3fab9d17d9eed8a11a042d9b69feb361c7eea0 Mon Sep 17 00:00:00 2001 From: Karl Cardenas <29551334+karl-cardenas-coding@users.noreply.github.com> Date: Sat, 19 Oct 2024 08:25:45 -0700 Subject: [PATCH 1/2] ci: Robots Txt Fix (#4380) * chore: fix docusaurus format * ci: fix robots workflow * ci: update --- .github/workflows/versions_robot.yaml | 2 +- docusaurus.config.js | 1 - netlify.toml | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/versions_robot.yaml b/.github/workflows/versions_robot.yaml index e38aec6660..96deb940fe 100644 --- a/.github/workflows/versions_robot.yaml +++ b/.github/workflows/versions_robot.yaml @@ -83,7 +83,7 @@ jobs: - name: Ensure noIndex is set id: check_noindex - run: node scripts/noindex_docusaurus_config.js $RUNNER_TEMP $PWD && mv $RUNNER_TEMP/temp.docusaurus.config.js $PWD/docusaurus.config.js + run: node scripts/noindex_docusaurus_config.js $PWD - name: Auto Format (Prettier) run: make format diff --git a/docusaurus.config.js b/docusaurus.config.js index a404471ffd..b891bd5090 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -9,7 +9,6 @@ const ArchivedVersions = require("./archiveVersions.json"); const { pluginPacksAndIntegrationsData } = require("./plugins/packs-integrations"); const { pluginImportFontAwesomeIcons } = require("./plugins/font-awesome"); import path from "path"; -import { Logger } from "sass"; /** @type {import('@docusaurus/types').Config} */ const config = { diff --git a/netlify.toml b/netlify.toml index 703f5a28d0..9be59d5709 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,7 @@ [build] ignore = "./scripts/netlify.sh" command = "npm run build" - +[context.branch-deploy.environment] + # Set so that branch deploys (version-x.legacy.docs.spectrocloud.com) contain sitemap.xml + NODE_ENV = "production" From 3adeb1a731dda2bb36f7c0dbff435df953436e46 Mon Sep 17 00:00:00 2001 From: Karl Cardenas Date: Sat, 19 Oct 2024 08:33:02 -0700 Subject: [PATCH 2/2] ci: fix nodescript --- scripts/noindex_docusaurus_config.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/noindex_docusaurus_config.js b/scripts/noindex_docusaurus_config.js index 7a24d5112c..de8a31c87b 100644 --- a/scripts/noindex_docusaurus_config.js +++ b/scripts/noindex_docusaurus_config.js @@ -4,8 +4,7 @@ const generate = require("@babel/generator").default; const t = require("@babel/types"); const docusaurusConfigFile = "docusaurus.config.js"; -const tempDirectory = process.argv[2]; -const baseDirectory = process.argv[3]; +const baseDirectory = process.argv[2]; // Remove the tempDirectory argument // This reads the docusaurus.config.js file and parses it into an AST. // We need to parse it into an AST so that we can add the new versions to the config object. @@ -18,35 +17,29 @@ const ast = parser.parse(configCode, { // Function to add noIndex: true after trailingSlash if not already present const addNoIndexProperty = () => { - // Find the main "config" declaration const configDeclaration = ast.program.body.find( (node) => node.type === "VariableDeclaration" && node.declarations[0].id.name === "config" ); - // If the "config" declaration is not found, log an error and return if (!configDeclaration) { console.error('Could not locate the main "config" declaration.'); return; } - // Check if the "noIndex" property already exists const noIndexExists = configDeclaration.declarations[0].init.properties.some((prop) => prop.key.name === "noIndex"); if (noIndexExists) { console.log('"noIndex" property already exists in the config.'); - return; // Do nothing if noIndex already exists + return; } - // Find the "trailingSlash" property in the "config" declaration const trailingSlashProperty = configDeclaration.declarations[0].init.properties.find( (prop) => prop.key.name === "trailingSlash" ); - // If "trailingSlash" is found, insert "noIndex: true" after it if (trailingSlashProperty) { const noIndexProperty = t.objectProperty(t.identifier("noIndex"), t.booleanLiteral(true)); - // Find the index of the trailingSlash property and insert noIndex after it const index = configDeclaration.declarations[0].init.properties.indexOf(trailingSlashProperty); configDeclaration.declarations[0].init.properties.splice(index + 1, 0, noIndexProperty); console.log('"noIndex" property added to the config.'); @@ -57,11 +50,12 @@ const addNoIndexProperty = () => { addNoIndexProperty(); -// This is where the new config object is converted back into code. +// Generate the updated code from the AST and overwrite the original config file const updatedCode = generate(ast).code; try { - // Lastly, this is where the new config object is written to the temp.docusaurus.config.js file. - fs.writeFileSync(`${tempDirectory}/temp.docusaurus.config.js`, updatedCode); + // Write directly to the original docusaurus.config.js file + fs.writeFileSync(`${baseDirectory}/${docusaurusConfigFile}`, updatedCode); + console.log("Original docusaurus.config.js updated with the new content."); } catch (err) { - console.error("Could not write to temp.docusaurus.config.js:", err); + console.error("Could not write to docusaurus.config.js:", err); }