-
Notifications
You must be signed in to change notification settings - Fork 1
Add enviroment variable #38
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
Conversation
…nore, update config and navigator to use baseURL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds environment variable support for configuring the base URL of the Docusaurus site, addressing the need for flexible deployment configurations. The implementation allows the site to be deployed under different base paths (e.g., GitHub Pages repository paths) by reading from a BASE_URL environment variable with a fallback to the root path /.
Key changes:
- Add
.envfile support using thedotenvpackage for runtime configuration - Refactor
PatternResultcomponent to use the configurable base URL from Docusaurus context instead of hardcoded values - Update documentation with deployment guidelines and clarify coding standards around TODO/FUTURE_WORK comments
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/components/navigator/PatternResult.tsx |
Updated to retrieve base URL from Docusaurus customFields instead of using hardcoded value |
package.json |
Added dotenv dependency for environment variable support |
package-lock.json |
Added lockfile entries for dotenv package and updated version to 1.0.0 |
docusaurus.config.ts |
Imported dotenv, read BASE_URL from environment, and passed it through customFields for client-side access |
README.md |
Added deployment section with .env configuration instructions and updated coding standard about TODO/FUTURE_WORK comments |
.gitignore |
Added .env to prevent committing environment variables |
| 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 |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a period at the end of the sentence. The sentence should end with proper punctuation.
| 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 | |
| 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. |
| import styles from "./navigator.module.css"; | ||
| import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; | ||
|
|
||
| const baseURL = "/DesignPatternPedia/docs"; |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded baseURL constant is now unused and should be removed. The component now retrieves the base URL from customFields instead.
| const baseURL = "/DesignPatternPedia/docs"; |
| siteConfig: { customFields }, | ||
| } = useDocusaurusContext(); | ||
|
|
||
| const baseUrlOrDefault = customFields.baseUrl || "/"; |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion for customFields.baseUrl should be added since customFields is typed as Record<string, unknown> in Docusaurus. Consider accessing it as (customFields.baseUrl as string | undefined) to ensure type safety.
| const baseUrlOrDefault = customFields.baseUrl || "/"; | |
| const baseUrlOrDefault = (customFields.baseUrl as string | undefined) || "/"; |
| <div className={styles.resultButtons}> | ||
| <a href={`${baseURL}/${path}`} className="button button--primary"> | ||
| <a | ||
| href={`${baseUrlOrDefault}docs/${path}`} |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL construction logic may produce double slashes when baseUrlOrDefault is "/" (the default). For example, if baseUrlOrDefault is "/", the href will be "/docs/path", which is correct. However, if baseUrlOrDefault is "/repository-name/", the href will be "/repository-name/docs/path", which is also correct. But if baseUrlOrDefault doesn't end with a slash (which violates the documentation), this could produce incorrect URLs. Consider adding validation or a more robust URL joining mechanism.
Related issue #33
This PR proposes to do the following;
/.dotenvpackage.