aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-10-23 10:36:16 +0200
committerGitHub <[email protected]>2022-10-23 10:36:16 +0200
commit7d39ef7babd89e10cded0769726084f92a62c4c6 (patch)
treec264fa92545d63bbf834bc012c8448a23c92960d /docs
parentb983ca11922d3c6b07499adbe2089081a9a69083 (diff)
downloadfaker-7d39ef7babd89e10cded0769726084f92a62c4c6.tar.xz
faker-7d39ef7babd89e10cded0769726084f92a62c4c6.zip
docs: link to next docs and vice versa (#1438)
Diffstat (limited to 'docs')
-rw-r--r--docs/.vitepress/versions.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/docs/.vitepress/versions.ts b/docs/.vitepress/versions.ts
index c82a5ee0..7d37619d 100644
--- a/docs/.vitepress/versions.ts
+++ b/docs/.vitepress/versions.ts
@@ -1,7 +1,58 @@
+import { execSync } from 'node:child_process';
+import * as semver from 'semver';
import { version } from '../../package.json';
-export const currentVersion = `v${version}`;
+function readBranchName(): string {
+ return (
+ execSync('git branch --show-current').toString('utf8').trim() || 'unknown'
+ );
+}
+function readOtherLatestReleaseTagNames(): string[] {
+ const currentMajorVersion = semver.major(version);
+ const latestReleaseTagNames = execSync('git tag -l')
+ .toString('utf8')
+ .split('\n')
+ .filter((tag) => semver.valid(tag))
+ .reduce<Record<number, string[]>>((acc, tag) => {
+ const majorVersion = semver.major(tag);
+ // Only consider tags for our deployed website versions,
+ // excluding the current major version.
+ if (majorVersion >= 6 && majorVersion !== currentMajorVersion) {
+ (acc[majorVersion] = acc[majorVersion] ?? []).push(tag);
+ }
+ return acc;
+ }, {});
+ return Object.entries(latestReleaseTagNames)
+ .map(([major, tags]) => semver.maxSatisfying(tags, `^${major}`))
+ .sort(semver.rcompare);
+}
+
+// Set by netlify
+const {
+ CONTEXT: deployContext = 'local',
+ 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);
+
+export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
export const oldVersions = [
- { version: 'v6.3.1', link: 'https://v6.fakerjs.dev/' },
-];
+ {
+ version: 'latest',
+ link: 'https://fakerjs.dev/',
+ },
+ {
+ version: 'next',
+ link: 'https://next.fakerjs.dev/',
+ },
+ ...otherVersions.map((version) => ({
+ version,
+ link: `https://v${semver.major(version)}.fakerjs.dev/`,
+ })),
+].filter(({ link }) => link !== hiddenLink);