Skip to content

docs: link to the latest release of the current version #2856

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

Merged
merged 2 commits into from
Apr 30, 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
4 changes: 2 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { apiPages } from './api-pages';
import {
algoliaIndex,
currentVersion,
oldVersions,
versionBannerInfix,
versionLinks,
} from './versions';

type SidebarItem = DefaultTheme.SidebarItem;
Expand Down Expand Up @@ -225,7 +225,7 @@ const config: UserConfig<DefaultTheme.Config> = {
text: 'Release Notes',
link: 'https://github.com/faker-js/faker/releases',
},
...oldVersions.map(({ version, link }) => ({
...versionLinks.map(({ version, link }) => ({
text: version,
link,
})),
Expand Down
24 changes: 7 additions & 17 deletions docs/.vitepress/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ function readBranchName(): string {
}

function readOtherLatestReleaseTagNames(): string[] {
const currentMajorVersion = semver.major(version);
const latestReleaseTagNames = execSync('git tag -l')
.toString('utf8')
.split('\n')
.filter((tag) => semver.valid(tag))
.filter((tag) => {
// Only consider tags for our deployed website versions,
// excluding the current major version.
const majorVersion = semver.major(tag);
return majorVersion >= 6 && majorVersion !== currentMajorVersion;
})
// Only consider tags for our deployed website versions
.filter((tag) => semver.major(tag) >= 6)
// Find the latest tag for each major version
.reduce<Record<number, string>>((latestTagByMajor, tag) => {
const majorVersion = semver.major(tag);

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

const hiddenLink =
deployContext === 'production'
? 'https://fakerjs.dev/'
: `https://${branchName}.fakerjs.dev/`;
const otherVersions = readOtherLatestReleaseTagNames();
const isReleaseBranch = /^v\d+$/.test(branchName);

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

export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
export const oldVersions = [
{
version: 'latest',
link: 'https://fakerjs.dev/',
},
export const versionLinks = [
{
version: 'next',
link: 'https://next.fakerjs.dev/',
Expand All @@ -73,7 +61,9 @@ export const oldVersions = [
version,
link: `https://v${semver.major(version)}.fakerjs.dev/`,
})),
].filter(({ link }) => link !== hiddenLink);
]
// Don't link to the current branch's version.
.filter(({ link }) => link !== `https://${branchName}.fakerjs.dev/`);

export const algoliaIndex = isReleaseBranch
? `fakerjs-v${semver.major(version)}`
Expand Down
13 changes: 4 additions & 9 deletions test/docs/versions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process';
import * as semver from 'semver';
import { describe, expect, it } from 'vitest';
import { oldVersions } from '../../docs/.vitepress/versions';
import { versionLinks } from '../../docs/.vitepress/versions';

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

expect(oldVersions[0]).toEqual({
version: 'latest',
link: 'https://fakerjs.dev/',
});

const versionEntry = oldVersions[1];
const versionEntry = versionLinks[0];
if (versionEntry.version === 'next') {
expect(versionEntry.link).toBe('https://next.fakerjs.dev/');
}

const releaseVersions = oldVersions.filter(({ version }) =>
const releaseVersions = versionLinks.filter(({ version }) =>
semver.valid(version)
);
const latestMajorRelease = semver.major(releaseVersions[0].version);
Expand Down