Skip to content
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

Add Docusaurus site source #1

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "CodeQL"

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
12 changes: 12 additions & 0 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Dependency Review

on:
pull_request:

jobs:
dependency-review:
uses: gravitational/shared-workflows/.github/workflows/dependency-review.yaml@main
permissions:
contents: read
with:
allow-dependencies-licenses: 'pkg:npm/%40inkeep/widgets, pkg:npm/domain-browser'
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.env
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Docs
versioned_docs/*
!versioned_docs/.gitkeep
versioned_sidebars/*
!versioned_sidebars/.gitkeep
docs/*
!docs/.gitkeep
sidebars.json
static/assets/*
versions.json
data/*
!data/.gitkeep

# Migration node dependencies
.build
16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[submodule "content/14.x"]
path = content/14.x
url = https://github.com/gravitational/teleport/
branch = branch/v14
[submodule "content/15.x"]
path = content/15.x
url = https://github.com/gravitational/teleport/
branch = branch/v15
[submodule "content/16.x"]
path = content/16.x
url = https://github.com/gravitational/teleport/
branch = branch/v16
[submodule "content/17.x"]
path = content/17.x
url = https://github.com/gravitational/teleport/
branch = master
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.12.2
118 changes: 116 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,116 @@
# docs-website
Teleport documentation website using Docusaurus
# Website

This a port of the Teleport docs from the original custom engine to [Docusaurus](https://docusaurus.io/).

## Installation

```
$ yarn
```

Create `.env` file with variables: `SANITY_PROJECT_ID` and `SANITY_DATASET` tom make menu and events work.

## Local Development

```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

## Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

## Deployment

Deployment happens automatically to commits to the `main` branch. Deploy is woriking thought AWS Amplify.

Settings for AWS Amplify are following:

1. `nodejs` 20 and `yarn` v1.22.22.
2. Build command `yarn build`
4. Build results folder `build`
5. Following env variables should be set: `INKEEP_API_KEY`, `INKEEP_INTEGRATION_ID`, `INKEEP_ORGANIZATION_ID`, `YOUTUBE_API_KEY`, `SANITY_PROJECT_ID`, `SANITY_DATASET`.
6. This variable should be set increase nodejs memory `NODE_OPTIONS=--max-old-space-size=8192`
7. Add the following redirect to make 404 work:
- Source address: `/<*>`
- Target address: `/404.html`
- Type `404 (Rewrite)`

## Architecture overview

Current setup is made with the goal to make this project backward compatible with the original [docs engine](https://github.com/gravitational/docs) so they can run in parallel until transition period is not over.

To make it possible, we convert content from the orginal format to the Docusaurus format at the build time and also use some of the orignal plugins.

How it works under the hood:

1. We store docs in the git submodules of the main `teleport` repo as in the original setup. Submodules are fetched inside `content` folder to the subfolders named after the teleport versions `15.x`, `16.x`, etc. Then we build the docs we update submodules to the latest version.
2. Info about versions, their status and original branches are manually added to the `config.json` file. See version config description below.
3. To make old docs work with Ducsaurus we need to move files to correct location and also generate a bunch of config files. To do it we use `scripts/prepare-files.mts` file. It does the following based on `config.json` content:
1. Move mdx files, except `includes` to the `versioned_docs/version-{name}` folder for the non-current versions.
2. Move mdx files, except `includes` to the `docs` folder for the `current` version.
3. Create `versioned_sidebars/version-{name}-sidebars.json` configs for sidebars of the non-current versions.
4. Create `sidebars.json` config for sidebar of the `current` version.
5. Create `versions.json` file with the list of non-current versions.
4. To make old docs work with Docusaurus we also need to run them through a bunch of custom plugins:
1. `remark-includes` - plugin from the old docs to work with the `(!filepath!)` syntax.
2. `remark-variables` - plugin from the old docs to work with the `(=variable=)` syntax.
3. `remark-update-asset-paths` - this plugn updates paths to the assets from new folders to the `content/{version}` folders.
4. `remark-update-tags` - this plugin replaces custom components used in the old docs to their Docuaaurus alternatives or removes them completely.

Everything else is more or less straightforward Docusaurus code.

### Folder structure

`content` – folder for docs content.
`scripts` – helper CLI scripts.
`server` – code for plugins, and config parsing.
`src` - forntend-related files.
`src/component` – components ported from the old site, mostly header-related.
`src/styles` – css used in header.
`src/theme` – overrides for default theme files of Docusaurus
`src/utls` – client-side utils.
`staitc` - static files for the site: manifests, favicons, etc.

`docs`, `versioned_docs` are `versioned_sidebars` – folders for docs content that will be automatically populated by script.

`data` is a folder for sanity content.

### `config.json` format

```
type Version = {
name: string; // should be the same as the folder in `content`
branch: string; // name of the original git branch
deprecated: boolean; // Unsupported versions
latest: boolean; // Last officially released version
current: boolean; // Next version currently in development
}
type Config = {
versions: Version[]
}
```

Only non-deprecated versions are built in the docs.

If no versions are marked as `current`/`latest`, last version in alphabetical order is marked as it.

### CLI commands

`yarn git-update` – update git modules.
`yarn prepare-files` – copy files from `content` to docusaurus folders.
`yarn prepare-sanity-data` - fetching and saving data form navigation for Sanity.
`yarn start` – start server in dev mode.
`yarn build` - buld static site.
`yarn swizzle` - used to eject files from default Docusaurus theme to `src/theme` folder. `see [swizzling](https://docusaurus.io/docs/swizzling).
`yarn serve` – server static files.
`yarn typecheck` - check types.

For other commands see [Docusaurus docs](https://docusaurus.io/docs/cli#docusaurus-cli-commands).
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
82 changes: 82 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"versions": [
{
"name": "4.4",
"branch": "branch/4.4",
"deprecated": true
},
{
"name": "5.0",
"branch": "branch/5.0",
"deprecated": true
},
{
"name": "6.0",
"branch": "branch/v6.0",
"deprecated": true
},
{
"name": "6.1",
"branch": "branch/v6.1",
"deprecated": true
},
{
"name": "6.2",
"branch": "branch/v6.2",
"deprecated": true
},
{
"name": "7.x",
"branch": "branch/v7",
"deprecated": true
},
{
"name": "8.x",
"branch": "branch/v8",
"deprecated": true
},
{
"name": "9.x",
"branch": "branch/v9",
"deprecated": true
},
{
"name": "10.x",
"branch": "branch/v10",
"deprecated": true
},
{
"name": "11.x",
"branch": "branch/v11",
"deprecated": true
},
{
"name": "12.x",
"branch": "branch/v12",
"deprecated": true
},
{
"name": "13.x",
"branch": "branch/v13",
"deprecated": true
},
{
"name": "14.x",
"branch": "branch/v14"
},
{
"name": "15.x",
"branch": "branch/v15"
},
{
"name": "16.x",
"branch": "master",
"latest": true
},
{
"name": "17.x",
"branch": "master",
"current": true
}
]
}
1 change: 1 addition & 0 deletions content/14.x
Submodule 14.x added at 5aed8c
1 change: 1 addition & 0 deletions content/15.x
Submodule 15.x added at 283729
1 change: 1 addition & 0 deletions content/16.x
Submodule 16.x added at 65f48f
1 change: 1 addition & 0 deletions content/17.x
Submodule 17.x added at 69a1e7
Empty file added data/.gitkeep
Empty file.
Empty file added docs/.gitkeep
Empty file.
Loading
Loading