Skip to content

Commit 4381cb0

Browse files
authored
docs: expose build time env variable at runtime (#12320) [ci skip]
1 parent fa4d026 commit 4381cb0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/website/docusaurus.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const config: Config = {
3535
customFields: {
3636
ui5Version: packageJson.version,
3737
ui5DeploymentType: process.env.DEPLOYMENT_TYPE,
38+
urlShortenerApiKey: process.env.URL_SHORTENER_API_KEY,
3839
},
3940
title: 'UI5 Web Components',
4041
tagline: 'An open-source UI components library for building enterprise-ready applications!',

packages/website/src/components/Editor/shortenURL.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
2+
13
const URL_SHORTEN_API = "https://linkshortener.int.sap/api/url";
24

35
export default async function shortenURL(longUrl) {
46
if (process.env.NODE_ENV === 'development' ) {
57
return;
68
}
9+
10+
const { siteConfig } = useDocusaurusContext();
11+
const URL_SHORTEN_API_KEY = siteConfig.customFields.urlShortenerApiKey;
712

8-
const URL_API_KEY = process.env.URL_SHORTENER_API_KEY;
9-
if (!URL_API_KEY) {
13+
if (!URL_SHORTEN_API_KEY) {
1014
console.warn("URL shortener API key not available.");
1115
return "";
1216
}
@@ -21,7 +25,7 @@ export default async function shortenURL(longUrl) {
2125
headers: {
2226
"Content-Type": "application/json",
2327
"Accept": "application/json",
24-
"ApiKey": URL_API_KEY,
28+
"ApiKey": URL_SHORTEN_API_KEY,
2529
"X-Requested-With": "XMLHttpRequest"
2630
},
2731
body: JSON.stringify(payload),

0 commit comments

Comments
 (0)