From 13dc42054abc6188c314acf98cec73f0283072c2 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 30 Apr 2024 08:09:44 +0200 Subject: [PATCH] docs: link to the latest release of the current version (#2856) --- docs/.vitepress/config.ts | 4 ++-- docs/.vitepress/versions.ts | 24 +++++++----------------- test/docs/versions.spec.ts | 13 ++++--------- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 3bb9c9355ba..b226f441971 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -4,8 +4,8 @@ import { apiPages } from './api-pages'; import { algoliaIndex, currentVersion, - oldVersions, versionBannerInfix, + versionLinks, } from './versions'; type SidebarItem = DefaultTheme.SidebarItem; @@ -225,7 +225,7 @@ const config: UserConfig = { text: 'Release Notes', link: 'https://github.com/faker-js/faker/releases', }, - ...oldVersions.map(({ version, link }) => ({ + ...versionLinks.map(({ version, link }) => ({ text: version, link, })), diff --git a/docs/.vitepress/versions.ts b/docs/.vitepress/versions.ts index a44b65c39ba..9d693e3d730 100644 --- a/docs/.vitepress/versions.ts +++ b/docs/.vitepress/versions.ts @@ -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>((latestTagByMajor, tag) => { const majorVersion = semver.major(tag); @@ -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); @@ -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/', @@ -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)}` diff --git a/test/docs/versions.spec.ts b/test/docs/versions.spec.ts index 777efcb2c9c..5567fd7323f 100644 --- a/test/docs/versions.spec.ts +++ b/test/docs/versions.spec.ts @@ -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 { @@ -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);