@ansiversa/components 0.0.147 → 0.0.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/package.json +1 -1
- package/src/layouts/WebLayout.astro +5 -4
- package/src/lib/urls/parentOrigin.ts +40 -0
package/README.md
CHANGED
|
@@ -24,3 +24,10 @@ Inside any Ansiversa app (`web`, `admin`, or mini-apps):
|
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
npm install @ansiversa/components
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Environment
|
|
30
|
+
|
|
31
|
+
- `PUBLIC_ANSIVERSA_PARENT_ORIGIN`: parent web origin used for shared footer legal/help links.
|
|
32
|
+
- Production example: `PUBLIC_ANSIVERSA_PARENT_ORIGIN=https://ansiversa.com`
|
|
33
|
+
- Local example: `PUBLIC_ANSIVERSA_PARENT_ORIGIN=http://localhost:2000`
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import AvFooter from "../AvFooter.astro";
|
|
|
4
4
|
import AvMiniAppBar from "./AvMiniAppBar.astro";
|
|
5
5
|
import AvNavbar from "../AvNavbar.astro";
|
|
6
6
|
import AvNavbarActions from "../AvNavbarActions.astro";
|
|
7
|
+
import { buildParentUrl } from "../lib/urls/parentOrigin";
|
|
7
8
|
|
|
8
9
|
interface Props {
|
|
9
10
|
title?: string;
|
|
@@ -99,10 +100,10 @@ const ROOT_URL = rawDomain.match(/^https?:\/\//i)
|
|
|
99
100
|
<!-- Footer -->
|
|
100
101
|
<AvFooter
|
|
101
102
|
links={[
|
|
102
|
-
{ label: "Terms", href: "/terms" },
|
|
103
|
-
{ label: "Privacy", href: "/privacy" },
|
|
104
|
-
{ label: "FAQ", href: "/faq" },
|
|
105
|
-
{ label: "Contact", href: "/contact" }
|
|
103
|
+
{ label: "Terms", href: buildParentUrl("/terms") },
|
|
104
|
+
{ label: "Privacy", href: buildParentUrl("/privacy") },
|
|
105
|
+
{ label: "FAQ", href: buildParentUrl("/faq") },
|
|
106
|
+
{ label: "Contact", href: buildParentUrl("/contact") }
|
|
106
107
|
]}
|
|
107
108
|
/>
|
|
108
109
|
</body>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const DEFAULT_PARENT_ORIGIN = "http://localhost:2000";
|
|
2
|
+
const PRODUCTION_PARENT_ORIGIN = "https://ansiversa.com";
|
|
3
|
+
|
|
4
|
+
const trimTrailingSlash = (value: string) => value.trim().replace(/\/+$/, "");
|
|
5
|
+
|
|
6
|
+
const normalizeOrigin = (value: string) => {
|
|
7
|
+
const normalized = trimTrailingSlash(value);
|
|
8
|
+
if (!normalized) return "";
|
|
9
|
+
try {
|
|
10
|
+
return new URL(normalized).toString().replace(/\/+$/, "");
|
|
11
|
+
} catch {
|
|
12
|
+
return normalized;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const isAnsiversaHostname = (hostname: string) =>
|
|
17
|
+
hostname === "ansiversa.com" || hostname.endsWith(".ansiversa.com");
|
|
18
|
+
|
|
19
|
+
export const resolveParentOrigin = () => {
|
|
20
|
+
const envOrigin = normalizeOrigin(import.meta.env.PUBLIC_ANSIVERSA_PARENT_ORIGIN ?? "");
|
|
21
|
+
if (envOrigin) return envOrigin;
|
|
22
|
+
|
|
23
|
+
if (import.meta.env.PROD) {
|
|
24
|
+
return PRODUCTION_PARENT_ORIGIN;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof window !== "undefined") {
|
|
28
|
+
const host = window.location.hostname.toLowerCase();
|
|
29
|
+
if (isAnsiversaHostname(host)) {
|
|
30
|
+
return PRODUCTION_PARENT_ORIGIN;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return DEFAULT_PARENT_ORIGIN;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const buildParentUrl = (path: string) => {
|
|
38
|
+
const normalizedPath = `/${String(path ?? "").replace(/^\/+/, "")}`;
|
|
39
|
+
return `${resolveParentOrigin()}${normalizedPath}`;
|
|
40
|
+
};
|