Repository: eslint/eslint
File: docs/.eleventy.js (JavaScript)

Code before:
    if (process.env.CONTEXT === "deploy-preview") {
        pathPrefix = "/";
    } else if (process.env.BRANCH === "latest") {
        pathPrefix = "/docs/latest/";
    } else if (process.env.BRANCH === "next") {
        pathPrefix = "/docs/next/";
    } else if (isNumberVersion) {
        pathPrefix = `/docs/${process.env.BRANCH}/`; // `/docs/v8.x/`, `/docs/v9.x/`, `/docs/v10.x/` ...
    }

    //------------------------------------------------------------------------------
    // Data
    //------------------------------------------------------------------------------

    // Load site-specific data
    const siteName = process.env.ESLINT_SITE_NAME || "en";

    /**
     * Determines whether we are in the prerelease phase.
     * @returns {Promise<boolean>} `true` if there is a prerelease of the next major version, `false` otherwise.
     */
    async function isPrereleasePhase() {
        const eslintVersions = await require("./src/_data/eslintVersions")();

        return eslintVersions.items.some(item => item.branch === "next");
    }

    eleventyConfig.addGlobalData("site_name", siteName);
    eleventyConfig.addGlobalData("GIT_BRANCH", process.env.BRANCH);
    eleventyConfig.addGlobalData("HEAD", process.env.BRANCH === "main");
    eleventyConfig.addGlobalData("NOINDEX", process.env.BRANCH !== "latest");
    eleventyConfig.addGlobalData("PATH_PREFIX", pathPrefix);
    eleventyConfig.addGlobalData("is_prerelease_phase", isPrereleasePhase);
    eleventyConfig.addGlobalData("is_number_version", isNumberVersion);
    eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));

    //------------------------------------------------------------------------------
    // Filters
    //------------------------------------------------------------------------------

    eleventyConfig.addFilter("limitTo", (arr, limit) => arr.slice(0, limit));

    eleventyConfig.addFilter("jsonify", variable => JSON.stringify(variable));

    eleventyConfig.addFilter("slugify", str => {
        if (!str) {
            return "";
        }

        return slug(str);
    });

Review comment (suggestion):
I just noticed that this would be an extra fetch on Netlify.

What do you think about the following, instead of adding a global variable `isPrereleasePhase`:

1. In `eslintVersions.js` we set `data.isPrereleasePhase`.
2. In `docs.html` we use `eslintVersions.isPrereleasePhase`.

Code after:
    if (process.env.CONTEXT === "deploy-preview") {
        pathPrefix = "/";
    } else if (process.env.BRANCH === "latest") {
        pathPrefix = "/docs/latest/";
    } else if (process.env.BRANCH === "next") {
        pathPrefix = "/docs/next/";
    } else if (isNumberVersion) {
        pathPrefix = `/docs/${process.env.BRANCH}/`; // `/docs/v8.x/`, `/docs/v9.x/`, `/docs/v10.x/` ...
    }

    //------------------------------------------------------------------------------
    // Data
    //------------------------------------------------------------------------------

    // Load site-specific data
    const siteName = process.env.ESLINT_SITE_NAME || "en";

    eleventyConfig.addGlobalData("site_name", siteName);
    eleventyConfig.addGlobalData("GIT_BRANCH", process.env.BRANCH);
    eleventyConfig.addGlobalData("HEAD", process.env.BRANCH === "main");
    eleventyConfig.addGlobalData("NOINDEX", process.env.BRANCH !== "latest");
    eleventyConfig.addGlobalData("PATH_PREFIX", pathPrefix);
    eleventyConfig.addGlobalData("is_number_version", isNumberVersion);
    eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));

    //------------------------------------------------------------------------------
    // Filters
    //------------------------------------------------------------------------------

    eleventyConfig.addFilter("limitTo", (arr, limit) => arr.slice(0, limit));

    eleventyConfig.addFilter("jsonify", variable => JSON.stringify(variable));

    eleventyConfig.addFilter("slugify", str => {
        if (!str) {
            return "";
        }

        return slug(str);
    });

    eleventyConfig.addFilter("URIencode", str => {
        if (!str) {
            return "";
        }
        return encodeURI(str);
    });

    /* order collection by the order specified in the front matter */
    eleventyConfig.addFilter("sortByPageOrder", values => values.slice().sort((a, b) => a.data.order - b.data.order));