Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent indexing of old kedro docs using RTD-Enabled JavaScript script #4516

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/static/deindex-old-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Explanation from RTD on how this script works:
// https://github.com/readthedocs/addons/pull/474#issuecomment-2615984387

// Ensure the correct API version is set
if (document.querySelector("meta[name='readthedocs-addons-api-version']") === null) {
const meta = document.createElement("meta");
meta.name = "readthedocs-addons-api-version";
meta.content = "1";
document.head.appendChild(meta);
}

// Function to handle RTD data and inject meta tags based on conditions
function _handleReadTheDocsData(data) {
const projectSlug = data.projects.current.slug;
const versionSlug = data.versions.current.slug;

console.log("Project slug:", projectSlug, "| Version:", versionSlug);

// Ensure the version is updated after each release of kedro-datasets
if (
(projectSlug === "kedro-datasets" && versionSlug !== "kedro-datasets-6.0.0") ||
(projectSlug !== "kedro-datasets" && versionSlug !== "stable")
) {
console.log("Non-indexable version detected, injecting meta tag");
const meta = document.createElement("meta");
meta.name = "robots";
meta.content = "noindex, nofollow";
document.head.appendChild(meta);
} else {
console.log("Indexable version detected, no meta tag added.");
}
}

// Check if the event has already been fired before this script runs
if (window.ReadTheDocsEventData !== undefined) {
_handleReadTheDocsData(window.ReadTheDocsEventData.data());
}

// Subscribe to future dispatches of the event (e.g., SPA navigation)
document.addEventListener("readthedocs-addons-data-ready", function (event) {
_handleReadTheDocsData(event.detail.data());
});