From c1d6723eb7850a6a2a949454f6debb6254023174 Mon Sep 17 00:00:00 2001 From: theartcher Date: Sat, 13 Dec 2025 12:40:25 +0100 Subject: [PATCH] Remove old TODO block, add env baseURL variable, ignored env in gitignore, update config and navigator to use baseURL --- .gitignore | 3 +++ README.md | 23 ++++++++++++++++++++++ docusaurus.config.ts | 10 ++++++++-- package-lock.json | 17 ++++++++++++++-- package.json | 1 + src/components/navigator/PatternResult.tsx | 12 ++++++++++- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b2d6de3..1525fe3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +# Environment variables +.env \ No newline at end of file diff --git a/README.md b/README.md index bddbe06..1a0b14e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ - [Local Development](#local-development) - [Linting](#linting) - [Build and serve](#build-and-serve) + - [Deployment](#deployment) + - [GitHub Pages](#github-pages) + - [Docker Image](#docker-image) - [Contributing](#contributing) This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator. @@ -24,6 +27,7 @@ This website is built using [Docusaurus](https://docusaurus.io/), a modern stati 10. Each page is built using the [template](/template.mdx) (validated by `npm run lint:mdx`). 11. Custom components should not implement their own title, they should use the correct heading (#) level in the page itself to ensure proper url based linking. 12. Images need to have padding applied around them, optimally `2rem`. +13. Code has no 'TODO' blocks, only a 'FUTURE_WORK' block may be present with a reference to an issue or task. ## Installation @@ -65,6 +69,25 @@ And then to serve the newly created build, simply run. npm run serve ``` +## Deployment + +To deploy the website, there are multiple options available depending on your hosting preferences. But first you should create a `.env` file in the root directory of the project with the following content: + +```env +# This value MUST start and end with a slash '/', unless it's the root '/'. +BASE_URL='' +``` + +This step is only necessary when you want to differ from the default `baseUrl` value of `/`. This is particularly useful when deploying to GitHub Pages under a repository, e.g., `https://username.github.io/repository-name/`, where the `BASE_URL` should be set to `/repository-name/`. See the [Docusaurus docs](https://docusaurus.io/docs/api/docusaurus-config#baseUrl) for more information + +### GitHub Pages + +T.B.A + +### Docker Image + +T.B.A + ## Contributing Would you like to propose changes to the pattern-wiki? Then feel free to create a pull request in this repository. Make sure that your PR follows the standards as set in the [coding standards](#coding-standards). These standards ensure that the wiki is of high quality and that both the users and developers can find the right information quickly. The steps to work on an issue or task are as follows: diff --git a/docusaurus.config.ts b/docusaurus.config.ts index e26c720..3b7f452 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -2,8 +2,10 @@ import { themes as prismThemes } from "prism-react-renderer"; import type { Config } from "@docusaurus/types"; import type * as Preset from "@docusaurus/preset-classic"; import packageJson from "./package.json"; +import "dotenv/config"; + +const baseUrlOrDefault = process.env.BASE_URL || "/"; -//todo enable search const config: Config = { title: "Design Pattern Pedia", tagline: "Practicing Patterns Made Plain and Practical", @@ -12,7 +14,11 @@ const config: Config = { v4: true, }, url: "https://your-docusaurus-site.example.com", - baseUrl: "/", + baseUrl: baseUrlOrDefault, + customFields: { + // We need to pass this directly as process.env is not available in the client bundle. But we do need this variable in the client bundle. + baseUrl: baseUrlOrDefault, + }, organizationName: "S7-OpenLearning-Individual", projectName: "DesignPatternPedia", onBrokenLinks: "throw", diff --git a/package-lock.json b/package-lock.json index ec5b668..5711199 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "design-pattern-pedia", - "version": "0.0.0", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "design-pattern-pedia", - "version": "0.0.0", + "version": "1.0.0", "dependencies": { "@docusaurus/core": "3.9.2", "@docusaurus/preset-classic": "3.9.2", @@ -15,6 +15,7 @@ "@easyops-cn/docusaurus-search-local": "^0.52.1", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "dotenv": "^17.2.3", "prism-react-renderer": "^2.3.0", "react": "^19.0.0", "react-dom": "^19.0.0", @@ -9183,6 +9184,18 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index faba16c..0f31f0d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@easyops-cn/docusaurus-search-local": "^0.52.1", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "dotenv": "^17.2.3", "prism-react-renderer": "^2.3.0", "react": "^19.0.0", "react-dom": "^19.0.0", diff --git a/src/components/navigator/PatternResult.tsx b/src/components/navigator/PatternResult.tsx index 488966a..ce9ce24 100644 --- a/src/components/navigator/PatternResult.tsx +++ b/src/components/navigator/PatternResult.tsx @@ -1,5 +1,6 @@ import React from "react"; import styles from "./navigator.module.css"; +import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; const baseURL = "/DesignPatternPedia/docs"; @@ -16,6 +17,12 @@ const PatternResult: React.FC = ({ path, onReset, }) => { + const { + siteConfig: { customFields }, + } = useDocusaurusContext(); + + const baseUrlOrDefault = customFields.baseUrl || "/"; + return ( <>
@@ -23,7 +30,10 @@ const PatternResult: React.FC = ({

{name}

{description}

- + Learn More