diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-24 15:38:37 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-24 15:38:37 +0100 |
| commit | ef7912256cb4765d553b002c24b9752c2d5096ac (patch) | |
| tree | 59b574dbda693dc5f1b2605272a6eff3b23802f2 /src | |
| parent | fe5d74a864ddd1429b0753a3984c45b2392176d2 (diff) | |
| parent | 0bb6411ee9fce02c2e5680f2be5740a1bbb508ad (diff) | |
feat: use mdx for pages
Diffstat (limited to 'src')
| m--------- | src/content | 0 | ||||
| -rw-r--r-- | src/pages/cv.tsx | 21 | ||||
| -rw-r--r-- | src/pages/index.tsx | 10 | ||||
| -rw-r--r-- | src/pages/mentions-legales.tsx | 20 | ||||
| -rw-r--r-- | src/services/graphql/queries.ts | 47 | ||||
| -rw-r--r-- | src/ts/types/app.ts | 16 | ||||
| -rw-r--r-- | src/ts/types/homepage.ts | 12 | ||||
| -rw-r--r-- | src/ts/types/pages.ts | 23 | ||||
| -rw-r--r-- | src/utils/helpers/format.ts | 23 |
9 files changed, 21 insertions, 151 deletions
diff --git a/src/content b/src/content new file mode 160000 +Subproject d6f4c2ff1510272a42da208dde9340dbb185753 diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index 44d943c..5107f6a 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -1,14 +1,13 @@ import { getLayout } from '@components/Layouts/Layout'; import ToC from '@components/ToC/ToC'; import { seo } from '@config/seo'; -import { getPageByUri } from '@services/graphql/queries'; import { NextPageWithLayout } from '@ts/types/app'; -import { PageProps } from '@ts/types/pages'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; +import CVContent, { intro, meta } from '@content/pages/cv.mdx'; -const CV: NextPageWithLayout<PageProps> = ({ page }) => { +const CV: NextPageWithLayout = () => { return ( <> <Head> @@ -17,17 +16,11 @@ const CV: NextPageWithLayout<PageProps> = ({ page }) => { </Head> <article> <header> - <h1>{page.title}</h1> - {page.content && ( - <div dangerouslySetInnerHTML={{ __html: page.intro }}></div> - )} + <h1>{meta.title}</h1> + <div dangerouslySetInnerHTML={{ __html: intro }}></div> </header> <ToC /> - <div - dangerouslySetInnerHTML={{ - __html: page.content ? page.content : page.intro, - }} - ></div> + <CVContent /> </article> </> ); @@ -42,13 +35,11 @@ export const getStaticProps: GetStaticProps = async ( context.locale!, process.env.NODE_ENV === 'production' ); - const page = await getPageByUri('/cv/'); - const breadcrumbTitle = page.title; + const breadcrumbTitle = meta.title; return { props: { breadcrumbTitle, - page, translation, }, }; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 4146f34..3d4f6ff 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -4,18 +4,17 @@ import Head from 'next/head'; import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; import { NextPageWithLayout } from '@ts/types/app'; -import { HomePage, HomePageProps } from '@ts/types/homepage'; import { loadTranslation } from '@utils/helpers/i18n'; -import { getHomePage } from '@services/graphql/queries'; +import HomePageContent from '@content/pages/homepage.mdx'; -const Home: NextPageWithLayout<HomePageProps> = ({ data }) => { +const Home: NextPageWithLayout = () => { return ( <> <Head> <title>{seo.homepage.title}</title> <meta name="description" content={seo.homepage.description} /> </Head> - <div dangerouslySetInnerHTML={{ __html: data.content }}></div> + <HomePageContent /> </> ); }; @@ -30,11 +29,8 @@ export const getStaticProps: GetStaticProps = async (ctx) => { process.env.NODE_ENV === 'production' ); - const data: HomePage = await getHomePage(); - return { props: { - data, translation, }, }; diff --git a/src/pages/mentions-legales.tsx b/src/pages/mentions-legales.tsx index 41e9a0c..6bb1a55 100644 --- a/src/pages/mentions-legales.tsx +++ b/src/pages/mentions-legales.tsx @@ -1,14 +1,13 @@ import { getLayout } from '@components/Layouts/Layout'; import ToC from '@components/ToC/ToC'; import { seo } from '@config/seo'; -import { getPageByUri } from '@services/graphql/queries'; import { NextPageWithLayout } from '@ts/types/app'; -import { PageProps } from '@ts/types/pages'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; +import LegalNoticeContent, { meta } from '@content/pages/legal-notice.mdx'; -const LegalNotice: NextPageWithLayout<PageProps> = ({ page }) => { +const LegalNotice: NextPageWithLayout = () => { return ( <> <Head> @@ -17,17 +16,10 @@ const LegalNotice: NextPageWithLayout<PageProps> = ({ page }) => { </Head> <article> <header> - <h1>{page.title}</h1> - {page.content && ( - <div dangerouslySetInnerHTML={{ __html: page.intro }}></div> - )} + <h1>{meta.title}</h1> </header> <ToC /> - <div - dangerouslySetInnerHTML={{ - __html: page.content ? page.content : page.intro, - }} - ></div> + <LegalNoticeContent /> </article> </> ); @@ -42,13 +34,11 @@ export const getStaticProps: GetStaticProps = async ( context.locale!, process.env.NODE_ENV === 'production' ); - const page = await getPageByUri('/mentions-legales/'); - const breadcrumbTitle = page.title; + const breadcrumbTitle = meta.title; return { props: { breadcrumbTitle, - page, translation, }, }; diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts index 652caa1..a40446e 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -1,8 +1,6 @@ import { Slug } from '@ts/types/app'; import { Article, PostBy } from '@ts/types/articles'; import { AllPostsSlug, PostsList, RawPostsList } from '@ts/types/blog'; -import { HomePage, HomePageBy } from '@ts/types/homepage'; -import { Page, PageBy } from '@ts/types/pages'; import { AllSubjectsSlug, AllThematicsSlug, @@ -12,7 +10,6 @@ import { ThematicBy, } from '@ts/types/taxonomies'; import { - getFormattedPage, getFormattedPost, getFormattedPostPreview, getFormattedSubject, @@ -235,50 +232,6 @@ export const getPostBySlug = async (slug: string): Promise<Article> => { }; //============================================================================== -// Pages query -//============================================================================== - -export const getHomePage = async (): Promise<HomePage> => { - const query = gql` - query HomePage { - nodeByUri(uri: "/") { - ... on Page { - id - content - } - } - } - `; - - const response = await fetchApi<HomePageBy>(query, null); - const homepage = response.nodeByUri; - - return homepage; -}; - -export const getPageByUri = async (slug: string): Promise<Page> => { - const query = gql` - query PageByUri($slug: String!) { - pageBy(uri: $slug) { - contentParts { - afterMore - beforeMore - } - date - modified - title - } - } - `; - - const variables = { slug }; - const response = await fetchApi<PageBy>(query, variables); - const page = getFormattedPage(response.pageBy); - - return page; -}; - -//============================================================================== // Subject query //============================================================================== diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index e1d8917..2a1c9fc 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -5,8 +5,6 @@ import { PostBy } from './articles'; import { AllPostsSlug, RawPostsList } from './blog'; import { CommentData, CreateComment } from './comments'; import { ContactData, SendEmail } from './contact'; -import { HomePageBy } from './homepage'; -import { PageBy } from './pages'; import { AllSubjectsSlug, AllThematicsSlug, @@ -30,11 +28,7 @@ export type AppPropsWithLayout = AppProps & { // API //============================================================================== -export type VariablesType<T> = T extends - | PageBy - | PostBy - | SubjectBy - | ThematicBy +export type VariablesType<T> = T extends PostBy | SubjectBy | ThematicBy ? Slug : T extends RawPostsList ? CursorPagination @@ -49,8 +43,6 @@ export type RequestType = | AllSubjectsSlug | AllThematicsSlug | CreateComment - | HomePageBy - | PageBy | PostBy | SubjectBy | ThematicBy @@ -83,6 +75,12 @@ export type Heading = { title: string; }; +export type Meta = { + title: string; + publishedOn: string; + updatedOn: string; +}; + export type PageInfo = { endCursor: string; hasNextPage: boolean; diff --git a/src/ts/types/homepage.ts b/src/ts/types/homepage.ts deleted file mode 100644 index 8ff2ccb..0000000 --- a/src/ts/types/homepage.ts +++ /dev/null @@ -1,12 +0,0 @@ -export type HomePage = { - id: string; - content: string; -}; - -export type HomePageBy = { - nodeByUri: HomePage; -}; - -export type HomePageProps = { - data: HomePage; -}; diff --git a/src/ts/types/pages.ts b/src/ts/types/pages.ts deleted file mode 100644 index 93ff62e..0000000 --- a/src/ts/types/pages.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ContentParts, Dates } from './app'; - -export type Page = { - content: string; - dates: Dates; - intro: string; - title: string; -}; - -export type RawPage = { - contentParts: ContentParts; - date: string; - modified: string; - title: string; -}; - -export type PageBy = { - pageBy: RawPage; -}; - -export type PageProps = { - page: Page; -}; diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 8c5e545..fc7f1c2 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -5,7 +5,6 @@ import { RawArticlePreview, } from '@ts/types/articles'; import { Comment, RawComment } from '@ts/types/comments'; -import { Page, RawPage } from '@ts/types/pages'; import { RawSubject, RawThematic, @@ -202,25 +201,3 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { return formattedPost; }; - -/** - * Format a page from RawPage to Page type. - * @param page - A page coming from WP GraphQL. - * @returns A formatted page. - */ -export const getFormattedPage = (rawPage: RawPage): Page => { - const { date, modified } = rawPage; - const dates = { - publication: date, - update: modified, - }; - - const formattedPage: Page = { - ...rawPage, - content: rawPage.contentParts.afterMore, - dates, - intro: rawPage.contentParts.beforeMore, - }; - - return formattedPage; -}; |
