-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable search and production deploy
- Loading branch information
Eric Lin
committed
Feb 9, 2023
1 parent
0398c5e
commit 5234c4a
Showing
10 changed files
with
272 additions
and
11 deletions.
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,111 @@ | ||
--- | ||
sidebar_position: 8 | ||
--- | ||
|
||
# Enable search bar | ||
|
||
Docusaurus has official support for [Algolia Search](https://docusaurus.io/docs/search#using-algolia-docsearch) as the primary method of integrating search into docs. | ||
|
||
We have an [open-source account](https://docsearch.algolia.com/docs/who-can-apply/) with [Algolia](https://www.algolia.com/) to hold the indexes for our documentation but it is limited to **only** open-source projects (not just the documentation but the originating source code). If your project does not have any source code (general guidelines or tutorials), then it will satisfy the conditions as long as the documentation is open-source. | ||
|
||
:::tip | ||
|
||
This template repo assumes that the project and its source code is open-source, so it is set up out of the box to be able to integrate Algolia directly. | ||
|
||
Please follow the additional instructions below on how to set up local search to avoid an index if you do not satisfy those conditions. | ||
|
||
::: | ||
|
||
## Docs and source code is open-source | ||
|
||
Join the [#documentation](https://consensys.slack.com/archives/C0272B5P1CY) Slack channel and ask for Algolia search integration for your docs site. Make sure to provide details of your project so that we can determine whether you are eligible for the Algolia account. | ||
|
||
We will get back to you with the `appId`, `apiKey` (it's ok to expose this) and your `indexName`. | ||
|
||
You will need to fill those three fields in your `docusaurus.config.js` as shown below. | ||
|
||
```js {7-10} title="docusaurus.config.js" | ||
const config = { | ||
themeConfig: | ||
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */ | ||
({ | ||
algolia: { | ||
// The application ID provided by Algolia | ||
appId: "NSRFPEJ4NC", # // cspell:disable-line | ||
// Public API key: it is safe to commit it | ||
apiKey: "cea41b975ad6c9a01408dfda6e0061d3", | ||
indexName: "docs-template", // Ping #documentation on Slack for your index name | ||
}, | ||
}), | ||
}; | ||
``` | ||
|
||
## Source code is not open-source | ||
|
||
Unfortunately, if your project does not satisfy the [checklist](https://docsearch.algolia.com/docs/who-can-apply/) then we cannot use Algolia (for free). | ||
|
||
In this scenario, there are two options: | ||
|
||
1. Make a decision with your team and team lead whether there is [budget](https://www.algolia.com/pricing/) for integrating Algolia Search | ||
2. Install a [local search plugin](https://github.com/easyops-cn/docusaurus-search-local) and do not use Algolia | ||
|
||
If you decide on _option 1_ and have obtained Finance approval, then you can follow the steps from above and contact us with this information. | ||
|
||
If you decide on _option 2_, you can easily install the [local search plugin](https://github.com/easyops-cn/docusaurus-search-local). However, please note there are some small caveats. | ||
|
||
- Local search means that at build-time this is part of the build. For very large documentation sites there may be some marginal performance deficits and additional size to the bundle. Usually, it would require the docs site to be **very large** before it is even a consideration. | ||
- Search will not work when running in a dev environment (`npm run start`). You must `npm run build` and `npm run serve` locally to get the local search to work. | ||
|
||
### Steps to install plugin for local search | ||
|
||
1. `cd` into the root of your repository where your `package.json` is located | ||
2. Install the plugin with `npm` | ||
|
||
```bash | ||
npm i @easyops-cn/docusaurus-search-local | ||
``` | ||
|
||
3. Remove the `algolia` key entirely under `config > themeConfig`. | ||
|
||
```js title="DELETE ME in docusaurus.config.js" | ||
algolia: { | ||
// The application ID provided by Algolia | ||
appId: "NSRFPEJ4NC", # // cspell:disable-line | ||
// Public API key: it is safe to commit it | ||
apiKey: "cea41b975ad6c9a01408dfda6e0061d3", | ||
indexName: "docs-template", // Ping #documentation on Slack for your index name | ||
// Optional: see doc section below | ||
contextualSearch: true, | ||
// Optional: Specify domains where the navigation should occur through window.location instead on history.push. Useful when our Algolia config crawls multiple documentation sites and we want to navigate with window.location.href to them. | ||
externalUrlRegex: "external\\.com|domain\\.com", | ||
// Optional: Algolia search parameters | ||
searchParameters: {}, | ||
// Optional: path for search page that enabled by default (`false` to disable it) | ||
searchPagePath: "search", | ||
// ... other Algolia params | ||
}, | ||
``` | ||
|
||
This is to ensure that Algolia search bar is overridden by the plugin. | ||
|
||
4. Apply the config options for the local plugin, like below under `config > themes` in `docusaurus.config.js`: | ||
|
||
```js | ||
themes: [ | ||
[ | ||
require.resolve("@easyops-cn/docusaurus-search-local"), | ||
/** @type {import("@easyops-cn/docusaurus-search-local").PluginOptions} */ | ||
({ | ||
hashed: true, | ||
docsRouteBasePath: "/", | ||
indexBlog: false, | ||
}), | ||
], | ||
], | ||
``` | ||
|
||
:::tip | ||
|
||
You can find more options that you supply the plugin for your needs [here](https://github.com/easyops-cn/docusaurus-search-local#theme-options). | ||
|
||
::: |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,113 @@ | ||
--- | ||
sidebar_position: 7 | ||
--- | ||
|
||
# Production deployment | ||
|
||
The recommended method to deploying your docs site is by using [**Vercel**](https://vercel.com/). | ||
|
||
The main benefits of using Vercel over GitHub Pages is the ease of integration with GitHub repos and also deploying automatic previews on Pull Requests. The only caveat is that private GitHub repos require all pushes to a PR to also be members of the Vercel account which increases the cost of the subscription. In such a case, there is a workaround that allows Vercel to still host the docs and provide previews but requires a little more setup. | ||
|
||
## Scenario A: Public GitHub repo | ||
|
||
Once you are ready to deploy to Vercel, ensure that you have done the following: | ||
|
||
1. Copy the `vercel.json` file in the root of this template repo to the root of your documentation repo | ||
|
||
1. This file contains some URL redirects from older MkDocs docs that we had at the company before we moved to Docusaurus. If your documentation did not pre-exist in MkDocs, then you can remove these fields. | ||
|
||
:::caution | ||
|
||
Please ensure the `cleanUrls` is set to true and specified in the `vercel.json`. This is necessary to make sure that Vercel deploys the app properly without expecting trailing slashes. | ||
|
||
::: | ||
|
||
2. Determine the public URL that you want to use to expose the docs site. It is common practice for the URL to follow the format of `https://docs.<YOUR_PRODUCT>.consensys.net`; however, that may be different depending on your needs. | ||
3. Join the [#documentation](https://consensys.slack.com/archives/C0272B5P1CY) Slack channel and ask for Vercel integration for your repo. Make sure to provide a link to your repo in your message. | ||
|
||
Once integration has occurred, any new PRs should have a Vercel bot update with a preview link on all new commits to that PR. | ||
|
||
<details> | ||
<summary> | ||
See example Github comment | ||
</summary> | ||
<div> | ||
<img src={require("./img/vercelGithubComment.png").default} alt="vercelGithub" /> | ||
</div> | ||
</details> | ||
|
||
## Scenario B: Private GitHub repo | ||
|
||
1. Join the [#documentation](https://consensys.slack.com/archives/C0272B5P1CY) Slack channel and ask for Vercel integration for your **_private_** repo. Make sure to provide a link to your repo in your message. | ||
2. Your `build.yml` file under `.github/workflows` will be modified to look like below (you **do not** need to take this action yourself). Essentially, we will bypass the Vercel limitation by having GitHub Actions build and push the static build directly to Vercel. The Action will also take care of commenting the preview URLs in the PR on new commits. | ||
|
||
<details> | ||
<summary> | ||
Updated <code>build.yml</code> | ||
</summary> | ||
<div> | ||
|
||
```yaml title=".github/workflows/build.yml" | ||
--- | ||
name: Build and Preview | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
# the environment to deploy to / use secrets from | ||
environment: vercel | ||
# modify the default permissions of the GITHUB_TOKEN, so as to only allow least privileges | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
uses: ConsenSys/docs-gha/build@main | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- run: cp vercel.json ./build | ||
- uses: amondnet/vercel-action@v25.1.1 # // cspell:disable-line | ||
id: vercel-action-staging | ||
if: github.event_name == 'pull_request' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
vercel-token: ${{ secrets.VERCEL_TOKEN }} | ||
vercel-org-id: ${{ secrets.ORG_ID }} | ||
vercel-project-id: ${{ secrets.PROJECT_ID }} | ||
working-directory: ./build | ||
scope: infura-web | ||
- uses: amondnet/vercel-action@v25.1.1 # // cspell:disable-line | ||
id: vercel-action-production | ||
if: github.event_name == 'push' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
vercel-token: ${{ secrets.VERCEL_TOKEN }} | ||
vercel-org-id: ${{ secrets.ORG_ID }} | ||
vercel-project-id: ${{ secrets.PROJECT_ID }} | ||
working-directory: ./build | ||
vercel-args: "--prod " | ||
scope: infura-web | ||
github-comment: false | ||
``` | ||
</div> | ||
</details> | ||
<details> | ||
<summary> | ||
Example Action comment in PR | ||
</summary> | ||
<div> | ||
<img src={require("./img/privateRepoVercel.png").default} alt="privateRepoVercel" /> | ||
</div> | ||
</details> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
5234c4a
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.
Successfully deployed to the following URLs:
docs-template – ./
docs-template-git-main-infura-web.vercel.app
docs-template-consensys.vercel.app
docs-template-infura-web.vercel.app