From 3dd1e395e34157b997fc7e402008ce621bd39c94 Mon Sep 17 00:00:00 2001 From: Harsh Mahajan Date: Mon, 10 Nov 2025 13:45:31 +0000 Subject: [PATCH 1/2] point View source button to specific template folder --- src/lib/helpers/templateSource.ts | 40 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers/templateSource.ts b/src/lib/helpers/templateSource.ts index d24b67e777..8381407987 100644 --- a/src/lib/helpers/templateSource.ts +++ b/src/lib/helpers/templateSource.ts @@ -1,8 +1,7 @@ import type { Models } from '@appwrite.io/console'; /** - * Build VCS repo URL from the template response model. - * Example (GitHub): https://github.com/appwrite/templates-for-sites + * Example (GitHub): https://github.com/appwrite/templates-for-sites/tree/main/sveltekit/starter */ export function getTemplateSourceUrl( t: Models.TemplateSite | Models.TemplateFunction @@ -20,7 +19,40 @@ export function getTemplateSourceUrl( bitbucket: 'bitbucket.org' }; - const host = hostMap[provider.toLowerCase()] ?? provider; // fallback + const host = hostMap[provider.toLowerCase()]; + if (!host) return null; - return `https://${host}/${owner}/${repo}`; + let folderPath: string | undefined; + if ( + 'providerRootDirectory' in t && + t.providerRootDirectory && + typeof t.providerRootDirectory === 'string' + ) { + folderPath = t.providerRootDirectory; + } else if ( + 'frameworks' in t && + t.frameworks?.length > 0 && + t.frameworks[0]?.providerRootDirectory && + typeof t.frameworks[0].providerRootDirectory === 'string' + ) { + folderPath = t.frameworks[0].providerRootDirectory; + } + + let url = `https://${host}/${owner}/${repo}`; + + if (folderPath) { + const normalizedPath = folderPath.replace(/^\/+|\/+$/g, ''); + if (normalizedPath) { + const providerLower = provider.toLowerCase(); + if (providerLower === 'github') { + url = `${url}/tree/main/${normalizedPath}`; + } else if (providerLower === 'gitlab') { + url = `${url}/-/tree/main/${normalizedPath}`; + } else if (providerLower === 'bitbucket') { + url = `${url}/src/main/${normalizedPath}`; + } + } + } + + return url; } From 2b20b68bed569f02d31e51a9e89699f7cc3cab3a Mon Sep 17 00:00:00 2001 From: Harsh Mahajan Date: Sat, 22 Nov 2025 12:35:23 +0000 Subject: [PATCH 2/2] use master branch --- src/lib/helpers/templateSource.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers/templateSource.ts b/src/lib/helpers/templateSource.ts index 8381407987..4c8c6c0e00 100644 --- a/src/lib/helpers/templateSource.ts +++ b/src/lib/helpers/templateSource.ts @@ -1,7 +1,15 @@ import type { Models } from '@appwrite.io/console'; /** - * Example (GitHub): https://github.com/appwrite/templates-for-sites/tree/main/sveltekit/starter + * build VCS repo URL from the template response model. + * supports GitHub, GitLab, and Bitbucket. + * + * important: We use 'master' as the branch name because GitHub (and other providers) + * redirect 'master' to the repository's default branch, regardless of whether + * its actually named 'main', 'master', or something else. This ensures the + * link works across all repositories without needing to know their default branch. + * + * Example (GitHub): https://github.com/appwrite/templates-for-sites/tree/master/sveltekit/starter */ export function getTemplateSourceUrl( t: Models.TemplateSite | Models.TemplateFunction @@ -44,12 +52,13 @@ export function getTemplateSourceUrl( const normalizedPath = folderPath.replace(/^\/+|\/+$/g, ''); if (normalizedPath) { const providerLower = provider.toLowerCase(); + // Use 'master' as branch name - GitHub/GitLab/Bitbucket redirect it to default branch if (providerLower === 'github') { - url = `${url}/tree/main/${normalizedPath}`; + url = `${url}/tree/master/${normalizedPath}`; } else if (providerLower === 'gitlab') { - url = `${url}/-/tree/main/${normalizedPath}`; + url = `${url}/-/tree/master/${normalizedPath}`; } else if (providerLower === 'bitbucket') { - url = `${url}/src/main/${normalizedPath}`; + url = `${url}/src/master/${normalizedPath}`; } } }