diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-23 19:32:42 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-23 20:53:58 +0200 |
| commit | c51b5d9a5f217f8aa59c4bdcb04eb3c87f5129b3 (patch) | |
| tree | a4ce7f77c2b1742119eebf818d9b97db7ed1e310 /src | |
| parent | 5ebd7c14f7303a0feb8ec1d902ecd0e287d929c3 (diff) | |
fix: ensure all topics/thematics have the base url
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/organisms/layout/posts-list.fixture.tsx | 8 | ||||
| -rw-r--r-- | src/components/organisms/layout/summary.fixture.tsx | 4 | ||||
| -rw-r--r-- | src/components/organisms/layout/summary.tsx | 4 | ||||
| -rw-r--r-- | src/pages/404.tsx | 8 | ||||
| -rw-r--r-- | src/pages/article/[slug].tsx | 8 | ||||
| -rw-r--r-- | src/pages/blog/index.tsx | 8 | ||||
| -rw-r--r-- | src/pages/blog/page/[number].tsx | 8 | ||||
| -rw-r--r-- | src/pages/recherche/index.tsx | 8 | ||||
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 8 | ||||
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 9 | ||||
| -rw-r--r-- | src/services/graphql/articles.ts | 4 | ||||
| -rw-r--r-- | src/services/graphql/thematics.ts | 2 | ||||
| -rw-r--r-- | src/services/graphql/topics.ts | 2 | ||||
| -rw-r--r-- | src/ts/types/app.ts | 2 | ||||
| -rw-r--r-- | src/utils/helpers/pages.ts | 16 |
15 files changed, 46 insertions, 53 deletions
diff --git a/src/components/organisms/layout/posts-list.fixture.tsx b/src/components/organisms/layout/posts-list.fixture.tsx index b0afdf8..e3f2378 100644 --- a/src/components/organisms/layout/posts-list.fixture.tsx +++ b/src/components/organisms/layout/posts-list.fixture.tsx @@ -25,8 +25,8 @@ export const posts: Post[] = [ dates: { publication: '2022-02-26' }, wordsCount: introPost1.split(' ').length, thematics: [ - { id: 1, name: 'Cat 1', slug: '#' }, - { id: 2, name: 'Cat 2', slug: '#' }, + { id: 1, name: 'Cat 1', url: '#' }, + { id: 2, name: 'Cat 2', url: '#' }, ], commentsCount: 1, }, @@ -39,7 +39,7 @@ export const posts: Post[] = [ meta: { dates: { publication: '2022-02-20' }, wordsCount: introPost2.split(' ').length, - thematics: [{ id: 2, name: 'Cat 2', slug: '#' }], + thematics: [{ id: 2, name: 'Cat 2', url: '#' }], commentsCount: 0, }, title: 'Debitis laudantium laudantium', @@ -52,7 +52,7 @@ export const posts: Post[] = [ cover, dates: { publication: '2021-12-20' }, wordsCount: introPost3.split(' ').length, - thematics: [{ id: 1, name: 'Cat 1', slug: '#' }], + thematics: [{ id: 1, name: 'Cat 1', url: '#' }], commentsCount: 3, }, title: 'Quaerat ut corporis', diff --git a/src/components/organisms/layout/summary.fixture.tsx b/src/components/organisms/layout/summary.fixture.tsx index fbc46a5..bb3ebcb 100644 --- a/src/components/organisms/layout/summary.fixture.tsx +++ b/src/components/organisms/layout/summary.fixture.tsx @@ -14,8 +14,8 @@ export const meta: SummaryMeta = { dates: { publication: '2022-04-11' }, wordsCount: intro.split(' ').length, thematics: [ - { id: 1, name: 'Cat 1', slug: '#' }, - { id: 2, name: 'Cat 2', slug: '#' }, + { id: 1, name: 'Cat 1', url: '#' }, + { id: 2, name: 'Cat 2', url: '#' }, ], commentsCount: 1, }; diff --git a/src/components/organisms/layout/summary.tsx b/src/components/organisms/layout/summary.tsx index ca51cd6..8807878 100644 --- a/src/components/organisms/layout/summary.tsx +++ b/src/components/organisms/layout/summary.tsx @@ -83,12 +83,12 @@ const Summary: FC<SummaryProps> = ({ : undefined, readingTime, thematics: thematics?.map((thematic) => ( - <Link key={thematic.id} href={thematic.slug}> + <Link key={thematic.id} href={thematic.url}> {thematic.name} </Link> )), topics: topics?.map((topic) => ( - <Link key={topic.id} href={topic.slug}> + <Link key={topic.id} href={topic.url}> {topic.name} </Link> )), diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 4ab7784..fd7187a 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -98,8 +98,9 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ <LinksListWidget key="thematics-list" items={getLinksListItems( - thematicsList.map(getPageLinkFromRawData), - 'thematic' + thematicsList.map((thematic) => + getPageLinkFromRawData(thematic, 'thematic') + ) )} title={thematicsListTitle} level={2} @@ -107,8 +108,7 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ <LinksListWidget key="topics-list" items={getLinksListItems( - topicsList.map(getPageLinkFromRawData), - 'topic' + topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) )} title={topicsListTitle} level={2} diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index c72d48e..5e75ae7 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -81,7 +81,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ thematics: thematics && thematics.map((thematic) => ( - <Link key={thematic.id} href={`/thematique/${thematic.slug}`}> + <Link key={thematic.id} href={thematic.url}> {thematic.name} </Link> )), @@ -99,11 +99,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ label: footerMetaLabel, value: topics.map((topic) => { return ( - <ButtonLink - key={topic.id} - target={`/sujet/${topic.slug}`} - className={styles.btn} - > + <ButtonLink key={topic.id} target={topic.url} className={styles.btn}> {topic.logo && <ResponsiveImage {...topic.logo} />} {topic.name} </ButtonLink> ); diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index cfd6f8c..3956308 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -153,8 +153,9 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ <LinksListWidget key="thematics-list" items={getLinksListItems( - thematicsList.map(getPageLinkFromRawData), - 'thematic' + thematicsList.map((thematic) => + getPageLinkFromRawData(thematic, 'thematic') + ) )} title={thematicsListTitle} level={2} @@ -162,8 +163,7 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ <LinksListWidget key="topics-list" items={getLinksListItems( - topicsList.map(getPageLinkFromRawData), - 'topic' + topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) )} title={topicsListTitle} level={2} diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx index 78b1db4..b5efd27 100644 --- a/src/pages/blog/page/[number].tsx +++ b/src/pages/blog/page/[number].tsx @@ -148,8 +148,9 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ <LinksListWidget key="thematics-list" items={getLinksListItems( - thematicsList.map(getPageLinkFromRawData), - 'thematic' + thematicsList.map((thematic) => + getPageLinkFromRawData(thematic, 'thematic') + ) )} title={thematicsListTitle} level={2} @@ -157,8 +158,7 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ <LinksListWidget key="topics-list" items={getLinksListItems( - topicsList.map(getPageLinkFromRawData), - 'topic' + topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) )} title={topicsListTitle} level={2} diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx index ab619fb..ffdbf44 100644 --- a/src/pages/recherche/index.tsx +++ b/src/pages/recherche/index.tsx @@ -165,8 +165,9 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({ <LinksListWidget key="thematics-list" items={getLinksListItems( - thematicsList.map(getPageLinkFromRawData), - 'thematic' + thematicsList.map((thematic) => + getPageLinkFromRawData(thematic, 'thematic') + ) )} title={thematicsListTitle} level={2} @@ -174,8 +175,7 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({ <LinksListWidget key="topics-list" items={getLinksListItems( - topicsList.map(getPageLinkFromRawData), - 'topic' + topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) )} title={topicsListTitle} level={2} diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 838f009..5c86720 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -138,13 +138,13 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({ ? [ <LinksListWidget key="related-thematics" - items={getLinksListItems(thematics, 'thematic')} + items={getLinksListItems(thematics)} title={thematicsListTitle} level={2} />, <LinksListWidget key="topics" - items={getLinksListItems(topics, 'topic')} + items={getLinksListItems(topics)} title={topicsListTitle} level={2} />, @@ -198,10 +198,10 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({ first: totalTopics, }); const allTopics = allTopicsEdges.edges.map((edge) => - getPageLinkFromRawData(edge.node) + getPageLinkFromRawData(edge.node, 'topic') ); const topicsLinks = allTopics.filter( - (topic) => topic.slug !== (params!.slug as TopicParams['slug']) + (topic) => topic.url !== `/sujet/${params!.slug as TopicParams['slug']}` ); const translation = await loadTranslation(locale); diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index 84ab134..0519731 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -118,13 +118,13 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ ? [ <LinksListWidget key="thematics" - items={getLinksListItems(thematics, 'thematic')} + items={getLinksListItems(thematics)} title={thematicsListTitle} level={2} />, <LinksListWidget key="related-topics" - items={getLinksListItems(topics, 'topic')} + items={getLinksListItems(topics)} title={topicsListTitle} level={2} />, @@ -178,10 +178,11 @@ export const getStaticProps: GetStaticProps<ThematicPageProps> = async ({ first: totalThematics, }); const allThematics = allThematicsEdges.edges.map((edge) => - getPageLinkFromRawData(edge.node) + getPageLinkFromRawData(edge.node, 'thematic') ); const allThematicsLinks = allThematics.filter( - (thematic) => thematic.slug !== (params!.slug as ThematicParams['slug']) + (thematic) => + thematic.url !== `/thematique/${params!.slug as ThematicParams['slug']}` ); const translation = await loadTranslation(locale); diff --git a/src/services/graphql/articles.ts b/src/services/graphql/articles.ts index f0ba4e4..27406ac 100644 --- a/src/services/graphql/articles.ts +++ b/src/services/graphql/articles.ts @@ -82,10 +82,10 @@ export const getArticleFromRawData = (data: RawArticle): Article => { title: seo?.title || '', }, thematics: acfPosts.postsInThematic?.map((thematic) => - getPageLinkFromRawData(thematic) + getPageLinkFromRawData(thematic, 'thematic') ), topics: acfPosts.postsInTopic?.map((topic) => - getPageLinkFromRawData(topic) + getPageLinkFromRawData(topic, 'topic') ), wordsCount: info.wordsCount, }, diff --git a/src/services/graphql/thematics.ts b/src/services/graphql/thematics.ts index fd9d9f5..4dc69e7 100644 --- a/src/services/graphql/thematics.ts +++ b/src/services/graphql/thematics.ts @@ -79,7 +79,7 @@ export const getThematicFromRawData = (data: RawThematic): Thematic => { posts.forEach((post) => { if (post.acfPosts.postsInTopic) { post.acfPosts.postsInTopic.forEach((topic) => - topics.push(getPageLinkFromRawData(topic)) + topics.push(getPageLinkFromRawData(topic, 'topic')) ); } }); diff --git a/src/services/graphql/topics.ts b/src/services/graphql/topics.ts index 277580f..0b1971b 100644 --- a/src/services/graphql/topics.ts +++ b/src/services/graphql/topics.ts @@ -80,7 +80,7 @@ export const getTopicFromRawData = (data: RawTopic): Topic => { posts.forEach((post) => { if (post.acfPosts.postsInThematic) { post.acfPosts.postsInThematic.forEach((thematic) => - thematics.push(getPageLinkFromRawData(thematic)) + thematics.push(getPageLinkFromRawData(thematic, 'thematic')) ); } }); diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index cb5429b..7bf1541 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -103,7 +103,7 @@ export type PageLink = { id: number; logo?: Image; name: string; - slug: string; + url: string; }; export type Article = Page<'article'>; diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts index 1a388e1..773d454 100644 --- a/src/utils/helpers/pages.ts +++ b/src/utils/helpers/pages.ts @@ -21,15 +21,17 @@ import { getImageFromRawData } from './images'; * @returns {PageLink} The link data (id, slug and title). */ export const getPageLinkFromRawData = ( - data: RawThematicPreview | RawTopicPreview + data: RawThematicPreview | RawTopicPreview, + kind: 'thematic' | 'topic' ): PageLink => { const { databaseId, featuredImage, slug, title } = data; + const baseUrl = kind === 'thematic' ? '/thematique/' : '/sujet/'; return { id: databaseId, logo: featuredImage ? getImageFromRawData(featuredImage?.node) : undefined, name: title, - slug, + url: `${baseUrl}${slug}`, }; }; @@ -37,19 +39,13 @@ export const getPageLinkFromRawData = ( * Convert page link data to an array of links items. * * @param {PageLink[]} links - An array of page links. - * @param {'thematic'|'topic'} kind - The page links kind. * @returns {LinksListItem[]} An array of links items. */ -export const getLinksListItems = ( - links: PageLink[], - kind: 'thematic' | 'topic' -): LinksListItems[] => { - const baseUrl = kind === 'thematic' ? '/thematique/' : '/sujet/'; - +export const getLinksListItems = (links: PageLink[]): LinksListItems[] => { return links.map((link) => { return { name: link.name, - url: `${baseUrl}${link.slug}`, + url: link.url, }; }); }; |
