File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 11import { describe , expect , test } from "vitest" ;
22import { DOCS_BASE_URL , PREVIEW_URL_REGEX } from "./constants" ;
3- import { filenameToPath } from "./util" ;
3+ import { filenameToPath , branchToSubdomain } from "./util" ;
44
55test ( "PREVIEW_URL_REGEX" , ( ) => {
66 const comment =
@@ -13,6 +13,20 @@ test("PREVIEW_URL_REGEX", () => {
1313 ) ;
1414} ) ;
1515
16+ describe ( "branchToSubdomain" , ( ) => {
17+ test ( "slash" , ( ) => {
18+ expect ( branchToSubdomain ( "kian/pcx-15803" ) ) . toEqual ( "kian-pcx-15803" ) ;
19+ } ) ;
20+
21+ test ( "normal" , ( ) => {
22+ expect ( branchToSubdomain ( "pcx-15803" ) ) . toEqual ( "pcx-15803" ) ;
23+ } ) ;
24+
25+ test ( "capitalisation" , ( ) => {
26+ expect ( branchToSubdomain ( "PCX-15803" ) ) . toEqual ( "pcx-15803" ) ;
27+ } ) ;
28+ } ) ;
29+
1630describe ( "filenameToPath" , ( ) => {
1731 test ( "index" , ( ) => {
1832 expect ( filenameToPath ( "src/content/docs/workers/index.mdx" ) ) . toEqual (
Original file line number Diff line number Diff line change 88 PREVIEW_URL_REGEX ,
99} from "./constants" ;
1010
11- import { filenameToPath , slug } from "./util" ;
11+ import { filenameToPath , branchToSubdomain } from "./util" ;
1212
1313async function run ( ) : Promise < void > {
1414 try {
@@ -51,7 +51,7 @@ async function run(): Promise<void> {
5151 ) ;
5252
5353 const previewUrl = {
54- branch : `https://${ slug ( process . env . GITHUB_REF_NAME ) } .preview.developers.cloudflare.com` ,
54+ branch : `https://${ branchToSubdomain ( process . env . GITHUB_REF_NAME ) } .preview.developers.cloudflare.com` ,
5555 commit : `https://${ ctx . sha . slice ( 0 , 8 ) } .preview.developers.cloudflare.com` ,
5656 } ;
5757
Original file line number Diff line number Diff line change 11import { slug } from "github-slugger" ;
2-
2+ import { execSync } from "node:child_process" ;
33import { CONTENT_BASE_PATH } from "./constants" ;
44
55export const filenameToPath = ( filename : string ) => {
@@ -30,4 +30,9 @@ export const filenameToPath = (filename: string) => {
3030 . concat ( "/" ) ;
3131} ;
3232
33- export { slug } ;
33+ export const branchToSubdomain = ( branch : string ) => {
34+ return execSync (
35+ `echo "${ branch } " | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z` ,
36+ { encoding : "utf-8" } ,
37+ ) . trim ( ) ;
38+ } ;
You can’t perform that action at this time.
0 commit comments