mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat(templates): add helper for template source URL
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export type Template = {
|
||||
key?: string; // template slug, e.g. "magic-portfolio"
|
||||
frameworks?: Array<{
|
||||
key?: string;
|
||||
providerRootDirectory?: string;
|
||||
}>; // e.g. [{ key: "nextjs", providerRootDirectory: "./nextjs/magic-portfolio" }]
|
||||
providerOwner?: string; // e.g. "appwrite"
|
||||
providerRepositoryId?: string; // e.g. "templates-for-sites" or "template-for-store"
|
||||
repository?: string; // if API already returns full URL, use it
|
||||
repoUrl?: string; // alias some builds may use
|
||||
source?: string; // alias some builds may use
|
||||
};
|
||||
|
||||
export function getTemplateSourceUrl(template: Template): string | null {
|
||||
// 1) Prefer a direct URL if the API already provides it
|
||||
const direct = template.repository || template.repoUrl || template.source;
|
||||
if (direct) return direct;
|
||||
|
||||
// 2) Ensure we have the parts to build the GitHub URL
|
||||
const owner = template.providerOwner || "appwrite";
|
||||
const repo = template.providerRepositoryId || "templates-for-sites";
|
||||
const rootDir = template.frameworks?.[0]?.providerRootDirectory ?? "./";
|
||||
|
||||
// strip leading "./"
|
||||
const cleanDir = rootDir.startsWith("./") ? rootDir.slice(2) : rootDir;
|
||||
|
||||
if (!cleanDir || cleanDir === "") {
|
||||
return `https://github.com/${owner}/${repo}/tree/main`;
|
||||
}
|
||||
|
||||
return `https://github.com/${owner}/${repo}/tree/main/${cleanDir}`;
|
||||
}
|
||||
Reference in New Issue
Block a user