diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-06 18:08:04 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | c9c1c90b30e243563bb4f731da15b3fe657556d2 (patch) | |
| tree | 8263c176b4096e2893b9d9319bfa7edb01fce188 /src/utils/helpers/pages.ts | |
| parent | 2771de88f40a5f4ed7480bd8614532dda72deeda (diff) | |
refactor(components): replace Summary component with PostPreview
* rename component to PostPreview because Summary is an HTML element
and it could lead to confusion
* replace `title` and `titleLevel` with `heading` and `headingLvl`
because `title` is a native attribute
* rename `intro` prop to `excerpt`
* extract `cover` from `meta` prop
* rewrite meta type
* extract meta logic into a new component
Diffstat (limited to 'src/utils/helpers/pages.ts')
| -rw-r--r-- | src/utils/helpers/pages.ts | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts deleted file mode 100644 index 84854cd..0000000 --- a/src/utils/helpers/pages.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { LinksListItems, Post } from '../../components'; -import { getArticleFromRawData } from '../../services/graphql'; -import type { - Article, - EdgesResponse, - PageLink, - RawArticle, - RawThematicPreview, - RawTopicPreview, -} from '../../types'; -import { ROUTES } from '../constants'; -import { getImageFromRawData } from './images'; - -/** - * Convert raw data to a Link object. - * - * @param data - An object. - * @param {number} data.databaseId - The data id. - * @param {number} [data.logo] - The data logo. - * @param {string} data.slug - The data slug. - * @param {string} data.title - The data name. - * @returns {PageLink} The link data (id, slug and title). - */ -export const getPageLinkFromRawData = ( - data: RawThematicPreview | RawTopicPreview, - kind: 'thematic' | 'topic' -): PageLink => { - const { databaseId, featuredImage, slug, title } = data; - const baseUrl = `${ - kind === 'thematic' ? ROUTES.THEMATICS.INDEX : ROUTES.TOPICS - }/`; - - return { - id: databaseId, - logo: featuredImage ? getImageFromRawData(featuredImage.node) : undefined, - name: title, - url: `${baseUrl}${slug}`, - }; -}; - -/** - * Method to sort PageLink objects by name. - * - * @param {PageLink} a - A PageLink object. - * @param {PageLink} b - Another PageLink object. - * @returns {1 | -1 | 0} - */ -export const sortPageLinksByName = (a: PageLink, b: PageLink) => { - const nameA = a.name.toUpperCase(); - const nameB = b.name.toUpperCase(); - - if (nameA < nameB) return -1; - if (nameA > nameB) return 1; - return 0; -}; - -/** - * Convert page link data to an array of links items. - * - * @param {PageLink[]} links - An array of page links. - * @returns {LinksListItem[]} An array of links items. - */ -export const getLinksListItems = (links: PageLink[]): LinksListItems[] => - links.map((link) => { - return { - name: link.name, - url: link.url, - }; - }); - -/** - * Retrieve the posts list with the article URL. - * - * @param {Article[]} posts - An array of articles. - * @returns {Post[]} An array of posts with full article URL. - */ -export const getPostsWithUrl = (posts: Article[]): Post[] => - posts.map((post) => { - return { - ...post, - url: `/article/${post.slug}`, - }; - }); - -/** - * Retrieve the posts list from raw data. - * - * @param {EdgesResponse<RawArticle>[]} rawData - The raw data. - * @returns {Post[]} An array of posts. - */ -export const getPostsList = (rawData: EdgesResponse<RawArticle>[]): Post[] => { - const articlesList: RawArticle[] = []; - rawData.forEach((articleData) => { - articleData.edges.forEach((edge) => { - articlesList.push(edge.node); - }); - }); - - return getPostsWithUrl( - articlesList.map((article) => getArticleFromRawData(article)) - ); -}; |
