-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Docusaurus Integration Page #267
Open
BeeBombshell
wants to merge
1
commit into
djyde:master
Choose a base branch
from
BeeBombshell:docusaurus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Integrate Cusdis into Docusaurus | ||
|
||
[Docusaurus](https://github.com/facebook/docusaurus) is a user-friendly, open-source static site generator developed by Meta. It harnesses the full potential of **React** and **MDX**, making it easy to start, customizable, and suitable for localization. | ||
|
||
## Usage | ||
|
||
This guide will walk you through the steps to add Cusdis comments to your Docusaurus website pages. | ||
|
||
### Installing Dependencies | ||
|
||
Before integrating Cusdis, ensure that you have installed the required dependencies. You will need `react-cusdis`, which is a **React wrapper for Cusdis**. Install it as a dependency in your Docusaurus project: | ||
|
||
```bash | ||
npm install react-cusdis | ||
# or | ||
yarn add react-cusdis | ||
|
||
``` | ||
|
||
### Create a Cusdis Component | ||
|
||
Next, create a new component for Cusdis in your Docusaurus project. You can name it `CusdisComments.js` and place it in the `src/components folder`. Here's an example of what the component might look like: | ||
|
||
```js | ||
import { ReactCusdis } from 'react-cusdis'; | ||
|
||
export default function CusdisComments(props) { | ||
const appId = process.env.CUSDIS_APP_ID; | ||
|
||
return ( | ||
<div> | ||
<ReactCusdis | ||
id="cusdis-thread" | ||
attrs={{ | ||
host: "https://cusdis.com", | ||
appId: appId, | ||
pageId: props.attrs.pageId, | ||
pageTitle: props.attrs.pageTitle, | ||
pageUrl: props.attrs.pageUrl, | ||
theme: "auto", | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
### Import and add the Cusdis Component | ||
|
||
Once you've created the `CusdisComments.js` component, import it into the documentation page where you want to add the Cusdis comment system. Import the component at the top of your page file, like this: | ||
|
||
```js | ||
import CusdisComments from '../src/components/CusdisComments'; | ||
``` | ||
|
||
In the same documentation page, add the following code where you want to display the comment system: | ||
|
||
```js | ||
<CusdisComments | ||
id="cusdis_thread" | ||
attrs={{ | ||
pageId: frontMatter.id, | ||
pageTitle: frontMatter.title, | ||
pageUrl: frontMatter.__resourcePath, | ||
}} | ||
/> | ||
``` | ||
|
||
This code snippet will render the Cusdis comment system on your Docusaurus page. | ||
|
||
### Set Up Environment Variables (optional) | ||
|
||
To securely store your Cusdis App ID, follow these steps to set up environment variables in your Docusaurus project: | ||
|
||
#### Step 1: Install the `@docusaurus/plugin-client-redirects` Package | ||
|
||
Install the `@docusaurus/plugin-client-redirects` package using npm or yarn: | ||
|
||
```bash | ||
npm install @docusaurus/plugin-client-redirects | ||
# or | ||
yarn add @docusaurus/plugin-client-redirects | ||
``` | ||
|
||
#### Step 2: Configure Environment Variables | ||
|
||
In your `docusaurus.config.js` file, add the following configuration under the `plugins` section to enable environment variables: | ||
|
||
```js | ||
plugins: [ | ||
[ | ||
"docusaurus2-dotenv", | ||
{ | ||
systemvars: true, | ||
}, | ||
], | ||
], | ||
``` | ||
|
||
#### Step 3: Create an .env File | ||
|
||
Create a `.env` file in the root of your Docusaurus project and add your **Cusdis App ID** to it. For example: | ||
|
||
```env | ||
CUSDIS_APP_ID=your-app-id | ||
``` | ||
|
||
#### Step 4: Access Environment Variables | ||
|
||
You can now access your environment variable in the `CusdisComments` component as follows: | ||
|
||
```js | ||
import { ReactCusdis } from 'react-cusdis'; | ||
|
||
export default function CusdisComments(props) { | ||
const appId = process.env.CUSDIS_APP_ID; | ||
|
||
// ... rest of the component code | ||
} | ||
|
||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's probably helpful to mention that the
frontMatter
here comes fromprops.content
, and theprops
is from the pager's wrapper (e.g.DocItemWrapper
):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.
观摩一下,哈哈。