{
+ const parsedUrl = useMemo(() => {
+ try {
+ return tldts.parse(window.location.toString());
+ } catch {
+ return null;
+ }
+ }, [window.location]);
+
+ const getHref = useCallback(
+ (appType: AppType) => {
+ if (appType.behaviour.externalUrl.length > 0) {
+ return appType.behaviour.externalUrl
+ .replace('[homarr_base]', `${window.location.protocol}//${window.location.hostname}`)
+ .replace('[homarr_hostname]', parsedUrl?.hostname ?? '')
+ .replace('[homarr_domain]', parsedUrl?.domain ?? '')
+ .replace('[homarr_protocol]', window.location.protocol.replace(':', ''));
+ }
+ return appType.url;
+ },
+ [parsedUrl]
+ );
+
+ return getHref;
+};
+
+export const useExternalUrl = (app: AppType) => {
+ const getHref = useGetExternalUrl();
+
+ const href = useMemo(() => {
+ return getHref(app);
+ }, [app, getHref]);
+
+ return href;
+};
diff --git a/yarn.lock b/yarn.lock
index 26f58fa16d5..c9d89b889f2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7495,6 +7495,7 @@ __metadata:
sabnzbd-api: ^1.5.0
sass: ^1.56.1
swagger-ui-react: ^5.11.0
+ tldts: ^6.1.18
trpc-openapi: ^1.2.0
ts-node: latest
turbo: ^1.10.12
@@ -11885,6 +11886,24 @@ __metadata:
languageName: node
linkType: hard
+"tldts-core@npm:^6.1.18":
+ version: 6.1.18
+ resolution: "tldts-core@npm:6.1.18"
+ checksum: 392d490c04aca5b40f16666fb6cbc9d7ef6df42884b1ac196736ffdeeb378019962dbc04ee00a2a85ce61944a0692c1f1cd8b64896277949906991146830314f
+ languageName: node
+ linkType: hard
+
+"tldts@npm:^6.1.18":
+ version: 6.1.18
+ resolution: "tldts@npm:6.1.18"
+ dependencies:
+ tldts-core: ^6.1.18
+ bin:
+ tldts: bin/cli.js
+ checksum: 04ec7d6a5ad42ddedd9dd250d9cde37608b09bf28eecb94bad8c49d65225d861e0bddc6e1cea3253baf8fc96722e0d2fc1e926eb73b7a35396c77346efaf70f0
+ languageName: node
+ linkType: hard
+
"tmp@npm:^0.0.33":
version: 0.0.33
resolution: "tmp@npm:0.0.33"