Skip to content

Commit 21a1d98

Browse files
committed
Update document
1 parent 1e4db4d commit 21a1d98

File tree

3 files changed

+167
-16
lines changed

3 files changed

+167
-16
lines changed

.github/workflows/doc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
ref: gh-pages
3030
- name: Find variables
3131
id: vars
32-
# if on master branch push, use "dev", otherwise major.minor
32+
# if on master branch push, use "dev", otherwise major
3333
run: |
34-
[ "$GITHUB_REF_NAME" = "master" ] && (echo version=dev >> $GITHUB_OUTPUT) || (echo version=$GITHUB_REF_NAME | cut -d "." -f 1,2 >> $GITHUB_OUTPUT)
34+
[ "$GITHUB_REF_NAME" = "master" ] && (echo version=dev >> $GITHUB_OUTPUT) || (echo version=$GITHUB_REF_NAME | cut -d "." -f 1 >> $GITHUB_OUTPUT)
3535
echo git_msg=\"$(git log -1 --pretty=format:'%s')\" >> $GITHUB_OUTPUT
3636
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
37-
- name: build site
37+
- name: Build site
3838
run: |
3939
rm -rf site/${{ steps.vars.outputs.version }}
4040
mv docs site/${{ steps.vars.outputs.version }}

README.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
# Version Select Plugin for Typedoc
1+
# Version Select Plugin for TypeDoc
22

3-
This plugin adds a version select drop-down besides the title.
3+
This plugin adds a version select drop-down menu beside the title of the TypeDoc generated document.
44

5-
A json file describing the items in this select is loaded dynamically.
5+
TypeDoc generates documentation for current version as a sub-site,
6+
allowing you to manage the overall site organization.
7+
8+
A dynamically loaded JSON file provides the data of items for the version select.
69

7-
Typedoc will generate the doc of the current version as a sub-site.
8-
You can manage how the entire site is organized.
910

1011
# Usage
1112

12-
## Install the plugin
13+
## Install the plugin using npm:
1314

1415
```sh
1516
npm install --save-dev typedoc-plugin-version-select
1617
```
1718

18-
## Apply the plugin in the config
19+
## Apply the plugin to your configuration file:
1920

