Skip to content

Commit cb50a8a

Browse files
committed
Migration
1 parent 115aa85 commit cb50a8a

8 files changed

Lines changed: 30 additions & 32 deletions

File tree

src/components/CustomDocCardList.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function resolveCardData(targetIds) {
6161
id: targetId,
6262
label,
6363
description: doc?.data.description || 'Learn more about this topic in our documentation.',
64-
href: `/${targetId}`
64+
href: `${import.meta.env.BASE_URL}/${targetId}`.replace(/\/+/g, '/')
6565
};
6666
});
6767
}

src/components/Header.astro

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const links = [
2222

2323
<!-- Desktop Navigation -->
2424
<nav class="hidden lg:flex items-center gap-1 text-[14px] font-medium">
25-
<a href="/" class="nav-link">
25+
<a href={import.meta.env.BASE_URL} class="nav-link">
2626
Documentation
2727
</a>
2828

@@ -39,23 +39,23 @@ const links = [
3939
<div class="dropdown-menu">
4040
<div class="dropdown-content">
4141
{[
42-
{ label: "iOS", href: "/ios-sdk-overview" },
43-
{ label: "Android", href: "/android-sdk-overview" },
44-
{ label: "React Native", href: "/react-native-sdk-overview" },
45-
{ label: "Flutter", href: "/flutter-sdk-overview" },
46-
{ label: "Unity", href: "/unity-sdk-overview" },
47-
{ label: "Kotlin Multiplatform", href: "/kmp-sdk-overview" },
48-
{ label: "Capacitor", href: "/capacitor-sdk-overview" }
42+
{ label: "iOS", href: `${import.meta.env.BASE_URL}/ios-sdk-overview` },
43+
{ label: "Android", href: `${import.meta.env.BASE_URL}/android-sdk-overview` },
44+
{ label: "React Native", href: `${import.meta.env.BASE_URL}/react-native-sdk-overview` },
45+
{ label: "Flutter", href: `${import.meta.env.BASE_URL}/flutter-sdk-overview` },
46+
{ label: "Unity", href: `${import.meta.env.BASE_URL}/unity-sdk-overview` },
47+
{ label: "Kotlin Multiplatform", href: `${import.meta.env.BASE_URL}/kmp-sdk-overview` },
48+
{ label: "Capacitor", href: `${import.meta.env.BASE_URL}/capacitor-sdk-overview` }
4949
].map(item => (
50-
<a href={item.href} class="dropdown-item">
50+
<a href={item.href.replace(/\/+/g, '/')} class="dropdown-item">
5151
{item.label}
5252
</a>
5353
))}
5454
</div>
5555
</div>
5656
</div>
5757

58-
<a href="/getting-started-with-server-side-api" class="nav-link">Server API</a>
58+
<a href={`${import.meta.env.BASE_URL}/getting-started-with-server-side-api`.replace(/\/+/g, '/')} class="nav-link">Server API</a>
5959
<a href="https://ask.adapty.io/questions" class="nav-link">Support Forum</a>
6060
</nav>
6161
</div>

src/components/PlatformSwitcher.astro

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ function getTargetLink(platformId: string, targetLabel?: string, activeId?: stri
6868
// 1. If current is overview, always try to land on target's overview
6969
if (isCurrentOverview) {
7070
const targetOverview = findOverview(sidebarData);
71-
if (targetOverview) return `/${targetOverview.id}`;
71+
if (targetOverview) return `${import.meta.env.BASE_URL}/${targetOverview.id}`.replace(/\/+/g, '/');
7272
}
7373
7474
// 2. Otherwise, try to find matching label first (Topic Consistency)
7575
if (targetLabel) {
7676
const match = findItemByLabel(sidebarData, targetLabel);
77-
if (match) return `/${match.id}`;
77+
if (match) return `${import.meta.env.BASE_URL}/${match.id}`.replace(/\/+/g, '/');
7878
}
7979
8080
// 3. Last Fallback: Target platform's overview
8181
const overview = findOverview(sidebarData);
82-
if (overview) return `/${overview.id}`;
82+
if (overview) return `${import.meta.env.BASE_URL}/${overview.id}`.replace(/\/+/g, '/');
8383
84-
return `/${platformId}-sdk-overview`; // Ultimate hardcoded fallback
84+
return `${import.meta.env.BASE_URL}/${platformId}-sdk-overview`.replace(/\/+/g, '/'); // Ultimate hardcoded fallback
8585
}
8686
---
8787

@@ -346,11 +346,12 @@ function getTargetLink(platformId: string, targetLabel?: string, activeId?: stri
346346
}
347347

348348
function getTargetLink(platformId: string, sidebarName: string): string {
349+
const baseUrl = import.meta.env.BASE_URL;
349350
// Remove .json extension if present
350351
const cleanSidebarName = sidebarName.replace('.json', '');
351352
const sidebarData = sidebarsMap.get(cleanSidebarName);
352353
if (!sidebarData) {
353-
return `/${platformId}-sdk-overview`;
354+
return `${baseUrl}/${platformId}-sdk-overview`.replace(/\/+/g, '/');
354355
}
355356

356357
// Get current page info dynamically
@@ -375,25 +376,25 @@ function getTargetLink(platformId: string, targetLabel?: string, activeId?: stri
375376
if (isCurrentOverview) {
376377
const targetOverview = findOverview(sidebarData);
377378
if (targetOverview) {
378-
return `/${targetOverview.id}`;
379+
return `${baseUrl}/${targetOverview.id}`.replace(/\/+/g, '/');
379380
}
380381
}
381382

382383
// 2. Try to find matching label (Topic Consistency)
383384
if (currentLabel) {
384385
const match = findItemByLabel(sidebarData, currentLabel);
385386
if (match) {
386-
return `/${match.id}`;
387+
return `${baseUrl}/${match.id}`.replace(/\/+/g, '/');
387388
}
388389
}
389390

390391
// 3. Fallback to target's overview
391392
const overview = findOverview(sidebarData);
392393
if (overview) {
393-
return `/${overview.id}`;
394+
return `${baseUrl}/${overview.id}`.replace(/\/+/g, '/');
394395
}
395396

396-
return `/${platformId}-sdk-overview`;
397+
return `${baseUrl}/${platformId}-sdk-overview`.replace(/\/+/g, '/');
397398
}
398399

399400
function initPlatformSwitcher() {

src/components/Sidebar.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ function transformItems(items: any[]): any[] {
6464
if (!item.href) {
6565
// Check if there's a custom slug for this document
6666
const customSlug = docSlugs.get(item.id);
67-
newItem.href = customSlug || `/${item.id}`;
67+
newItem.href = `${import.meta.env.BASE_URL}${customSlug || `/${item.id}`}`.replace(/\/+/g, '/');
6868
}
6969
}
7070
7171
// Handle category with link
7272
if (item.type === 'category' && item.link?.id && !item.href) {
7373
const customSlug = docSlugs.get(item.link.id);
74-
newItem.href = customSlug || `/${item.link.id}`;
74+
newItem.href = `${import.meta.env.BASE_URL}${customSlug || `/${item.link.id}`}`.replace(/\/+/g, '/');
7575
}
7676
if (item.items) {
7777
newItem.items = transformItems(item.items);

src/components/SidebarItem.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getHref = (item: any) => {
1414
if (item.type === 'link') return item.href;
1515
if (item.href) return item.href;
1616
const id = item.id || item.link?.id;
17-
if (id) return `/${id}`;
17+
if (id) return `${import.meta.env.BASE_URL}/${id}`.replace(/\/+/g, '/');
1818
return null;
1919
};
2020

src/layouts/DocsLayout.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ const keywordsString = Array.isArray(keywords) ? keywords.join(', ') : keywords;
396396

397397
function transformUrlForEnvironment(originalUrl: string): string {
398398
const currentOrigin = window.location.origin;
399+
const baseUrl = import.meta.env.BASE_URL;
399400
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
400401
const isVercel = window.location.hostname.includes('vercel.app');
401402
const isProduction = window.location.hostname === 'adapty.io';
@@ -404,7 +405,7 @@ const keywordsString = Array.isArray(keywords) ? keywords.join(', ') : keywords;
404405
if (url.startsWith('https://adapty.io/docs/')) {
405406
if (isLocalhost || isVercel || !isProduction) {
406407
const path = url.replace('https://adapty.io/docs/', '');
407-
url = `${currentOrigin}/${path}`;
408+
url = `${currentOrigin}${baseUrl}/${path}`.replace(/\/+/g, '/');
408409
}
409410
}
410411
return url;

src/pages/[...slug].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function getBreadcrumbs(items, targetId, path = []) {
161161
d.id.split('/').pop()?.replace(/\.(md|mdx)$/, '') === candidateId
162162
);
163163
if (docExists) {
164-
href = `/${candidateId}`;
164+
href = `${import.meta.env.BASE_URL}/${candidateId}`.replace(/\/+/g, '/');
165165
}
166166
}
167167
}

src/scripts/search.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ document.addEventListener('DOMContentLoaded', () => {
7777
*/
7878
const transformUrlForEnvironment = (originalUrl: string): string => {
7979
const currentOrigin = window.location.origin;
80-
const currentPathname = window.location.pathname;
80+
const baseUrl = import.meta.env.BASE_URL;
8181

8282
// Parse the original URL
8383
let url = originalUrl;
@@ -93,12 +93,8 @@ document.addEventListener('DOMContentLoaded', () => {
9393
// Extract the path after /docs/
9494
const path = url.replace('https://adapty.io/docs/', '');
9595

96-
// Determine the base path for the current environment
97-
// If we're already on a /docs path, use that as base
98-
const basePath = currentPathname.startsWith('/docs') ? '' : '';
99-
100-
// Construct the new URL with current origin
101-
url = `${currentOrigin}${basePath}/${path}`;
96+
// Construct the new URL with current origin and base URL
97+
url = `${currentOrigin}${baseUrl}/${path}`.replace(/\/+/g, '/');
10298
}
10399
}
104100

0 commit comments

Comments
 (0)