Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 27b1e5b

Browse files
committed
Add docs version on 2.3.0
1 parent d2d1675 commit 27b1e5b

19 files changed

Lines changed: 524 additions & 1 deletion

File tree

docs/docusaurus.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ const config = {
9595
label: 'Changelog',
9696
docsPluginId: 'changelog',
9797
},
98+
{
99+
type: 'docsVersionDropdown',
100+
position: 'right',
101+
dropdownItemsAfter: [{to: '/versions', label: 'All versions'}],
102+
},
98103
{
99104
href: 'https://github.com/axelrindle/github-version-checker',
100-
label: 'GitHub',
101105
position: 'right',
102106
className: 'nav-icon-link nav-github-link',
103107
'aria-label': 'GitHub',

docs/src/pages/versions.tsx

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found at
5+
* https://github.com/facebook/docusaurus/blob/f22da5ac125cb128b8e1081969f82d4100cbc645/LICENSE
6+
*/
7+
// Copied from https://github.com/facebook/docusaurus/blob/f22da5ac125cb128b8e1081969f82d4100cbc645/website/src/pages/versions.tsx
8+
9+
import React from 'react'
10+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
11+
import Link from '@docusaurus/Link'
12+
import Translate from '@docusaurus/Translate'
13+
import {
14+
useVersions,
15+
useLatestVersion,
16+
} from '@docusaurus/plugin-content-docs/client'
17+
import Layout from '@theme/Layout'
18+
import Heading from '@theme/Heading'
19+
//import VersionsArchived from '@site/versionsArchived.json';
20+
21+
const docsPluginId = undefined // Default docs plugin instance
22+
23+
//const VersionsArchivedList = Object.entries(VersionsArchived);
24+
const VersionsArchivedList = Object.entries([])
25+
26+
function DocumentationLabel() {
27+
return (
28+
<Translate id="versionsPage.versionEntry.link">Documentation</Translate>
29+
)
30+
}
31+
32+
function ReleaseNotesLabel() {
33+
return (
34+
<Translate id="versionsPage.versionEntry.releaseNotes">
35+
Release Notes
36+
</Translate>
37+
)
38+
}
39+
40+
export default function Version(): JSX.Element {
41+
const {
42+
siteConfig: { organizationName, projectName },
43+
} = useDocusaurusContext()
44+
const versions = useVersions(docsPluginId)
45+
const latestVersion = useLatestVersion(docsPluginId)
46+
const currentVersion = versions.find(
47+
(version) => version.name === 'current',
48+
)!
49+
const pastVersions = versions.filter(
50+
(version) => version !== latestVersion && version.name !== 'current',
51+
)
52+
const repoUrl = `https://github.com/${organizationName!}/${projectName!}`
53+
54+
return (
55+
<Layout
56+
title="Versions"
57+
description="Docusaurus 2 Versions page listing all documented site versions">
58+
<main className="container margin-vert--lg">
59+
<Heading as="h1">
60+
<span>
61+
{projectName}
62+
</span>
63+
&nbsp;
64+
<Translate id="versionsPage.title">
65+
documentation versions
66+
</Translate>
67+
</Heading>
68+
69+
<div className="margin-bottom--lg">
70+
<Heading as="h3" id="next">
71+
<Translate id="versionsPage.current.title">
72+
Current version (Stable)
73+
</Translate>
74+
</Heading>
75+
<p>
76+
<Translate id="versionsPage.current.description">
77+
Here you can find the documentation for current released version.
78+
</Translate>
79+
</p>
80+
<table>
81+
<tbody>
82+
<tr>
83+
<th>{latestVersion.label}</th>
84+
<td>
85+
<Link to={latestVersion.path}>
86+
<DocumentationLabel />
87+
</Link>
88+
</td>
89+
<td>
90+
<Link to={`${repoUrl}/releases/tag/v${latestVersion.name}`}>
91+
<ReleaseNotesLabel />
92+
</Link>
93+
</td>
94+
</tr>
95+
</tbody>
96+
</table>
97+
</div>
98+
99+
{currentVersion !== latestVersion && (
100+
<div className="margin-bottom--lg">
101+
<Heading as="h3" id="latest">
102+
<Translate id="versionsPage.next.title">
103+
Next version (Unreleased)
104+
</Translate>
105+
</Heading>
106+
<p>
107+
<Translate id="versionsPage.next.description">
108+
Here you can find the documentation for work-in-process
109+
unreleased version.
110+
</Translate>
111+
</p>
112+
<table>
113+
<tbody>
114+
<tr>
115+
<th>{currentVersion.label}</th>
116+
<td>
117+
<Link to={currentVersion.path}>
118+
<DocumentationLabel />
119+
</Link>
120+
</td>
121+
</tr>
122+
</tbody>
123+
</table>
124+
</div>
125+
)}
126+
127+
{(pastVersions.length > 0 || VersionsArchivedList.length > 0) && (
128+
<div className="margin-bottom--lg">
129+
<Heading as="h3" id="archive">
130+
<Translate id="versionsPage.archived.title">
131+
Past versions (Not maintained anymore)
132+
</Translate>
133+
</Heading>
134+
<p>
135+
<Translate id="versionsPage.archived.description">
136+
Here you can find documentation for previous versions of
137+
Docusaurus.
138+
</Translate>
139+
</p>
140+
<table>
141+
<tbody>
142+
{pastVersions.map((version) => (
143+
<tr key={version.name}>
144+
<th>{version.label}</th>
145+
<td>
146+
<Link to={version.path}>
147+
<DocumentationLabel />
148+
</Link>
149+
</td>
150+
<td>
151+
<Link href={`${repoUrl}/releases/tag/v${version.name}`}>
152+
<ReleaseNotesLabel />
153+
</Link>
154+
</td>
155+
</tr>
156+
))}
157+
{VersionsArchivedList.map(([versionName, versionUrl]) => (
158+
<tr key={versionName}>
159+
<th>{versionName}</th>
160+
<td>
161+
<Link to={versionUrl}>
162+
<DocumentationLabel />
163+
</Link>
164+
</td>
165+
<td>
166+
<Link href={`${repoUrl}/releases/tag/v${versionName}`}>
167+
<ReleaseNotesLabel />
168+
</Link>
169+
</td>
170+
</tr>
171+
))}
172+
</tbody>
173+
</table>
174+
</div>
175+
)}
176+
</main>
177+
</Layout>
178+
)
179+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
sidebar_position: 2
3+
sidebar_label: 🧩 API
4+
---
5+
6+
# API
7+
8+
```js
9+
// Require the module
10+
const versionCheck = require('github-version-checker');
11+
```
12+
13+
### `function versionCheck(options, [callback])`
14+
Performs an update check with the given options. The `callback` is optional, can be omitted to return a `Promise`.
15+
16+
#### The `options` object
17+
Option | Description | Default Value | Introduction
18+
--- | --- | --- | ---
19+
token | A [personal access token](https://blog.github.com/2013-05-16-personal-api-tokens/) used to access the **Github GraphQL API (v4)**. Can be omitted and instead be read from an env variable called `GITHUB_API_TOKEN`. When no token can be found, the module will fall back to the **Github Rest API (v3)**. | `undefined` | `v2.0.0`
20+
repo | The name of your Github repository.| **None. Required.** | `v1.0.0`
21+
owner | The owner of your Github repository (usually your username).| **None. Required.** | `v1.0.0`
22+
currentVersion | Your app's current version. | **None. Required.** | `v1.0.0`
23+
fetchTags | Whether to fetch the repositories' git tags instead of the GitHub releases. Useful when no releases are created, but only tags. | `false` | `v1.0.0`
24+
latestOnly | Setting this to `true` will fetch the latest release only | `false` | `v2.2.0`
25+
excludePrereleases | Excludes pre-releases from checks. Currently only works when no token is specified. | `false` | `v2.3.0`
26+
27+
#### The `callback` function (optional)
28+
Should be of the following form:
29+
```javascript
30+
function(error, update) {
31+
// ...your code
32+
}
33+
```
34+
* `error`:
35+
* If an error occurs, this holds the error message. `null` if no error occurs.
36+
* `update`:
37+
* An object in the format specified below. `null` if no update was found.
38+
39+
#### Using `Promise`
40+
You can omit the `callback` function to return a `Promise`, which resolves with the `update` object.
41+
42+
### Object schemes
43+
#### Releases
44+
When fetching releases, an object with the following structure will be returned:
45+
```js
46+
Object {
47+
name
48+
tag {
49+
name
50+
}
51+
isPrerelease
52+
publishedAt
53+
url
54+
}
55+
```
56+
57+
#### Tags
58+
When fetching tags, you will receive an object with the following structure:
59+
```js
60+
Object {
61+
name
62+
}
63+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "🥸 Basic",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Basic Examples"
7+
}
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Async / Await
2+
3+
The future is now! Futuristic approach leveraging top-level await.
4+
5+
```js showLineNumbers title="src/util/version-check.js"
6+
const versionCheck = require('github-version-checker')
7+
const options = {
8+
// token: '...',
9+
repo: 'github-version-checker',
10+
owner: 'axelrindle',
11+
currentVersion: require('../package.json').version
12+
}
13+
14+
try {
15+
// highlight-next-line
16+
const update = await versionCheck(options)
17+
if (update) { // update is null if there is no update available, so check here
18+
console.log('An update is available! ' + update.name)
19+
console.log('You are on version ' + options.currentVersion + '!')
20+
} else {
21+
console.log('You are up to date.')
22+
}
23+
} catch (e) {
24+
console.error(e)
25+
}
26+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Callback
2+
3+
Using a plain old callback.
4+
5+
````js showLineNumbers title="src/util/version-check.js"
6+
const versionCheck = require('github-version-checker')
7+
const options = {
8+
// token: '...',
9+
repo: 'github-version-checker',
10+
owner: 'axelrindle',
11+
currentVersion: require('../package.json').version
12+
}
13+
14+
versionCheck(options, function (error, update) {
15+
if (error) {
16+
console.error(error)
17+
process.exit(-1)
18+
}
19+
20+
if (update) {
21+
console.log('An update is available! ' + update.name)
22+
console.log('You are on version ' + options.currentVersion + '!')
23+
} else {
24+
console.log('You are up to date.')
25+
}
26+
})
27+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Promise
2+
3+
Modern version using a Promise-based approach.
4+
5+
```js showLineNumbers title="src/util/version-check.js"
6+
const versionCheck = require('github-version-checker')
7+
const options = {
8+
// token: '...',
9+
repo: 'github-version-checker',
10+
owner: 'axelrindle',
11+
currentVersion: require('../package.json').version
12+
}
13+
14+
versionCheck(options)
15+
.then(function (update) {
16+
if (update) { // update is null if there is no update available, so check here
17+
console.log('An update is available! ' + update.name)
18+
console.log('You are on version ' + options.currentVersion + '!')
19+
} else {
20+
console.log('You are up to date.')
21+
}
22+
})
23+
.catch(function (error) {
24+
console.error(error)
25+
})
26+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "👨‍🎓 Advanced",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Advanced Examples"
7+
}
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fetch Git tags instead of GitHub releases
2+
3+
In case your repository does not use GitHub releases but just Git tags a call to the
4+
releases api won't work.
5+
6+
Fetch the tags instead by setting `fetchTags` to `true`:
7+
8+
```js showLineNumbers title="src/util/version-check.js"
9+
const versionCheck = require('github-version-checker')
10+
const options = {
11+
token: 'my-token',
12+
repo: 'github-version-checker',
13+
owner: 'axelrindle',
14+
currentVersion: require('../package.json').version,
15+
// highlight-next-line
16+
fetchTags: true
17+
}
18+
19+
versionCheck(options, function (error, update) {
20+
if (error) {
21+
console.error(error)
22+
process.exit(-1)
23+
}
24+
25+
if (update) {
26+
console.log('An update is available! ' + update.name)
27+
console.log('You are on version ' + options.currentVersion + '!')
28+
} else {
29+
console.log('You are up to date.')
30+
}
31+
})
32+
```

0 commit comments

Comments
 (0)