Upgrade to Docusaurus v3.1 (#99)

* Upgrade to Docusaurus v3

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Upgrade everything to latest version

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Rebuild lock file

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Update all remaining packages

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Upgrade everything

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Fix outdated findFirstCategoryLink import

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Swizzle color mode component

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Remove unused import

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Rebase, upgrade to v3.1.0, use TS in config

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

* Point to the latest commit in the submodule

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>

---------

Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>
This commit is contained in:
Damian Stasik 2024-01-12 13:30:13 +01:00 committed by GitHub
parent 1d2d9fbc89
commit ea06c3cd8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 5370 additions and 3583 deletions

View file

@ -1,337 +0,0 @@
// @ts-check
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
/** @type {import('@docusaurus/types').Config} */
const config = {
title: "OpenTofu",
url: "https://opentofu.org",
headTags: [
{
tagName: "link",
attributes: {
rel: "apple-touch-icon",
type: "image/png",
sizes: "180x180",
href: "/favicons/apple-touch-icon.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/svg+xml",
href: "/favicons/favicon.svg",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "16x16",
href: "/favicons/favicon-16x16.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "32x32",
href: "/favicons/favicon-32x32.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "48x48",
href: "/favicons/favicon-48x48.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "192x192",
href: "/favicons/android-chrome-192x192.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "512x512",
href: "/favicons/android-chrome-512x512.png",
},
},
{
tagName: "link",
attributes: {
rel: "manifest",
href: "/favicons/site.webmanifest",
},
},
],
baseUrl: "/",
// TODO: Once we clean up links we can switch to "throw"
onBrokenLinks: "warn",
onBrokenMarkdownLinks: "warn",
i18n: {
defaultLocale: "en",
locales: ["en"],
},
presets: [
[
"classic",
/** @type {import('@docusaurus/preset-classic').Options} */
({
theme: {
customCss: [require.resolve("./src/css/custom.css")],
},
docs: {
sidebarPath: require.resolve("./sidebars.js"),
path: "opentofu-repo/website/docs",
routeBasePath: "/docs",
editUrl: ({ docPath }) => {
// Remove the edit link from the documentation index page
// TODO: remove after moving the page to the main OpenTofu repo
if (docPath === "index.mdx") {
return `https://github.com/opentofu/opentofu.org/edit/main/docs/${docPath}`;
}
return `https://github.com/opentofu/opentofu/edit/main/website/docs/${docPath}`;
},
},
blog: false,
gtag: {
trackingID: "G-NKLFR0FNQZ",
},
}),
],
],
plugins: [
"./plugins/blog-plugin",
function tailwindPlugin() {
return {
name: "tailwindcss",
configurePostCss(postcssOptions) {
postcssOptions.plugins.push(require("tailwindcss"));
postcssOptions.plugins.push(require("autoprefixer"));
return postcssOptions;
},
};
},
[
"@docusaurus/plugin-client-redirects",
{
redirects: [
{
to: "/blog/opentofu-announces-fork-of-terraform",
from: "/announcement",
},
{
to: "/blog/the-opentofu-fork-is-now-available",
from: "/fork",
},
{
from: "/docs/cli/install/apt",
to: "/docs/intro/install/deb",
},
{
from: "/docs/cli/install/yum",
to: "/docs/intro/install/rpm",
},
// TODO: This will be possible after upgrading to Docusaurus 3
// {
// to: "https://join.slack.com/t/opentofucommunity/shared_invite/zt-24ma55j2u-a2DlPHCoMqlJkCEHL5DX_w",
// from: "/slack",
// },
],
},
],
function () {
return {
name: "follow-symlinks",
configureWebpack() {
return {
resolve: {
// Yes, leave this on false to support symlinks.
symlinks: false,
},
};
},
};
},
],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
// TODO: Do we want to support light mode?
colorMode: {
defaultMode: "dark",
respectPrefersColorScheme: false,
},
docs: {
sidebar: {
autoCollapseCategories: true,
},
},
announcementBar: {
id: "opentofu-ga",
content:
'<a target="_blank" rel="noopener noreferrer" href="https://opentofu.org/blog/opentofu-is-going-ga/">OpenTofu is going GA</a> we\'ve released the first stable release of OpenTofu, a community-driven open source fork of Terraform.',
backgroundColor: "#ffda18",
textColor: "#1b1d20",
isCloseable: false,
},
algolia: {
appId: "0AUNALFPJF",
apiKey: "5a83e1af5126db1360bdc84bfefb20b8",
indexName: "opentofu",
},
footer: {
links: [
{
label: "Manifesto",
href: "/manifesto",
},
{
label: "Supporters",
href: "/supporters",
},
{
label: "FAQs",
href: "/faq",
},
{
label: "Blog",
href: "/blog",
},
{
label: "Docs",
href: "/docs",
},
{
label: "Privacy",
href: "/privacy",
},
],
},
navbar: {
hideOnScroll: true,
items: [
{
to: "/manifesto",
label: "Manifesto",
position: "left",
},
{
to: "/supporters",
label: "Supporters",
position: "left",
},
{
to: "/faq",
label: "FAQs",
position: "left",
},
{
to: "/blog",
label: "Blog",
position: "left",
},
{
label: "Roadmap",
href: "https://github.com/opentofu/opentofu/milestones",
position: "left",
},
{
type: "dropdown",
to: "/docs",
label: "Docs",
position: "left",
items: [
{
type: "doc",
label: "Introduction",
docId: "intro/index",
},
{
type: "doc",
label: "CLI",
docId: "cli/index",
},
{
type: "doc",
label: "Language",
docId: "language/index",
},
{
type: "doc",
label: "Internals",
docId: "internals/index",
},
],
},
// TODO: This link is important but there's no design for it yet
// {
// type: "dropdown",
// label: "Community",
// position: "right",
// items: [
// {
// label: "GitHub Discussions",
// href: "https://github.com/orgs/opentofu/discussions",
// },
// ],
// },
{
type: "custom-github-stars-navbar-item",
position: "right",
ghRepoUrl: "https://github.com/opentofu/opentofu",
buttonLabel: "Star",
},
{
type: "custom-social-icon-link-navbar-item",
href: "https://www.youtube.com/channel/UCgIzfj9QuWL9HHXIXq2A0Ig",
position: "right",
name: "youtube",
label: "Go to the OpenTofu's Youtube page",
},
{
type: "custom-social-icon-link-navbar-item",
href: "https://twitter.com/opentofuorg",
position: "right",
name: "twitter",
label: "Follow us on Twitter",
},
{
type: "custom-social-icon-link-navbar-item",
href: "/slack",
position: "right",
name: "slack",
label: "Join us on Slack",
},
],
},
prism: {
theme: darkCodeTheme,
additionalLanguages: ["hcl", "powershell"],
},
image: "/img/og.png",
}),
};
module.exports = config;