2021
```json
2122
"plugin": ["typedoc-plugin-version-select"],
@@ -24,25 +25,39 @@ npm install --save-dev typedoc-plugin-version-select
2425
## Options
2526

2627
Option `versionSpecHRef` is used to customize the url of the version data file.
27-
It can be an absolute URL or a relative path.
28-
The default value of this option is `../versions.json`.
28+
This option can be set to an absolute URL or a relative path.
29+
The default value is `../versions.json`.
2930

3031
## Format of version spec file
3132

32-
It is a json file of an array, each item represent one version.
33+
The version spec file is a JSON file containing an array of items, where each item represents a version.
3334

3435
| Key | Description |
3536
|-|-|
3637
| version | The version string displayed in the version select |
3738
| url | The URL of the sub-site of this version |
3839

40+
Here’s an example of the version spec file:
41+
42+
```json
43+
[
44+
{
45+
“version”: “1.0.0”,
46+
“url”: “https://jameslan.github.io/typedoc-plugin-version-select/1.0.0”
47+
},
48+
{
49+
“version”: “1.1.0”,
50+
“url”: “https://jameslan.github.io/typedoc-plugin-version-select/1.1.0”
51+
}
52+
]
53+
```
3954

40-
# Example
55+
# Demo
4156

42-
The doc site of this plugin hosted on GitHub is an example of itself.
57+
The documentation site of this plugin hosted on GitHub is an example of itself.
4358

4459
https://jameslan.github.io/typedoc-plugin-version-select/
4560

46-
# Compatible Typedoc versions
61+
# Compatible TypeDoc versions
4762

4863
- 0.27.x

example.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,137 @@
11
# How This Site Is Built
2+
3+
## Hosting
4+
5+
This documentation site is stored in the `gh-pages` branch and hosted on GitHub Pages.
6+
7+
To create a standalone branch, separate from your source code branches, you can use the `--orphan` argument of git:
8+
9+
```sh
10+
git switch --orphan gh-pages
11+
touch .nojekyll
12+
git add .nojekyll
13+
git commit -m "Initial commit for web site storing branch"
14+
git push --set-upstream origin gh-pages
15+
```
16+
17+
The `.nojekyll` file is used to prevent Jekyll from processing the files stored in this branch.
18+
19+
Now, go to the project's `Settings` tab on GitHub to set up your Pages site.
20+
21+
Under the `Build and deployment` section in the `Pages` section,
22+
set the `Source` to `Deploy from a branch` and the `Branch` to the root directory of the `gh-pages` branch.
23+
24+
This will create an empty site that can be accessed even without a homepage.
25+
26+
## Directory Structure
27+
28+
Here’s the file structure of the `gh-pages` branch, which is also this documentation site:
29+
30+
```
31+
gh-pages
32+
|-index.html
33+
|-versions.json
34+
|-.nojekyll
35+
|-dev
36+
| |-index.html
37+
| |-modules.html
38+
| |-.nojekyll
39+
| |-functions
40+
| | |-index.load.html
41+
| |-documents
42+
| | |-example.html
43+
| |-modules
44+
| | |-index.html
45+
| |-assets
46+
| | |-icons.js
47+
| | |-hierarchy.js
48+
| | |-highlight.css
49+
| | |-version-select.css
50+
| | |-main.js
51+
| | |-version-select.js
52+
| | |-navigation.js
53+
| | |-style.css
54+
| | |-search.js
55+
| | |-icons.svg
56+
|-v1
57+
| |-index.html
58+
| |-modules.html
59+
| |-.nojekyll
60+
| |-functions
61+
| | |-index.load.html
62+
| |-documents
63+
| | |-example.html
64+
| |-modules
65+
| | |-index.html
66+
| |-assets
67+
| | |-icons.js
68+
| | |-hierarchy.js
69+
| | |-highlight.css
70+
| | |-version-select.css
71+
| | |-main.js
72+
| | |-version-select.js
73+
| | |-navigation.js
74+
| | |-style.css
75+
| | |-search.js
76+
| | |-icons.svg
77+
|-.git
78+
```
79+
80+
### Document for multiple versions
81+
82+
This document contains multiple versions of the website.
83+
84+
The first-level directories, `dev` and `v1`, represent two different versions.
85+
86+
- When the `master` branch has a new commit,
87+
a GitHub workflow generates the updated document and commits it to the `dev` directory in the `gh-pages` branch.
88+
- When a new version `1.*.*` is released,
89+
the generated document is checked into the `v1` directory.
90+
91+
Once the content in the `gh-pages` branch changes,
92+
GitHub deploys the updated assets to GitHub Pages.
93+
94+
### index.html
95+
96+
The website needs to redirect the browser to the default version when the user accesses the root homepage.
97+
Since GitHub Pages doesn’t allow you to configure redirect responses,
98+
we use the `<meta>` tag in the [index.html](https://github.com/jameslan/typedoc-plugin-version-select/blob/gh-pages/index.html#L7) head to make the browser jump to another URL.
99+
100+
This file needs to be manually updated when the default version changes.
101+
For example, a new major version is released and stored in a new directory,
102+
so it becomes the new default version.
103+
104+
### versions.json
105+
106+
[versions.json](https://github.com/jameslan/typedoc-plugin-version-select/blob/gh-pages/versions.json) contains the configuration of the content of the version select dropdown menu.
107+
108+
## GitHub Action
109+
110+
This project uses [a GitHub workflow](https://github.com/jameslan/typedoc-plugin-version-select/blob/master/.github/workflows/doc.yml) to automatically generate and check-in the document site.
111+
112+
### Triggering
113+
114+
The workflow is triggered when a new commit is pushed to the `master` branch or a new release is published.
115+
116+
### Permission
117+
118+
Since we need to commit to the `gh-pages` branch and push,
119+
we require write permission.
120+
121+
### Steps
122+
123+
- In the step `Checkout the site branch`, we check out `gh-pages` branch into directory `site`.
124+
- In the step `Build doc`, the documents are built into `docs` directory.
125+
Due to our directory structure,
126+
the default value of option `versionSpecHRef` works, so we don't need to customize it.
127+
- In the step `Find variables`, shell script is used to set up some workflow variables
128+
- In the `Find variables` step, a shell script is employed to set up essential workflow variables,
129+
including the version (directory name) and commit message.
130+
This step is identified by the id `vars` to facilitate referencing of these variables as `steps.vars.outputs.*`.
131+
- Next, in the `Build site` step, the newly generated documents replace the subdirectory.
132+
- Finally, in the `Commit to site branch` step, the changes are committed and pushed to the `gh-pages` branch.
133+
134+
By executing these steps, the documentation site is automatically updated in accordance with the latest commit.
135+
136+
However, it’s important to note that this workflow does not update the `versions.json` file.
137+
Therefore, manual updates to this file are necessary when required.

0 commit comments

Comments
 (0)