-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { notFound } from 'next/navigation'; | ||
import { Metadata } from 'next'; | ||
import { dataSiteBySubdomain, dataSitePageBySlug } from '@/lib/data/site'; | ||
import { TWebsitePageProps } from '@/types'; | ||
import SitePage from '@/components/website/page'; | ||
|
||
export async function generateMetadata( | ||
props: TWebsitePageProps<{ slug: string }> | ||
): Promise<Metadata> { | ||
const { | ||
params: { subdomain, slug }, | ||
} = props; | ||
const site = await dataSiteBySubdomain(subdomain); | ||
if (!site) notFound(); | ||
const item = await dataSitePageBySlug(site.id, slug); | ||
if (!item) notFound(); | ||
|
||
return { | ||
title: item.title, | ||
description: item.description ?? site.name, | ||
}; | ||
} | ||
export default async function Page(props: TWebsitePageProps<{ slug: string }>) { | ||
const { | ||
params: { subdomain, slug }, | ||
} = props; | ||
const site = await dataSiteBySubdomain(subdomain); | ||
if (!site) notFound(); | ||
const item = await dataSitePageBySlug(site.id, slug); | ||
if (!item) notFound(); | ||
|
||
return ( | ||
<> | ||
<SitePage | ||
site={site} | ||
data={{ item }} | ||
page={{ | ||
...props, | ||
name: 'page/[slug]', | ||
title: item.title, | ||
subTitle: item.description ?? '', | ||
}} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/components/website/templates/base/pages/page/[slug]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import BlurImage from '@/components/blur-image'; | ||
import ContentBlocks from '@/components/content-blocks'; | ||
import BaseIcon from '@/components/icons/base-icon'; | ||
import NewsShareItem from '@/components/share/item-news'; | ||
import { SiteContextType } from '@/components/website/provider'; | ||
import { TWebPageItemBySlug } from '@/types'; | ||
|
||
export default function Page({ | ||
data: { item }, | ||
site, | ||
}: SiteContextType<{ slug: string }, { item: TWebPageItemBySlug }>) { | ||
return ( | ||
<article className="px-5"> | ||
<section className="h-full grid grid-cols-1 gap-8 lg:grid-cols-[70%,25%] xl:gap-[72px]"> | ||
<div className="flex flex-col gap-7"> | ||
<div className="w-full min-h-screen"> | ||
<div className="flex flex-col gap-2 mt-3"> | ||
{item.image_cover && ( | ||
<BlurImage | ||
src={item.image_cover.url} | ||
alt={item.title} | ||
width="0" | ||
height="0" | ||
sizes="100vw" | ||
className="image-zoom w-full h-full rounded-lg" | ||
/> | ||
)} | ||
</div> | ||
{item.content && item.content.blocks && ( | ||
<div className="prose max-w-none"> | ||
<ContentBlocks {...item.content} /> | ||
</div> | ||
)} | ||
</div> | ||
<p className="font-lora text-gray-800"></p> | ||
</div> | ||
<div className="my-5 w-full"> | ||
<div className="flex flex-col gap-2 lg:sticky lg:top-[88px] w-full overflow-auto"> | ||
<div className="flex flex-col gap-3 mb-5 overflow-y-auto"> | ||
<p className="inline-flex gap-3 font-lato text-xs text-blue-gray-200 leading-5"> | ||
<BaseIcon | ||
icon="share" | ||
className="self-start text-primary w-5 h-5" | ||
/> | ||
Bagikan | ||
</p> | ||
</div> | ||
<NewsShareItem item={item as any} isPage /> | ||
</div> | ||
</div> | ||
</section> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import _ from 'lodash'; | ||
import { createApiResource } from '../base'; | ||
|
||
export default createApiResource('web_menu', { | ||
baseFields: [ | ||
'id', | ||
'slug', | ||
'title', | ||
'status', | ||
'title', | ||
'sort', | ||
{ pages: ['id', 'title', 'status', 'slug', 'sort'] }, | ||
{ website: ['id', 'name', 'subdomain'] }, | ||
{ | ||
user_created: ['first_name', 'last_name', 'content_author_name'], | ||
}, | ||
{ user_updated: ['first_name', 'last_name', 'content_author_name'] }, | ||
'date_updated', | ||
'date_created', | ||
], | ||
baseQuery: { | ||
sort: ['sort'], | ||
filter: { status: { _eq: 'published' } }, | ||
}, | ||
baseNormalizer: (data) => { | ||
return data; | ||
}, | ||
}).addPath('read', 'siteMenu', (res) => async ({ paths: [websiteId] }) => { | ||
if (!websiteId) res.errorThrow('Website dibutuhkan.'); | ||
return await res.read | ||
.clientOptions({ cache: 'no-cache' }) | ||
.setQuery({ | ||
filter: { website: { _eq: websiteId } }, | ||
limit: -1, | ||
}) | ||
.items({ | ||
normalizer: [ | ||
[ | ||
'id', | ||
'title', | ||
'slug', | ||
'sort', | ||
{ pages: ['id', 'slug', 'title', 'sort', 'description'] }, | ||
], | ||
(data) => { | ||
return data; | ||
}, | ||
], | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import _ from 'lodash'; | ||
import { createApiResource } from '../base'; | ||
import { | ||
imageFileNormalizer, | ||
contentBlocksNormalizer, | ||
} from '../../normalizer-helper'; | ||
|
||
export default createApiResource('web_pages', { | ||
baseFields: [ | ||
'id', | ||
'slug', | ||
'title', | ||
'description', | ||
'sort', | ||
'menu', | ||
{ image_cover: ['*'] }, | ||
{ website: ['id', 'name', 'subdomain'] }, | ||
{ | ||
user_created: ['first_name', 'last_name', 'content_author_name'], | ||
}, | ||
{ user_updated: ['first_name', 'last_name', 'content_author_name'] }, | ||
'date_updated', | ||
'date_created', | ||
], | ||
baseQuery: { | ||
sort: ['sort'], | ||
filter: { status: { _eq: 'published' } }, | ||
}, | ||
baseNormalizer: (data) => { | ||
return { | ||
..._.omit(data, 'user_updated', 'user_created'), | ||
image_cover: data.image_cover | ||
? imageFileNormalizer(data.image_cover!) | ||
: null, | ||
}; | ||
}, | ||
}).addPath('read', 'bySlug', (res) => ({ paths: [websiteId, slug] }) => { | ||
if (!websiteId) res.errorThrow('Website dibutuhkan.'); | ||
if (!slug) res.errorThrow('Slug dibutuhkan.'); | ||
return res.read | ||
.setQuery({ | ||
filter: { | ||
website: { _eq: websiteId }, | ||
slug: { _eq: slug }, | ||
}, | ||
}) | ||
.items({ | ||
normalizer: [ | ||
[...res.baseFields, 'content'], | ||
(data) => { | ||
return { | ||
...res.baseNormalizer(data), | ||
content: contentBlocksNormalizer(data.content), | ||
}; | ||
}, | ||
], | ||
single: true, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TDirectusStatusField, TDirectusUser } from './_base'; | ||
import { WebPages } from './web_pages'; | ||
import { Websites } from './websites'; | ||
|
||
export interface WebMenu { | ||
id: string; | ||
status: TDirectusStatusField; | ||
title: string; | ||
slug: string; | ||
website: string | Websites; | ||
sort: number; | ||
pages: WebPages[]; | ||
|
||
user_created: string | TDirectusUser; | ||
user_updated: string | TDirectusUser; | ||
date_updated?: string; | ||
date_created: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { TDirectusFile, TDirectusStatusField, TDirectusUser } from './_base'; | ||
import { WebMenu } from './web_menu'; | ||
import { Websites } from './websites'; | ||
|
||
export interface WebPages { | ||
id: string; | ||
status: TDirectusStatusField; | ||
title: string; | ||
slug: string; | ||
description: null | string; | ||
website: string | Websites; | ||
image_cover: string | TDirectusFile; | ||
menu: string | WebMenu; | ||
sort: number; | ||
content: { | ||
time: number; | ||
blocks: JSON; | ||
version: string; | ||
}; | ||
|
||
user_created: string | TDirectusUser; | ||
user_updated: string | TDirectusUser; | ||
date_updated?: string; | ||
date_created: string; | ||
} |