Skip to content

Commit 23d3f8c

Browse files
authored
Merge pull request #38 from S7-OpenLearning-Individual/bugfix/#33/navigator-page-linking-broken
Add enviroment variable
2 parents 4cac7de + c1d6723 commit 23d3f8c

6 files changed

Lines changed: 61 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
npm-debug.log*
1919
yarn-debug.log*
2020
yarn-error.log*
21+
22+
# Environment variables
23+
.env

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- [Local Development](#local-development)
77
- [Linting](#linting)
88
- [Build and serve](#build-and-serve)
9+
- [Deployment](#deployment)
10+
- [GitHub Pages](#github-pages)
11+
- [Docker Image](#docker-image)
912
- [Contributing](#contributing)
1013

1114
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
2427
10. Each page is built using the [template](/template.mdx) (validated by `npm run lint:mdx`).
2528
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.
2629
12. Images need to have padding applied around them, optimally `2rem`.
30+
13. Code has no 'TODO' blocks, only a 'FUTURE_WORK' block may be present with a reference to an issue or task.
2731

2832
## Installation
2933

@@ -65,6 +69,25 @@ And then to serve the newly created build, simply run.
6569
npm run serve
6670
```
6771

72+
## Deployment
73+
74+
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:
75+
76+
```env
77+
# This value MUST start and end with a slash '/', unless it's the root '/'.
78+
BASE_URL=''
79+
```
80+
81+
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
82+
83+
### GitHub Pages
84+
85+
T.B.A
86+
87+
### Docker Image
88+
89+
T.B.A
90+
6891
## Contributing
6992

7093
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:

docusaurus.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { themes as prismThemes } from "prism-react-renderer";
22
import type { Config } from "@docusaurus/types";
33
import type * as Preset from "@docusaurus/preset-classic";
44
import packageJson from "./package.json";
5+
import "dotenv/config";
6+
7+
const baseUrlOrDefault = process.env.BASE_URL || "/";
58

6-
//todo enable search
79
const config: Config = {
810
title: "Design Pattern Pedia",
911
tagline: "Practicing Patterns Made Plain and Practical",
@@ -12,7 +14,11 @@ const config: Config = {
1214
v4: true,
1315
},
1416
url: "https://your-docusaurus-site.example.com",
15-
baseUrl: "/",
17+
baseUrl: baseUrlOrDefault,
18+
customFields: {
19+
// 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.
20+
baseUrl: baseUrlOrDefault,
21+
},
1622
organizationName: "S7-OpenLearning-Individual",
1723
projectName: "DesignPatternPedia",
1824
onBrokenLinks: "throw",

package-lock.json

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@easyops-cn/docusaurus-search-local": "^0.52.1",
2424
"@mdx-js/react": "^3.0.0",
2525
"clsx": "^2.0.0",
26+
"dotenv": "^17.2.3",
2627
"prism-react-renderer": "^2.3.0",
2728
"react": "^19.0.0",
2829
"react-dom": "^19.0.0",

src/components/navigator/PatternResult.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import styles from "./navigator.module.css";
3+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
34

45
const baseURL = "/DesignPatternPedia/docs";
56

@@ -16,14 +17,23 @@ const PatternResult: React.FC<PatternResultProps> = ({
1617
path,
1718
onReset,
1819
}) => {
20+
const {
21+
siteConfig: { customFields },
22+
} = useDocusaurusContext();
23+
24+
const baseUrlOrDefault = customFields.baseUrl || "/";
25+
1926
return (
2027
<>
2128
<div className={styles.divider} />
2229
<div className={styles.patternResult}>
2330
<h2>{name}</h2>
2431
<p>{description}</p>
2532
<div className={styles.resultButtons}>
26-
<a href={`${baseURL}/${path}`} className="button button--primary">
33+
<a
34+
href={`${baseUrlOrDefault}docs/${path}`}
35+
className="button button--primary"
36+
>
2737
Learn More
2838
</a>
2939
<button

0 commit comments

Comments
 (0)