From 48daa6a5171602685e8b79b0e3694015c9d30d05 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Dec 2021 13:35:33 +0100 Subject: build: add a git submodule to manage content in a separate repo --- src/content | 1 + 1 file changed, 1 insertion(+) create mode 160000 src/content (limited to 'src') diff --git a/src/content b/src/content new file mode 160000 index 0000000..9f37f10 --- /dev/null +++ b/src/content @@ -0,0 +1 @@ +Subproject commit 9f37f1095e625ef2d42dd3c64144b77424ac4ead -- cgit v1.2.3 From a35f1a9c2564557aea9bca4abb8db5f820a7ad79 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Dec 2021 15:03:41 +0100 Subject: build: add a typescript declaration file for MDX I need to inform Typescript than I am exporting a meta constant from MDX files. --- mdx.d.ts | 7 +++++++ src/ts/types/app.ts | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 mdx.d.ts (limited to 'src') diff --git a/mdx.d.ts b/mdx.d.ts new file mode 100644 index 0000000..b77b39d --- /dev/null +++ b/mdx.d.ts @@ -0,0 +1,7 @@ +declare module '*.mdx' { + import { Meta } from '@ts/types/app'; + + let MDXComponent: (props: any) => JSX.Element; + export default MDXComponent; + export const meta: Meta; +} diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index e1d8917..a8c552d 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -83,6 +83,12 @@ export type Heading = { title: string; }; +export type Meta = { + title: string; + publishedOn: string; + updatedOn: string; +}; + export type PageInfo = { endCursor: string; hasNextPage: boolean; -- cgit v1.2.3 From 8105e2577d4aa401f960e78085f6038eb879ee8a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Dec 2021 15:06:12 +0100 Subject: chore: replace legal notice page content with MDX content I cannot use WordPress shortcodes from a custom plugin through WP GraphQL so I'm using mdx file instead to define the page content. --- src/content | 2 +- src/pages/mentions-legales.tsx | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/content b/src/content index 9f37f10..cc48676 160000 --- a/src/content +++ b/src/content @@ -1 +1 @@ -Subproject commit 9f37f1095e625ef2d42dd3c64144b77424ac4ead +Subproject commit cc486766242f106dbefabb70c6a78b2470490d00 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 = ({ page }) => { +const LegalNotice: NextPageWithLayout = () => { return ( <> @@ -17,17 +16,10 @@ const LegalNotice: NextPageWithLayout = ({ page }) => {
-

{page.title}

- {page.content && ( -
- )} +

{meta.title}

-
+
); @@ -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, }, }; -- cgit v1.2.3 From 3956ed77e11455a963ce17a64783d70fa666a7a0 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Dec 2021 15:13:19 +0100 Subject: chore: replace homepage content with MDX content I cannot import custom blocks through WP GraphQL, so I prefer to use MDX file. This way I cannot import custom components. --- src/pages/index.tsx | 10 +++------- src/services/graphql/queries.ts | 19 ------------------- src/ts/types/app.ts | 2 -- src/ts/types/homepage.ts | 12 ------------ 4 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 src/ts/types/homepage.ts (limited to 'src') 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 = ({ data }) => { +const Home: NextPageWithLayout = () => { return ( <> {seo.homepage.title} -
+ ); }; @@ -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/services/graphql/queries.ts b/src/services/graphql/queries.ts index 652caa1..518cf75 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -1,7 +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, @@ -238,24 +237,6 @@ export const getPostBySlug = async (slug: string): Promise
=> { // Pages query //============================================================================== -export const getHomePage = async (): Promise => { - const query = gql` - query HomePage { - nodeByUri(uri: "/") { - ... on Page { - id - content - } - } - } - `; - - const response = await fetchApi(query, null); - const homepage = response.nodeByUri; - - return homepage; -}; - export const getPageByUri = async (slug: string): Promise => { const query = gql` query PageByUri($slug: String!) { diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index a8c552d..ebd604c 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -5,7 +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, @@ -49,7 +48,6 @@ export type RequestType = | AllSubjectsSlug | AllThematicsSlug | CreateComment - | HomePageBy | PageBy | PostBy | SubjectBy 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; -}; -- cgit v1.2.3 From 0bb6411ee9fce02c2e5680f2be5740a1bbb508ad Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Dec 2021 15:35:33 +0100 Subject: chore: replace CV content with mdx content Since I replace the other pages, there is no reason to fetch this page content through WP GraphQL. --- mdx.d.ts | 1 + src/content | 2 +- src/pages/cv.tsx | 21 ++++++--------------- src/services/graphql/queries.ts | 28 ---------------------------- src/ts/types/app.ts | 8 +------- src/ts/types/pages.ts | 23 ----------------------- src/utils/helpers/format.ts | 23 ----------------------- 7 files changed, 9 insertions(+), 97 deletions(-) delete mode 100644 src/ts/types/pages.ts (limited to 'src') diff --git a/mdx.d.ts b/mdx.d.ts index b77b39d..fb9f909 100644 --- a/mdx.d.ts +++ b/mdx.d.ts @@ -4,4 +4,5 @@ declare module '*.mdx' { let MDXComponent: (props: any) => JSX.Element; export default MDXComponent; export const meta: Meta; + export const intro: string; } diff --git a/src/content b/src/content index cc48676..d6f4c2f 160000 --- a/src/content +++ b/src/content @@ -1 +1 @@ -Subproject commit cc486766242f106dbefabb70c6a78b2470490d00 +Subproject commit d6f4c2ff1510272a42da208dde9340dbb1857538 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 = ({ page }) => { +const CV: NextPageWithLayout = () => { return ( <> @@ -17,17 +16,11 @@ const CV: NextPageWithLayout = ({ page }) => {
-

{page.title}

- {page.content && ( -
- )} +

{meta.title}

+
-
+
); @@ -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/services/graphql/queries.ts b/src/services/graphql/queries.ts index 518cf75..a40446e 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -1,7 +1,6 @@ import { Slug } from '@ts/types/app'; import { Article, PostBy } from '@ts/types/articles'; import { AllPostsSlug, PostsList, RawPostsList } from '@ts/types/blog'; -import { Page, PageBy } from '@ts/types/pages'; import { AllSubjectsSlug, AllThematicsSlug, @@ -11,7 +10,6 @@ import { ThematicBy, } from '@ts/types/taxonomies'; import { - getFormattedPage, getFormattedPost, getFormattedPostPreview, getFormattedSubject, @@ -233,32 +231,6 @@ export const getPostBySlug = async (slug: string): Promise
=> { return post; }; -//============================================================================== -// Pages query -//============================================================================== - -export const getPageByUri = async (slug: string): Promise => { - const query = gql` - query PageByUri($slug: String!) { - pageBy(uri: $slug) { - contentParts { - afterMore - beforeMore - } - date - modified - title - } - } - `; - - const variables = { slug }; - const response = await fetchApi(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 ebd604c..2a1c9fc 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -5,7 +5,6 @@ import { PostBy } from './articles'; import { AllPostsSlug, RawPostsList } from './blog'; import { CommentData, CreateComment } from './comments'; import { ContactData, SendEmail } from './contact'; -import { PageBy } from './pages'; import { AllSubjectsSlug, AllThematicsSlug, @@ -29,11 +28,7 @@ export type AppPropsWithLayout = AppProps & { // API //============================================================================== -export type VariablesType = T extends - | PageBy - | PostBy - | SubjectBy - | ThematicBy +export type VariablesType = T extends PostBy | SubjectBy | ThematicBy ? Slug : T extends RawPostsList ? CursorPagination @@ -48,7 +43,6 @@ export type RequestType = | AllSubjectsSlug | AllThematicsSlug | CreateComment - | PageBy | PostBy | SubjectBy | ThematicBy 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; -}; -- cgit v1.2.3