From 82d310403c4bb09bc2f0a204b6374934a10cf348 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 29 Jan 2022 23:38:13 +0100 Subject: refactor(config): move config from config dir to utils --- src/pages/404.tsx | 4 ++-- src/pages/_app.tsx | 4 ++-- src/pages/article/[slug].tsx | 28 ++++++++++++++-------------- src/pages/blog/index.tsx | 38 +++++++++++++++++++------------------- src/pages/contact.tsx | 24 ++++++++++++------------ src/pages/cv.tsx | 26 +++++++++++++------------- src/pages/index.tsx | 24 ++++++++++++------------ src/pages/mentions-legales.tsx | 26 +++++++++++++------------- src/pages/projet/[slug].tsx | 24 ++++++++++++------------ src/pages/projets.tsx | 26 +++++++++++++------------- src/pages/recherche/index.tsx | 14 +++++++------- src/pages/sujet/[slug].tsx | 28 ++++++++++++++-------------- src/pages/thematique/[slug].tsx | 26 +++++++++++++------------- 13 files changed, 146 insertions(+), 146 deletions(-) (limited to 'src/pages') diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 079dead..d5b2e86 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,8 +1,8 @@ import { getLayout } from '@components/Layouts/Layout'; import PostHeader from '@components/PostHeader/PostHeader'; -import { config } from '@config/website'; import styles from '@styles/pages/Page.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; +import { settings } from '@utils/config'; import { getIntlInstance, loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; @@ -17,7 +17,7 @@ const Error404: NextPageWithLayout = () => { defaultMessage: 'Error 404: Page not found - {websiteName}', description: '404Page: SEO - Page title', }, - { websiteName: config.name } + { websiteName: settings.name } ); const pageDescription = intl.formatMessage({ defaultMessage: 'Page not found.', diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index ec97ff7..7c6142c 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,5 +1,5 @@ -import { config } from '@config/website'; import { AppPropsWithLayout } from '@ts/types/app'; +import { settings } from '@utils/config'; import { ThemeProvider } from 'next-themes'; import { useRouter } from 'next/router'; import { IntlProvider } from 'react-intl'; @@ -7,7 +7,7 @@ import '../styles/globals.scss'; const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => { const { locale, defaultLocale } = useRouter(); - const appLocale: string = locale || config.locales.defaultLocale; + const appLocale: string = locale || settings.locales.defaultLocale; const getLayout = Component.getLayout ?? ((page) => page); return ( diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 8668a66..dc2c76a 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -5,11 +5,11 @@ import PostFooter from '@components/PostFooter/PostFooter'; import PostHeader from '@components/PostHeader/PostHeader'; import Sidebar from '@components/Sidebar/Sidebar'; import { Sharing, ToC } from '@components/Widgets'; -import { config } from '@config/website'; import { getAllPostsSlug, getPostBySlug } from '@services/graphql/queries'; import styles from '@styles/pages/Page.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; import { ArticleMeta, ArticleProps } from '@ts/types/articles'; +import { settings } from '@utils/config'; import { loadTranslation } from '@utils/helpers/i18n'; import { addPrismClasses, translateCopyButton } from '@utils/helpers/prism'; import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; @@ -48,8 +48,8 @@ const SingleArticle: NextPageWithLayout = ({ post }) => { const intl = useIntl(); const router = useRouter(); - const locale = router.locale ? router.locale : config.locales.defaultLocale; - const articleUrl = `${config.url}${router.asPath}`; + const locale = router.locale ? router.locale : settings.locales.defaultLocale; + const articleUrl = `${settings.url}${router.asPath}`; useEffect(() => { addPrismClasses(); @@ -63,21 +63,21 @@ const SingleArticle: NextPageWithLayout = ({ post }) => { const webpageSchema: WebPage = { '@id': `${articleUrl}`, '@type': 'WebPage', - breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + breadcrumb: { '@id': `${settings.url}/#breadcrumb` }, lastReviewed: dates.update, name: seo.title, description: seo.metaDesc, - reviewedBy: { '@id': `${config.url}/#branding` }, + reviewedBy: { '@id': `${settings.url}/#branding` }, url: `${articleUrl}`, isPartOf: { - '@id': `${config.url}`, + '@id': `${settings.url}`, }, }; const blogSchema: Blog = { - '@id': `${config.url}/#blog`, + '@id': `${settings.url}/#blog`, '@type': 'Blog', - blogPost: { '@id': `${config.url}/#article` }, + blogPost: { '@id': `${settings.url}/#article` }, isPartOf: { '@id': `${articleUrl}`, }, @@ -88,24 +88,24 @@ const SingleArticle: NextPageWithLayout = ({ post }) => { const updateDate = new Date(dates.update); const blogPostSchema: BlogPosting = { - '@id': `${config.url}/#article`, + '@id': `${settings.url}/#article`, '@type': 'BlogPosting', name: title, description: intro, articleBody: content, - author: { '@id': `${config.url}/#branding` }, + author: { '@id': `${settings.url}/#branding` }, commentCount: comments.length, copyrightYear: publicationDate.getFullYear(), - creator: { '@id': `${config.url}/#branding` }, + creator: { '@id': `${settings.url}/#branding` }, dateCreated: publicationDate.toISOString(), dateModified: updateDate.toISOString(), datePublished: publicationDate.toISOString(), discussionUrl: `${articleUrl}/#comments`, - editor: { '@id': `${config.url}/#branding` }, + editor: { '@id': `${settings.url}/#branding` }, image: featuredImage?.sourceUrl, - inLanguage: config.locales.defaultLocale, + inLanguage: settings.locales.defaultLocale, isPartOf: { - '@id': `${config.url}/blog`, + '@id': `${settings.url}/blog`, }, license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', mainEntityOfPage: { '@id': `${articleUrl}` }, diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 9a86d9f..c0d99e9 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -6,11 +6,11 @@ import PostsList from '@components/PostsList/PostsList'; import Sidebar from '@components/Sidebar/Sidebar'; import Spinner from '@components/Spinner/Spinner'; import { ThematicsList, TopicsList } from '@components/Widgets'; -import { config } from '@config/website'; import { getPublishedPosts } from '@services/graphql/queries'; import styles from '@styles/pages/Page.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; import { BlogPageProps, PostsList as PostsListData } from '@ts/types/blog'; +import { settings } from '@utils/config'; import { getIntlInstance, loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; @@ -29,9 +29,9 @@ const Blog: NextPageWithLayout = ({ fallback }) => { if (previousData && !previousData.posts) return null; return pageIndex === 0 - ? { first: config.postsPerPage } + ? { first: settings.postsPerPage } : { - first: config.postsPerPage, + first: settings.postsPerPage, after: previousData.pageInfo.endCursor, }; }; @@ -48,13 +48,13 @@ const Blog: NextPageWithLayout = ({ fallback }) => { }, [data]); const [loadedPostsCount, setLoadedPostsCount] = useState( - config.postsPerPage + settings.postsPerPage ); useEffect(() => { if (data && data.length > 0) { const newCount = - config.postsPerPage + + settings.postsPerPage + data[0].pageInfo.total - data[data.length - 1].pageInfo.total; setLoadedPostsCount(newCount); @@ -91,7 +91,7 @@ const Blog: NextPageWithLayout = ({ fallback }) => { defaultMessage: 'Blog: development, open source - {websiteName}', description: 'BlogPage: SEO - Page title', }, - { websiteName: config.name } + { websiteName: settings.name } ); const pageDescription = intl.formatMessage( { @@ -99,31 +99,31 @@ const Blog: NextPageWithLayout = ({ fallback }) => { "Discover {websiteName}'s writings. He talks about web development, Linux and open source mostly.", description: 'BlogPage: SEO - Meta description', }, - { websiteName: config.name } + { websiteName: settings.name } ); - const pageUrl = `${config.url}${router.asPath}`; + const pageUrl = `${settings.url}${router.asPath}`; const webpageSchema: WebPage = { '@id': `${pageUrl}`, '@type': 'WebPage', - breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + breadcrumb: { '@id': `${settings.url}/#breadcrumb` }, name: pageTitle, description: pageDescription, - inLanguage: config.locales.defaultLocale, - reviewedBy: { '@id': `${config.url}/#branding` }, - url: `${config.url}`, + inLanguage: settings.locales.defaultLocale, + reviewedBy: { '@id': `${settings.url}/#branding` }, + url: `${settings.url}`, isPartOf: { - '@id': `${config.url}`, + '@id': `${settings.url}`, }, }; const blogSchema: BlogSchema = { - '@id': `${config.url}/#blog`, + '@id': `${settings.url}/#blog`, '@type': 'Blog', - author: { '@id': `${config.url}/#branding` }, - creator: { '@id': `${config.url}/#branding` }, - editor: { '@id': `${config.url}/#branding` }, - inLanguage: config.locales.defaultLocale, + author: { '@id': `${settings.url}/#branding` }, + creator: { '@id': `${settings.url}/#branding` }, + editor: { '@id': `${settings.url}/#branding` }, + inLanguage: settings.locales.defaultLocale, license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', mainEntityOfPage: { '@id': `${pageUrl}` }, }; @@ -213,7 +213,7 @@ export const getStaticProps: GetStaticProps = async ( defaultMessage: 'Blog', description: 'BlogPage: breadcrumb item', }); - const data = await getPublishedPosts({ first: config.postsPerPage }); + const data = await getPublishedPosts({ first: settings.postsPerPage }); const { locale } = context; const translation = await loadTranslation(locale); diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index 489135d..e410afa 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -4,10 +4,10 @@ import { getLayout } from '@components/Layouts/Layout'; import PostHeader from '@components/PostHeader/PostHeader'; import Sidebar from '@components/Sidebar/Sidebar'; import { SocialMedia } from '@components/Widgets'; -import { config } from '@config/website'; import { sendMail } from '@services/graphql/mutations'; import styles from '@styles/pages/Page.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; +import { settings } from '@utils/config'; import { getIntlInstance, loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; @@ -68,7 +68,7 @@ const ContactPage: NextPageWithLayout = () => { defaultMessage: 'Contact form - {websiteName}', description: 'ContactPage: SEO - Page title', }, - { websiteName: config.name } + { websiteName: settings.name } ); const pageDescription = intl.formatMessage( { @@ -76,9 +76,9 @@ const ContactPage: NextPageWithLayout = () => { "Contact {websiteName} through its website. All you need to do it's to fill the contact form.", description: 'ContactPage: SEO - Meta description', }, - { websiteName: config.name } + { websiteName: settings.name } ); - const pageUrl = `${config.url}${router.asPath}`; + const pageUrl = `${settings.url}${router.asPath}`; const title = intl.formatMessage({ defaultMessage: 'Contact', description: 'ContactPage: page title', @@ -91,25 +91,25 @@ const ContactPage: NextPageWithLayout = () => { const webpageSchema: WebPage = { '@id': `${pageUrl}`, '@type': 'WebPage', - breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + breadcrumb: { '@id': `${settings.url}/#breadcrumb` }, name: pageTitle, description: pageDescription, - reviewedBy: { '@id': `${config.url}/#branding` }, + reviewedBy: { '@id': `${settings.url}/#branding` }, url: `${pageUrl}`, isPartOf: { - '@id': `${config.url}`, + '@id': `${settings.url}`, }, }; const contactSchema: ContactPageSchema = { - '@id': `${config.url}/#contact`, + '@id': `${settings.url}/#contact`, '@type': 'ContactPage', name: title, description: intro, - author: { '@id': `${config.url}/#branding` }, - creator: { '@id': `${config.url}/#branding` }, - editor: { '@id': `${config.url}/#branding` }, - inLanguage: config.locales.defaultLocale, + author: { '@id': `${settings.url}/#branding` }, + creator: { '@id': `${settings.url}/#branding` }, + editor: { '@id': `${settings.url}/#branding` }, + inLanguage: settings.locales.defaultLocale, license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', mainEntityOfPage: { '@id': `${pageUrl}` }, }; diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index c3686de..311d0ce 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -2,11 +2,11 @@ import { getLayout } from '@components/Layouts/Layout'; import PostHeader from '@components/PostHeader/PostHeader'; import Sidebar from '@components/Sidebar/Sidebar'; import { CVPreview, SocialMedia, ToC } from '@components/Widgets'; -import { config } from '@config/website'; import CVContent, { intro, meta, pdf, image } from '@content/pages/cv.mdx'; import styles from '@styles/pages/Page.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; import { ArticleMeta } from '@ts/types/articles'; +import { settings } from '@utils/config'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; @@ -25,13 +25,13 @@ const CV: NextPageWithLayout = () => { const pageMeta: ArticleMeta = { dates, }; - const pageUrl = `${config.url}${router.asPath}`; + const pageUrl = `${settings.url}${router.asPath}`; const pageTitle = intl.formatMessage( { defaultMessage: 'CV Front-end developer - {websiteName}', description: 'CVPage: SEO - Page title', }, - { websiteName: config.name } + { websiteName: settings.name } ); const pageDescription = intl.formatMessage( { @@ -39,19 +39,19 @@ const CV: NextPageWithLayout = () => { 'Discover the curriculum of {websiteName}, front-end developer located in France: skills, experiences and training.', description: 'CVPage: SEO - Meta description', }, - { websiteName: config.name } + { websiteName: settings.name } ); const webpageSchema: WebPage = { '@id': `${pageUrl}`, '@type': 'WebPage', - breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + breadcrumb: { '@id': `${settings.url}/#breadcrumb` }, name: pageTitle, description: pageDescription, - reviewedBy: { '@id': `${config.url}/#branding` }, + reviewedBy: { '@id': `${settings.url}/#branding` }, url: `${pageUrl}`, isPartOf: { - '@id': `${config.url}`, + '@id': `${settings.url}`, }, }; @@ -59,18 +59,18 @@ const CV: NextPageWithLayout = () => { const updateDate = new Date(dates.update); const cvSchema: AboutPage = { - '@id': `${config.url}/#cv`, + '@id': `${settings.url}/#cv`, '@type': 'AboutPage', name: pageTitle, description: intro, - author: { '@id': `${config.url}/#branding` }, - creator: { '@id': `${config.url}/#branding` }, + author: { '@id': `${settings.url}/#branding` }, + creator: { '@id': `${settings.url}/#branding` }, dateCreated: publicationDate.toISOString(), dateModified: updateDate.toISOString(), datePublished: publicationDate.toISOString(), - editor: { '@id': `${config.url}/#branding` }, + editor: { '@id': `${settings.url}/#branding` }, image, - inLanguage: config.locales.defaultLocale, + inLanguage: settings.locales.defaultLocale, license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', thumbnailUrl: image, mainEntityOfPage: { '@id': `${pageUrl}` }, @@ -86,7 +86,7 @@ const CV: NextPageWithLayout = () => { defaultMessage: "{name}'s CV", description: 'CVPage: page title', }, - { name: config.name } + { name: settings.name } ); return ( diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 41a4603..0fe1a4f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -2,10 +2,10 @@ import FeedIcon from '@assets/images/icon-feed.svg'; import { ButtonLink } from '@components/Buttons'; import { ContactIcon } from '@components/Icons'; import Layout from '@components/Layouts/Layout'; -import { config } from '@config/website'; import HomePageContent from '@content/pages/homepage.mdx'; import styles from '@styles/pages/Home.module.scss'; import { NextPageWithLayout } from '@ts/types/app'; +import { settings } from '@utils/config'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; @@ -122,7 +122,7 @@ const Home: NextPageWithLayout = () => { defaultMessage: '{websiteName} | Front-end developer: WordPress/React', description: 'HomePage: SEO - Page title', }, - { websiteName: config.name } + { websiteName: settings.name } ); const pageDescription = intl.formatMessage( { @@ -130,22 +130,22 @@ const Home: NextPageWithLayout = () => { '{websiteName} is a front-end developer located in France. He codes and he writes mostly about web development and open-source.', description: 'HomePage: SEO - Meta description', }, - { websiteName: config.name } + { websiteName: settings.name } ); const webpageSchema: WebPage = { - '@id': `${config.url}/#home`, + '@id': `${settings.url}/#home`, '@type': 'WebPage', - breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + breadcrumb: { '@id': `${settings.url}/#breadcrumb` }, name: pageTitle, description: pageDescription, - author: { '@id': `${config.url}/#branding` }, - creator: { '@id': `${config.url}/#branding` }, - editor: { '@id': `${config.url}/#branding` }, - inLanguage: config.locales.defaultLocale, + author: { '@id': `${settings.url}/#branding` }, + creator: { '@id': `${settings.url}/#branding` }, + editor: { '@id': `${settings.url}/#branding` }, + inLanguage: settings.locales.defaultLocale, license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', - reviewedBy: { '@id': `${config.url}/#branding` }, - url: `${config.url}`, + reviewedBy: { '@id': `${settings.url}/#branding` }, + url: `${settings.url}`, }; const schemaJsonLd: Graph = { @@ -159,7 +159,7 @@ const Home: NextPageWithLayout = () => { {pageTitle} - +