diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-16 19:40:23 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-16 19:40:23 +0200 |
| commit | c77c58e18143233be042c4980a6ed08ae9beac52 (patch) | |
| tree | 94f7d828571a86470ae299fff7dffd32fb38de7c /src/pages | |
| parent | 2155550fa36a3bc3c8f66e0926530123b4018cd4 (diff) | |
chore: adjust and complete missing styles
* add logo to topics pages and links
* add Prism styles to articles
* and a few other adjustements
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/article/[slug].tsx | 43 | ||||
| -rw-r--r-- | src/pages/blog/index.tsx | 12 | ||||
| -rw-r--r-- | src/pages/cv.tsx | 19 | ||||
| -rw-r--r-- | src/pages/recherche/index.tsx | 12 | ||||
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 35 |
5 files changed, 86 insertions, 35 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 5eeabd9..995e3a9 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -1,5 +1,6 @@ import ButtonLink from '@components/atoms/buttons/button-link'; import Link from '@components/atoms/links/link'; +import ResponsiveImage from '@components/molecules/images/responsive-image'; import Sharing from '@components/organisms/widgets/sharing'; import PageLayout, { type PageLayoutProps, @@ -9,15 +10,20 @@ import { getArticleBySlug, } from '@services/graphql/articles'; import { getPostComments } from '@services/graphql/comments'; +import styles from '@styles/pages/article.module.scss'; import { type Article, type Comment } from '@ts/types/app'; import { loadTranslation, type Messages } from '@utils/helpers/i18n'; +import useAddPrismClassAttr from '@utils/hooks/use-add-prism-class-attr'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; +import usePrismPlugins, { PrismPlugin } from '@utils/hooks/use-prism-plugins'; import useSettings from '@utils/hooks/use-settings'; import { GetStaticPaths, GetStaticProps, NextPage } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; import { ParsedUrlQuery } from 'querystring'; +import { HTMLAttributes } from 'react'; +import { useIntl } from 'react-intl'; import { Blog, BlogPosting, Graph, WebPage } from 'schema-dts'; import useSWR from 'swr'; @@ -54,16 +60,31 @@ const ArticlePage: NextPage<ArticlePageProps> = ({ comments, post }) => { )), }; + const intl = useIntl(); + const footerMetaLabel = intl.formatMessage({ + defaultMessage: 'Read more articles about:', + description: 'ArticlePage: footer topics list label', + id: '50xc4o', + }); + const footerMeta: PageLayoutProps['footerMeta'] = { - topics: - topics && - topics.map((topic) => { + custom: topics && { + label: footerMetaLabel, + value: topics.map((topic) => { return ( - <ButtonLink key={topic.id} target={`/sujet/${topic.slug}`}> + <ButtonLink + key={topic.id} + target={`/sujet/${topic.slug}`} + className={styles.btn} + > + {topic.logo && ( + <ResponsiveImage className={styles.btn__icon} {...topic.logo} /> + )}{' '} {topic.name} </ButtonLink> ); }), + }, }; const { website } = useSettings(); @@ -156,6 +177,15 @@ const ArticlePage: NextPage<ArticlePageProps> = ({ comments, post }) => { }); }; + const prismPlugins: PrismPlugin[] = ['command-line', 'line-numbers']; + const { pluginsAttribute, pluginsClassName } = usePrismPlugins(prismPlugins); + useAddPrismClassAttr({ + attributes: { + 'data-filter-output': '#output#"', + }, + classNames: pluginsClassName, + }); + return ( <> <Head> @@ -173,6 +203,10 @@ const ArticlePage: NextPage<ArticlePageProps> = ({ comments, post }) => { /> <PageLayout allowComments={true} + bodyAttributes={{ + ...(pluginsAttribute as HTMLAttributes<HTMLDivElement>), + }} + bodyClassName={styles.body} breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} comments={data && getCommentsList(data)} @@ -185,6 +219,7 @@ const ArticlePage: NextPage<ArticlePageProps> = ({ comments, post }) => { widgets={[ <Sharing key="sharing-widget" + className={styles.widget} data={{ excerpt: intro, title, url: pageUrl }} media={[ 'diaspora', diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index a5ef045..b6ce221 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -114,16 +114,6 @@ const BlogPage: NextPage<BlogPageProps> = ({ '@graph': [webpageSchema, blogSchema], }; - const postsCount = intl.formatMessage( - { - defaultMessage: - '{postsCount, plural, =0 {No articles} one {# article} other {# articles}}', - id: 'OF5cPz', - description: 'BlogPage: posts count meta', - }, - { postsCount: totalArticles } - ); - /** * Retrieve the formatted meta. * @@ -231,7 +221,7 @@ const BlogPage: NextPage<BlogPageProps> = ({ title={title} breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} - headerMeta={{ total: postsCount }} + headerMeta={{ total: totalArticles }} widgets={[ <LinksListWidget key="thematics-list" diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index b3dec10..7936c84 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -1,4 +1,6 @@ +import Heading from '@components/atoms/headings/heading'; import Link from '@components/atoms/links/link'; +import List from '@components/atoms/lists/list'; import ImageWidget from '@components/organisms/widgets/image-widget'; import SocialMedia from '@components/organisms/widgets/social-media'; import PageLayout, { @@ -9,11 +11,12 @@ import styles from '@styles/pages/cv.module.scss'; import { loadTranslation } from '@utils/helpers/i18n'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; +import { NestedMDXComponents } from 'mdx/types'; import { GetStaticProps, NextPage } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; -import { ReactNode } from 'react'; +import React, { ReactNode } from 'react'; import { useIntl } from 'react-intl'; import { AboutPage, Graph, WebPage } from 'schema-dts'; @@ -141,6 +144,18 @@ const CVPage: NextPage = () => { '@graph': [webpageSchema, cvSchema], }; + const components: NestedMDXComponents = { + a: (props) => <Link external={true} {...props} />, + h1: (props) => <Heading level={1} {...props} />, + h2: (props) => <Heading level={2} {...props} />, + h3: (props) => <Heading level={3} {...props} />, + h4: (props) => <Heading level={4} {...props} />, + h5: (props) => <Heading level={5} {...props} />, + h6: (props) => <Heading level={6} {...props} />, + Link: (props) => <Link {...props} />, + List: (props) => <List {...props} />, + }; + return ( <PageLayout breadcrumb={breadcrumbItems} @@ -166,7 +181,7 @@ const CVPage: NextPage = () => { type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }} /> - <CVContent /> + <CVContent components={components} /> </PageLayout> ); }; diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx index 0a7dc60..d88a293 100644 --- a/src/pages/recherche/index.tsx +++ b/src/pages/recherche/index.tsx @@ -140,16 +140,6 @@ const SearchPage: NextPage<SearchPageProps> = ({ getTotalArticles(query.s as string) ); - const postsCount = intl.formatMessage( - { - defaultMessage: - '{postsCount, plural, =0 {No articles} one {# article} other {# articles}}', - id: 'LtsVOx', - description: 'SearchPage: posts count meta', - }, - { postsCount: totalArticles || 0 } - ); - /** * Retrieve the formatted meta. * @@ -244,7 +234,7 @@ const SearchPage: NextPage<SearchPageProps> = ({ title={title} breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} - headerMeta={{ total: postsCount }} + headerMeta={{ total: totalArticles }} widgets={[ <LinksListWidget key="thematics-list" diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 447d969..348fe05 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -1,4 +1,5 @@ import Heading from '@components/atoms/headings/heading'; +import ResponsiveImage from '@components/molecules/images/responsive-image'; import PostsList, { type Post } from '@components/organisms/layout/posts-list'; import LinksListWidget from '@components/organisms/widgets/links-list-widget'; import PageLayout, { @@ -10,6 +11,7 @@ import { getTopicsPreview, getTotalTopics, } from '@services/graphql/topics'; +import styles from '@styles/pages/topic.module.scss'; import { type Article, type PageLink, type Topic } from '@ts/types/app'; import { loadTranslation, type Messages } from '@utils/helpers/i18n'; import { @@ -35,7 +37,14 @@ export type TopicPageProps = { const TopicPage: NextPage<TopicPageProps> = ({ currentTopic, topics }) => { const { content, intro, meta, slug, title } = currentTopic; - const { articles, dates, seo, thematics } = meta; + const { + articles, + cover, + dates, + seo, + thematics, + website: officialWebsite, + } = meta; const intl = useIntl(); const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title, @@ -45,6 +54,8 @@ const TopicPage: NextPage<TopicPageProps> = ({ currentTopic, topics }) => { const headerMeta: PageLayoutProps['headerMeta'] = { publication: { date: dates.publication }, update: dates.update ? { date: dates.update } : undefined, + website: officialWebsite, + total: articles ? articles.length : undefined, }; const { website } = useSettings(); @@ -98,10 +109,10 @@ const TopicPage: NextPage<TopicPageProps> = ({ currentTopic, topics }) => { ...remainingData } = article; - const { cover, ...remainingMeta } = articleMeta; + const { cover: articleCover, ...remainingMeta } = articleMeta; return { - cover, + cover: articleCover, excerpt: articleIntro, meta: getPostMeta(remainingMeta), url: `/article/${articleSlug}`, @@ -122,6 +133,15 @@ const TopicPage: NextPage<TopicPageProps> = ({ currentTopic, topics }) => { id: '/sRqPT', }); + const getPageHeading = () => { + return ( + <> + {cover && <ResponsiveImage className={styles.logo} {...cover} />} + {title} + </> + ); + }; + return ( <> <Head> @@ -140,7 +160,7 @@ const TopicPage: NextPage<TopicPageProps> = ({ currentTopic, topics }) => { <PageLayout breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} - title={title} + title={getPageHeading()} intro={intro} headerMeta={headerMeta} widgets={ @@ -206,14 +226,15 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({ const allTopics = allTopicsEdges.edges.map((edge) => getPageLinkFromRawData(edge.node) ); + const topicsLinks = allTopics.filter( + (topic) => topic.slug !== (params!.slug as TopicParams['slug']) + ); const translation = await loadTranslation(locale); return { props: { currentTopic: JSON.parse(JSON.stringify(currentTopic)), - topics: allTopics.filter( - (topic) => topic.slug !== (params!.slug as TopicParams['slug']) - ), + topics: JSON.parse(JSON.stringify(topicsLinks)), translation, }, }; |
