Skip to content

Commit ffe9ac5

Browse files
committed
refactor: separate into utils, sanitize characters
1 parent 595349c commit ffe9ac5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

docusaurus.config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import {
1313
cacheAuthorData,
1414
getFileCommitHashSafe,
1515
} from "./src/util/authorUtils";
16+
import { preview, deploymentID } from "./src/util/pagesUtils";
1617

17-
const preview = isCI && env.CI_ENV === "preview";
1818
cacheAuthorData(preview || env.NODE_ENV === "development");
1919

20-
const pagesId =
21-
`${env.GITHUB_PR_HEAD_OWNER}-${env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME}`.substring(0, 28);
22-
const url = (preview && `https://${pagesId}.papermc-docs.pages.dev`) || "https://docs.papermc.io";
20+
const url =
21+
(preview && `https://${deploymentID}.papermc-docs.pages.dev`) || "https://docs.papermc.io";
2322

2423
const docsCommon: Options = {
2524
breadcrumbs: true,

src/util/pagesUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { env } from "process";
2+
3+
export const preview = env.CI_ENV === "preview";
4+
5+
export const deploymentID: string =
6+
`${env.GITHUB_PR_HEAD_OWNER}-${env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME}` // <PR head branch owner username>-<head branch name>
7+
.substring(0, 28) // capped to 28 characters
8+
.toLowerCase() // lowercase
9+
.replace("/", "-") // sanitize characters in branch names
10+
.replace("_", "-")
11+
.replace(".", "-");

0 commit comments

Comments
 (0)