Skip to content

Commit 13dc420

Browse files
authored
docs: link to the latest release of the current version (#2856)
1 parent b87acb8 commit 13dc420

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { apiPages } from './api-pages';
44
import {
55
algoliaIndex,
66
currentVersion,
7-
oldVersions,
87
versionBannerInfix,
8+
versionLinks,
99
} from './versions';
1010

1111
type SidebarItem = DefaultTheme.SidebarItem;
@@ -225,7 +225,7 @@ const config: UserConfig<DefaultTheme.Config> = {
225225
text: 'Release Notes',
226226
link: 'https://github.com/faker-js/faker/releases',
227227
},
228-
...oldVersions.map(({ version, link }) => ({
228+
...versionLinks.map(({ version, link }) => ({
229229
text: version,
230230
link,
231231
})),

docs/.vitepress/versions.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ function readBranchName(): string {
99
}
1010

1111
function readOtherLatestReleaseTagNames(): string[] {
12-
const currentMajorVersion = semver.major(version);
1312
const latestReleaseTagNames = execSync('git tag -l')
1413
.toString('utf8')
1514
.split('\n')
1615
.filter((tag) => semver.valid(tag))
17-
.filter((tag) => {
18-
// Only consider tags for our deployed website versions,
19-
// excluding the current major version.
20-
const majorVersion = semver.major(tag);
21-
return majorVersion >= 6 && majorVersion !== currentMajorVersion;
22-
})
16+
// Only consider tags for our deployed website versions
17+
.filter((tag) => semver.major(tag) >= 6)
18+
// Find the latest tag for each major version
2319
.reduce<Record<number, string>>((latestTagByMajor, tag) => {
2420
const majorVersion = semver.major(tag);
2521

@@ -39,10 +35,6 @@ const {
3935
BRANCH: branchName = readBranchName(),
4036
} = process.env;
4137

42-
const hiddenLink =
43-
deployContext === 'production'
44-
? 'https://fakerjs.dev/'
45-
: `https://${branchName}.fakerjs.dev/`;
4638
const otherVersions = readOtherLatestReleaseTagNames();
4739
const isReleaseBranch = /^v\d+$/.test(branchName);
4840

@@ -60,11 +52,7 @@ export const versionBannerInfix: string | null = (() => {
6052
})();
6153

6254
export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
63-
export const oldVersions = [
64-
{
65-
version: 'latest',
66-
link: 'https://fakerjs.dev/',
67-
},
55+
export const versionLinks = [
6856
{
6957
version: 'next',
7058
link: 'https://next.fakerjs.dev/',
@@ -73,7 +61,9 @@ export const oldVersions = [
7361
version,
7462
link: `https://v${semver.major(version)}.fakerjs.dev/`,
7563
})),
76-
].filter(({ link }) => link !== hiddenLink);
64+
]
65+
// Don't link to the current branch's version.
66+
.filter(({ link }) => link !== `https://${branchName}.fakerjs.dev/`);
7767

7868
export const algoliaIndex = isReleaseBranch
7969
? `fakerjs-v${semver.major(version)}`

test/docs/versions.spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from 'node:child_process';
22
import * as semver from 'semver';
33
import { describe, expect, it } from 'vitest';
4-
import { oldVersions } from '../../docs/.vitepress/versions';
4+
import { versionLinks } from '../../docs/.vitepress/versions';
55

66
function isFakerOrigin(): boolean {
77
try {
@@ -22,19 +22,14 @@ function isFakerOrigin(): boolean {
2222
describe.runIf(isFakerOrigin())('docs versions', () => {
2323
describe('oldVersions', () => {
2424
it('should have a complete set of oldVersions', () => {
25-
expect(oldVersions.length).toBeGreaterThanOrEqual(2);
25+
expect(versionLinks.length).toBeGreaterThanOrEqual(1);
2626

27-
expect(oldVersions[0]).toEqual({
28-
version: 'latest',
29-
link: 'https://fakerjs.dev/',
30-
});
31-
32-
const versionEntry = oldVersions[1];
27+
const versionEntry = versionLinks[0];
3328
if (versionEntry.version === 'next') {
3429
expect(versionEntry.link).toBe('https://next.fakerjs.dev/');
3530
}
3631

37-
const releaseVersions = oldVersions.filter(({ version }) =>
32+
const releaseVersions = versionLinks.filter(({ version }) =>
3833
semver.valid(version)
3934
);
4035
const latestMajorRelease = semver.major(releaseVersions[0].version);

0 commit comments

Comments
 (0)