feat: implement new footer

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-04-16 16:53:46 +07:00
parent 5c59c86d55
commit b08cf040ce
14 changed files with 90 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
import { HIDDEN_PRODUCT_TAG, SHOPIFY_GRAPHQL_API_ENDPOINT, TAGS } from 'lib/constants';
import { isShopifyError } from 'lib/type-guards';
import { ensureStartsWith } from 'lib/utils';
import { ensureStartsWith, normalizeUrl } from 'lib/utils';
import { revalidateTag } from 'next/cache';
import { headers } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';
@@ -346,12 +346,16 @@ export async function getMenu(handle: string): Promise<Menu[]> {
}
});
return (
res.body?.data?.menu?.items.map((item: { title: string; url: string }) => ({
const formatMenuItems = (
menu: { title: string; url: string; items?: { title: string; url: string }[] }[] = []
): Menu[] =>
menu.map((item) => ({
title: item.title,
path: item.url.replace(domain, '').replace('/collections', '/search').replace('/pages', '')
})) || []
);
path: normalizeUrl(domain, item.url),
items: item.items?.length ? formatMenuItems(item.items) : []
}));
return formatMenuItems(res.body?.data?.menu?.items);
}
export async function getPage(handle: string): Promise<Page> {

View File

@@ -4,6 +4,10 @@ export const getMenuQuery = /* GraphQL */ `
items {
title
url
items {
title
url
}
}
}
}

View File

@@ -43,6 +43,7 @@ export type Image = {
export type Menu = {
title: string;
path: string;
items: Menu[];
};
export type Money = {

View File

@@ -43,3 +43,7 @@ export const validateEnvironmentVariables = () => {
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function normalizeUrl(domain: string, url: string) {
return url.replace(domain, '').replace('/collections', '/search').replace('/pages', '');
}