334
docusaurus.config.ts Normal file
View file

@ -0,0 +1,334 @@
import { themes as prismThemes } from "prism-react-renderer";
import type { Config } from "@docusaurus/types";
import type * as Preset from "@docusaurus/preset-classic";
import tailwind from "tailwindcss";
import autoprefixer from "autoprefixer";
const config: Config = {
title: "OpenTofu",
url: "https://opentofu.org",
headTags: [
{
tagName: "link",
attributes: {
rel: "apple-touch-icon",
type: "image/png",
sizes: "180x180",
href: "/favicons/apple-touch-icon.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/svg+xml",
href: "/favicons/favicon.svg",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "16x16",
href: "/favicons/favicon-16x16.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "32x32",
href: "/favicons/favicon-32x32.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "48x48",
href: "/favicons/favicon-48x48.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "192x192",
href: "/favicons/android-chrome-192x192.png",
},
},
{
tagName: "link",
attributes: {
rel: "icon",
type: "image/png",
sizes: "512x512",
href: "/favicons/android-chrome-512x512.png",
},
},
{
tagName: "link",
attributes: {
rel: "manifest",
href: "/favicons/site.webmanifest",
},
},
],
baseUrl: "/",
// TODO: Once we clean up links we can switch to "throw"
onBrokenLinks: "warn",
onBrokenMarkdownLinks: "warn",
i18n: {
defaultLocale: "en",
locales: ["en"],
},
presets: [
[
"classic",
{
theme: {
customCss: [require.resolve("./src/css/custom.css")],
},
docs: {
sidebarPath: require.resolve("./sidebars.js"),
path: "opentofu-repo/website/docs",
routeBasePath: "/docs",
editUrl: ({ docPath }) => {
// Remove the edit link from the documentation index page
// TODO: remove after moving the page to the main OpenTofu repo
if (docPath === "index.mdx") {
return `https://github.com/opentofu/opentofu.org/edit/main/docs/${docPath}`;
}
return `https://github.com/opentofu/opentofu/edit/main/website/docs/${docPath}`;
},
},
blog: false,
gtag: {
trackingID: "G-NKLFR0FNQZ",
},
} satisfies Preset.Options,
],
],
plugins: [
"./plugins/blog-plugin",
function tailwindPlugin() {
return {
name: "tailwindcss",
configurePostCss(postcssOptions) {
postcssOptions.plugins.push(tailwind);
postcssOptions.plugins.push(autoprefixer);
return postcssOptions;
},
};
},
[
"@docusaurus/plugin-client-redirects",
{
redirects: [
{
to: "/blog/opentofu-announces-fork-of-terraform",
from: "/announcement",
},
{
to: "/blog/the-opentofu-fork-is-now-available",
from: "/fork",
},
{
from: "/docs/cli/install/apt",
to: "/docs/intro/install/deb",
},
{
from: "/docs/cli/install/yum",
to: "/docs/intro/install/rpm",
},
// TODO: This will be possible after upgrading to Docusaurus 3
// {
// to: "https://join.slack.com/t/opentofucommunity/shared_invite/zt-24ma55j2u-a2DlPHCoMqlJkCEHL5DX_w",
// from: "/slack",
// },
],
},
],
function () {
return {
name: "follow-symlinks",
configureWebpack() {
return {
resolve: {
// Yes, leave this on false to support symlinks.
symlinks: false,
},
};
},
};
},
],
themeConfig: {
colorMode: {
defaultMode: "dark",
respectPrefersColorScheme: false,
},
docs: {
sidebar: {
autoCollapseCategories: true,
},
},
announcementBar: {
id: "opentofu-ga",
content:
'<a target="_blank" rel="noopener noreferrer" href="https://opentofu.org/blog/opentofu-is-going-ga/">OpenTofu is going GA</a> we\'ve released the first stable release of OpenTofu, a community-driven open source fork of Terraform.',
backgroundColor: "#ffda18",
textColor: "#1b1d20",
isCloseable: false,
},
algolia: {
appId: "0AUNALFPJF",
apiKey: "5a83e1af5126db1360bdc84bfefb20b8",
indexName: "opentofu",
},
footer: {
links: [
{
label: "Manifesto",
href: "/manifesto",
},
{
label: "Supporters",
href: "/supporters",
},
{
label: "FAQs",
href: "/faq",
},
{
label: "Blog",
href: "/blog",
},
{
label: "Docs",
href: "/docs",
},
{
label: "Privacy",
href: "/privacy",
},
],
},
navbar: {
hideOnScroll: true,
items: [
{
to: "/manifesto",
label: "Manifesto",
position: "left",
},
{
to: "/supporters",
label: "Supporters",
position: "left",
},
{
to: "/faq",
label: "FAQs",
position: "left",
},
{
to: "/blog",
label: "Blog",
position: "left",
},
{
label: "Roadmap",
href: "https://github.com/opentofu/opentofu/milestones",
position: "left",
},
{
type: "dropdown",
to: "/docs",
label: "Docs",
position: "left",
items: [
{
type: "doc",
label: "Introduction",
docId: "intro/index",
},
{
type: "doc",
label: "CLI",
docId: "cli/index",
},
{
type: "doc",
label: "Language",
docId: "language/index",
},
{
type: "doc",
label: "Internals",
docId: "internals/index",
},
],
},
// TODO: This link is important but there's no design for it yet
// {
// type: "dropdown",
// label: "Community",
// position: "right",
// items: [
// {
// label: "GitHub Discussions",
// href: "https://github.com/orgs/opentofu/discussions",
// },
// ],
// },
{
type: "custom-github-stars-navbar-item",
position: "right",
ghRepoUrl: "https://github.com/opentofu/opentofu",
buttonLabel: "Star",
},
{
type: "custom-social-icon-link-navbar-item",
href: "https://www.youtube.com/channel/UCgIzfj9QuWL9HHXIXq2A0Ig",
position: "right",
name: "youtube",
label: "Go to the OpenTofu's Youtube page",
},
{
type: "custom-social-icon-link-navbar-item",
href: "https://twitter.com/opentofuorg",
position: "right",
name: "twitter",
label: "Follow us on Twitter",
},
{
type: "custom-social-icon-link-navbar-item",
href: "/slack",
position: "right",
name: "slack",
label: "Join us on Slack",
},
],
},
prism: {
theme: prismThemes.dracula,
additionalLanguages: ["hcl", "powershell"],
},
image: "/img/og.png",
} satisfies Preset.ThemeConfig,
};
export default config;

