Skip to content

Commit

Permalink
[version-4-4] ci: Robots Txt Fix (#4380) (#4382)
Browse files Browse the repository at this point in the history
* ci: Robots Txt Fix (#4380)

* chore: fix docusaurus format

* ci: fix robots workflow

* ci: update

* ci: fix docusarus file

* ci: remove netlify file
  • Loading branch information
karl-cardenas-coding authored Oct 19, 2024
1 parent 85033aa commit 2a8b4fe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/versions_robot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
ignore = "./scripts/netlify.sh"
command = "npm run build"


20 changes: 7 additions & 13 deletions scripts/noindex_docusaurus_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.');
Expand All @@ -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);
}

0 comments on commit 2a8b4fe

Please sign in to comment.