refactor shopify storefront

This commit is contained in:
Rami Bitar
2026-05-05 13:42:40 -04:00
parent ba8826030c
commit 62fbdead87
156 changed files with 1688 additions and 8293 deletions

View File

@@ -0,0 +1,34 @@
const TEMPLATE_PATTERNS: { key: string; prefix: string; param: string }[] = [
{ key: "/products/*", prefix: "/products/", param: "handle" },
{ key: "/collections/*", prefix: "/collections/", param: "handle" },
];
export type ResolvedEditorPath = {
isEdit: boolean;
path: string;
templateKey: string | null;
params: Record<string, string>;
};
const resolveEditorPath = (editorPath: string[] = []): ResolvedEditorPath => {
const isEdit =
editorPath.length > 0 && editorPath[editorPath.length - 1] === "edit";
const segments = isEdit ? editorPath.slice(0, -1) : editorPath;
const path = segments.length === 0 ? "/" : `/${segments.join("/")}`;
for (const { key, prefix, param } of TEMPLATE_PATTERNS) {
if (path.startsWith(prefix) && path.length > prefix.length) {
return {
isEdit,
path,
templateKey: key,
params: { [param]: path.slice(prefix.length) },
};
}
}
return { isEdit, path, templateKey: null, params: {} };
};
export default resolveEditorPath;