diff --git a/blog/app/author/[author]/[[...page]]/page.tsx b/blog/app/author/[author]/[[...page]]/page.tsx index a09ceec..5716c61 100644 --- a/blog/app/author/[author]/[[...page]]/page.tsx +++ b/blog/app/author/[author]/[[...page]]/page.tsx @@ -1,12 +1,8 @@ /* eslint-disable sonarjs/no-duplicate-string */ /* eslint-disable sonarjs/no-nested-template-literals */ -import { formatRecord } from 'ens-tools/dist/format'; import { ResolvingMetadata } from 'next'; -import Link from 'next/link'; -import { ReactElement } from 'react'; -import { FaDiscord, FaTelegram } from 'react-icons/fa'; -import { FiGithub, FiGlobe, FiMail } from 'react-icons/fi'; +import { Author } from '@/components/Author'; import { PageButtons } from '@/components/PageButtons'; import { BlogPostPreview } from '@/components/PostPreview'; import { getAuthorMetadata } from '@/lib/get_author_metadata'; @@ -94,119 +90,9 @@ const page = async ({ params }: PageProperties) => { return (

- {params.author}’s articles + {params.author}'s articles

-
-
- {params.author} -
-
-
-
- {params.author} -
- - {author_metadata?.records.description && ( -
{author_metadata.records.description}
- )} - - {params.author.endsWith('.eth') && ( - - {params.author + '.link'} - - )} -
-
- {( - [ - [ - 'com.twitter', - 'https://x.com/' + - formatRecord( - 'com.twitter', - author_metadata.records[ - 'com.twitter' - ] - ), - - {'𝕏'} - , - ], - [ - 'email', - 'mailto:' + - author_metadata.records['email'], - , - ], - [ - 'org.telegram', - 'https://t.me/' + - formatRecord( - 'org.telegram', - author_metadata.records[ - 'org.telegram' - ] - ), - , - ], - [ - 'url', - author_metadata.records.url, - , - ], - [ - 'com.github', - 'https://github.com/' + - formatRecord( - 'com.github', - author_metadata.records[ - 'com.github' - ] - ), - , - ], - [ - 'com.discord', - formatRecord( - 'com.discord', - author_metadata.records['com.discord'] - ), - , - ], - ] as [ - keyof typeof author_metadata.records, - string, - ReactElement - ][] - ) - .filter( - ([record, url, _element]) => - author_metadata.records[record] && !!url - ) - .map(([record, url, element]) => ( - - {element} - - ))} -
-
-
+
+ ); diff --git a/blog/public/icons/x.svg b/blog/public/icons/x.svg new file mode 100644 index 0000000..56368dd --- /dev/null +++ b/blog/public/icons/x.svg @@ -0,0 +1,3 @@ + + + diff --git a/blog/src/components/Author.tsx b/blog/src/components/Author.tsx new file mode 100644 index 0000000..575bb0a --- /dev/null +++ b/blog/src/components/Author.tsx @@ -0,0 +1,198 @@ +/* eslint-disable sonarjs/no-duplicate-string */ +import { avatars } from 'assets/assets'; +import { formatRecord } from 'ens-tools/dist/format'; +import Link from 'next/link'; +import { FC } from 'react'; +import { ReactElement } from 'react'; +import { FaDiscord, FaTelegram } from 'react-icons/fa'; +import { FiGithub, FiGlobe, FiMail, FiUser } from 'react-icons/fi'; + +import { cx } from '@/lib/cx'; +import { getAuthorMetadata } from '@/lib/get_author_metadata'; + +type ENStateResponse = { + name: string; + address: string; + avatar: string; + display: string; +}; + +export const Author: FC<{ + name: string; + socials?: boolean; + size?: 'normal' | 'small'; + link?: boolean; +}> = async ({ name, socials = true, size = 'normal', link = false }) => { + const author_metadata = await getAuthorMetadata(name); + + let avatar = avatars[name as keyof typeof avatars] + ? await avatars[name as keyof typeof avatars].avatar.then( + (imported) => imported.default.src + ) + : undefined; + + if (!avatar) { + const response = await fetch('https://enstate.rs/n/' + name); + + const data: ENStateResponse | undefined = + response.status === 200 ? await response.json() : undefined; + + if (response.status != 200) { + console.error('Enstate silently errored', response.body); + } + + avatar = data?.avatar; + } + + if (!avatar) { + const metadataResponse = await fetch( + `https://metadata.ens.domains/mainnet/avatar/${name}`, + { method: 'HEAD' } + ); + + if (metadataResponse.status === 200) { + avatar = `https://metadata.ens.domains/mainnet/avatar/${name}`; + } + } + + return ( +
+ {link && ( + + )} +
+ {avatar ? ( + {name} + ) : ( +
+ +
+ )} +
+
+
+
+ {name} +
+ + {author_metadata?.records.description && ( +
+ {author_metadata.records.description} +
+ )} + + {name.endsWith('.eth') && ( + + {name + '.link'} + + )} +
+ + {socials && ( +
+ {( + [ + [ + 'com.twitter', + 'https://x.com/' + + formatRecord( + 'com.twitter', + author_metadata.records[ + 'com.twitter' + ] + ), + + {'𝕏'} + , + ], + [ + 'email', + 'mailto:' + + author_metadata.records['email'], + , + ], + [ + 'org.telegram', + 'https://t.me/' + + formatRecord( + 'org.telegram', + author_metadata.records[ + 'org.telegram' + ] + ), + , + ], + [ + 'url', + author_metadata.records.url, + , + ], + [ + 'com.github', + 'https://github.com/' + + formatRecord( + 'com.github', + author_metadata.records[ + 'com.github' + ] + ), + , + ], + [ + 'com.discord', + formatRecord( + 'com.discord', + author_metadata.records['com.discord'] + ), + , + ], + ] as [ + keyof typeof author_metadata.records, + string, + ReactElement + ][] + ) + .filter( + ([record, url, _element]) => + author_metadata.records[record] && !!url + ) + .map(([record, url, element]) => ( + + {element} + + ))} +
+ )} +
+
+ ); +}; diff --git a/blog/src/components/post/PostFooter.tsx b/blog/src/components/post/PostFooter.tsx new file mode 100644 index 0000000..06f3ed6 --- /dev/null +++ b/blog/src/components/post/PostFooter.tsx @@ -0,0 +1,68 @@ +/* eslint-disable sonarjs/no-duplicate-string */ +import Image from 'next/image'; +import { FaFacebookF, FaLinkedin } from 'react-icons/fa'; + +import { BlogPostMetadata } from '@/types/BlogPostMetadata'; + +import xLogo from '../../../public/icons/x.svg'; +import { Author } from '../Author'; +import { BigTag } from '../tags/BigTag'; + +export const PostFooter = ({ post }: { post: BlogPostMetadata }) => { + return ( +
+ {/* add a horizontal line to indicate start of footer */} +
+
+ {post.authors.map((author) => ( + + ))} +
+
+ {/* insert share buttons for twitter, linkedin and facebook */} + +
+ {post.tags.map((tag) => ( + + ))} +
+
+ + X logo + + + + + + + +
+
+
+ ); +}; diff --git a/blog/tailwind.config.js b/blog/tailwind.config.js index 3f1c97e..9fee88a 100644 --- a/blog/tailwind.config.js +++ b/blog/tailwind.config.js @@ -60,6 +60,9 @@ module.exports = { borderRadius: { ens: '16px', }, + screens: { + xs: '448px', + }, }, }, };