Skip to content

Commit add23df

Browse files
committed
add env variables for branch and deployment url
1 parent 59c4de5 commit add23df

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

app/routes/MdxRoute.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ let default = () => {
320320
}
321321
})
322322
)}
323-
editHref={`https://github.com/rescript-lang/rescript-lang.org/blob/master${loaderData.filePath->Option.getOrThrow}`}
323+
editHref={`https://github.com/rescript-lang/rescript-lang.org/blob/${Env.github_branch}${loaderData.filePath->Option.getOrThrow}`}
324324
>
325325
<div className="markdown-body"> {component()} </div>
326326
</DocsLayout>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@
7676
"vite-plugin-devtools-json": "^1.0.0",
7777
"vite-plugin-env-compatible": "^2.0.1"
7878
}
79-
}
79+
}

src/bindings/Env.res

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// If Vite if running in dev mode
2+
external dev: bool = "import.meta.env.DEV"
3+
4+
// Cloudflare deployment URL
5+
external deployment_url: option<string> = "import.meta.env.DEPLOYMENT_URL"
6+
7+
// The current github branch
8+
external github_branch: option<string> = "import.meta.env.GITHUB_BRANCH"
9+
let github_branch = switch github_branch {
10+
| Some(branch) => branch
11+
| None => "master"
12+
}
13+
14+
// the root url of the site, e.g. "https://rescript-lang.org/" or "http://localhost:5173/"
15+
let root_url = switch deployment_url {
16+
| Some(url) => url
17+
| None => dev ? "http://localhost:5173/" : "https://rescript-lang.org/"
18+
}

src/components/Meta.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let make = (
1515
~ogImage="/Art-3-rescript-launch.jpg",
1616
~version: option<Url.version>=?,
1717
) => {
18-
let ogImage = "https://rescript-lang.org" ++ ogImage
18+
let ogImage = Env.root_url ++ ogImage
1919

2020
let title = switch title {
2121
| None

0 commit comments

Comments
 (0)