aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/author.ts
blob: cf125fcc02e0ffc7b6d1662d9f630c8af1add1f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { type Author, type AuthorKind } from '@ts/types/app';
import { type RawAuthor } from '@ts/types/raw-data';

/**
 * Convert author raw data to regular data.
 *
 * @param {RawAuthor<AuthorKind>} data - The author raw data.
 * @param {AuthorKind} kind - The author kind. Either `page` or `comment`.
 * @param {number} [avatarSize] - The author avatar size.
 * @returns {Author<AuthorKind>} The author data.
 */
export const getAuthorFromRawData = (
  data: RawAuthor<typeof kind>,
  kind: AuthorKind,
  avatarSize: number = 80
): Author<typeof kind> => {
  const { name, description, gravatarUrl, url } = data;

  return {
    name,
    avatar: gravatarUrl
      ? {
          alt: `${name} avatar`,
          height: avatarSize,
          src: gravatarUrl,
          width: avatarSize,
        }
      : undefined,
    description,
    website: url,
  };
};