@ -1 +1 @@
Subproject commit 370ca0578ca7562c2e2333af4b2b9738e6f54405
Subproject commit 723593c244cf67d960c0127944eb1676649c56ea

8186
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{
"name": "documentation",
"name": "website",
"version": "0.0.0",
"private": true,
"scripts": {
@ -13,31 +13,32 @@
"lint": "eslint --cache \"**/*.{js,jsx,ts,tsx}\""
},
"dependencies": {
"@docusaurus/core": "2.4.1",
"@docusaurus/module-type-aliases": "2.4.1",
"@docusaurus/plugin-client-redirects": "^2.4.1",
"@docusaurus/preset-classic": "2.4.1",
"@mdx-js/react": "^1.6.22",
"@docusaurus/core": "3.1.0",
"@docusaurus/module-type-aliases": "3.1.0",
"@docusaurus/plugin-client-redirects": "3.1.0",
"@docusaurus/preset-classic": "3.1.0",
"@docusaurus/tsconfig": "3.1.0",
"@docusaurus/types": "^3.1.0",
"@mdx-js/react": "^3.0.0",
"@tailwindcss/typography": "^0.5.10",
"@tsconfig/docusaurus": "^1.0.5",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"autoprefixer": "^10.4.15",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"autoprefixer": "^10.4.16",
"cheerio": "^1.0.0-rc.12",
"clsx": "^1.2.1",
"eslint": "^8.49.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"clsx": "^2.1.0",
"eslint": "^8.56.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"postcss": "^8.4.29",
"prettier": "^3.0.3",
"prism-react-renderer": "^1.3.5",
"postcss": "^8.4.33",
"prettier": "^3.1.1",
"prism-react-renderer": "^2.3.1",
"raw-loader": "^4.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-github-btn": "^1.4.0",
"tailwindcss": "^3.3.3",
"typescript": "^4.7.4"
"tailwindcss": "^3.4.1",
"typescript": "~5.3.3"
},
"browserslist": {
"production": [
@ -56,7 +57,7 @@
},
"devDependencies": {
"husky": "^8.0.3",
"lint-staged": "^14.0.1"
"lint-staged": "^15.2.0"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"

View file

@ -0,0 +1,31 @@
import React from "react";
import useIsBrowser from "@docusaurus/useIsBrowser";
import IconLightMode from "@theme/Icon/LightMode";
import IconDarkMode from "@theme/Icon/DarkMode";
import type { Props } from "@theme/ColorModeToggle";
function ColorModeToggle({ value, onChange }: Props) {
const isBrowser = useIsBrowser();
const title = `Switch between dark and light mode (currently ${
value === "dark" ? "dark mode" : "light mode"
})`;
return (
<button
className="transition-colors text-gray-900 hover:text-brand-700 dark:text-gray-50 dark:hover:text-brand-500"
type="button"
onClick={() => onChange(value === "dark" ? "light" : "dark")}
disabled={!isBrowser}
title={title}
aria-label={title}
aria-live="polite"
>
{value === "light" && <IconLightMode />}
{value === "dark" && <IconDarkMode />}
</button>
);
}
export default React.memo(ColorModeToggle);

View file

@ -1,7 +1,7 @@
import React from "react";
import Link from "@docusaurus/Link";
import {
findFirstCategoryLink,
findFirstSidebarItemLink,
useDocById,
} from "@docusaurus/theme-common/internal";
import type {
@ -40,7 +40,7 @@ type CardCategoryProps = {
};
function CardCategory({ item }: CardCategoryProps) {
const href = findFirstCategoryLink(item);
const href = findFirstSidebarItemLink(item);
// Unexpected: categories that don't have a link have been filtered upfront
if (!href) {
return null;

View file

@ -1,15 +1,14 @@
import React from "react";
import DocPageLayoutSidebar from "./Sidebar";
import { useDocsSidebar } from "@docusaurus/theme-common/internal";
import Layout from "@theme/Layout";
import BackToTopButton from "@theme/BackToTopButton";
import type { Props } from "@theme/DocPage/Layout";
import type { Props } from "@theme/DocRoot/Layout";
export default function DocPageLayout({ children }: Props) {
const sidebar = useDocsSidebar();
return (
<Layout wrapperClassName="border-t border-b border-gray-200 dark:border-gray-800">
<div className="border-t border-b border-gray-200 dark:border-gray-800">
<BackToTopButton />
<div className="container mx-auto flex flex-1 lg:divide-x divide-gray-200 dark:divide-gray-800">
{sidebar && (
@ -20,6 +19,6 @@ export default function DocPageLayout({ children }: Props) {
)}
<main className="w-full lg:w-4/5">{children}</main>
</div>
</Layout>
</div>
);
}

View file

@ -8,7 +8,7 @@ import {
} from "@docusaurus/theme-common";
import {
isActiveSidebarItem,
findFirstCategoryLink,
findFirstSidebarItemLink,
useDocSidebarItemsExpandedState,
isSamePath,
} from "@docusaurus/theme-common/internal";
@ -50,7 +50,7 @@ function useCategoryHrefWithSSRFallback(
): string | undefined {
const isBrowser = useIsBrowser();
return useMemo(() => {
if (item.href) {
if (item.href && !item.linkUnlisted) {
return item.href;
}
// In these cases, it's not necessary to render a fallback
@ -58,7 +58,7 @@ function useCategoryHrefWithSSRFallback(
if (isBrowser || !item.collapsible) {
return undefined;
}
return findFirstCategoryLink(item);
return findFirstSidebarItemLink(item);
}, [item, isBrowser]);
}

View file

@ -1,10 +1,9 @@
{
"extends": "@tsconfig/docusaurus/tsconfig.json",
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
"lib": ["ES2022", "DOM"],
"baseUrl": ".",
"resolveJsonModule": true,
"moduleResolution": "NodeNext",
"paths": {
"@theme/*": ["src/theme/*"],
"@site/*": ["*"]