diff --git a/src/application/dto/tag/tagDTO.ts b/src/application/dto/tag/tagDTO.ts index c884bb65..1ed9d52e 100644 --- a/src/application/dto/tag/tagDTO.ts +++ b/src/application/dto/tag/tagDTO.ts @@ -1,35 +1,37 @@ -import type { BaseDTO } from '@shared/application/dto/baseDTO.ts'; -import { groupBy } from './utils/groupBy'; -import type { ArticleDTO } from '@application/dto/article/articleDTO.ts'; -import { slugify } from '@shared/ui/utils/slugify'; - -export enum TagType { - TAG = 'tag', - AUTHOR = 'author' -} - -export interface TagDTOItem { - name: string; - type: TagType; - count: number -} - -export type TagDTO = Record; - -export const tagDTO: BaseDTO = { - render: (raw: ArticleDTO[]): TagDTO => { - const tags: TagDTOItem[] = raw.flatMap(article => ([ - ...article.data.tags.map((tag: string) => ({ name: tag, type: 'tag' })), - { name: slugify(article.data.author.data.name), type: 'author' } - ])); - - const uniqueTags: TagDTOItem[] = [...new Set(tags.map(tag => tag.name))].map(name => { - const type = tags.find(tag => tag.name === name)?.type ?? TagType.TAG; - const count = tags.filter(tag => tag.name === name).length; - - return { name, type, count }; - }).sort((a, b) => a.name.localeCompare(b.name)); - - return groupBy(uniqueTags, item => item.name.charAt(0).toUpperCase()); - }, -}; \ No newline at end of file +import type { BaseDTO } from "@shared/application/dto/baseDTO.ts"; +import { groupBy } from "./utils/groupBy"; +import type { ArticleDTO } from "@application/dto/article/articleDTO.ts"; +import { slugify } from "@shared/ui/utils/slugify"; + +export enum TagType { + TAG = "tag", + AUTHOR = "author", +} + +export interface TagDTOItem { + name: string; + type: TagType; + count: number; +} + +export type TagDTO = Record; + +export const tagDTO: BaseDTO = { + render: (raw: ArticleDTO[]): TagDTO => { + const tags: TagDTOItem[] = raw.flatMap((article) => [ + ...article.data.tags.map((tag: string) => ({ name: tag, type: "tag" })), + { name: slugify(article.data.author.data.name), type: "author" }, + ]); + + const uniqueTags: TagDTOItem[] = [...new Set(tags.map((tag) => tag.name))] + .map((name) => { + const type = tags.find((tag) => tag.name === name)?.type ?? TagType.TAG; + const count = tags.filter((tag) => tag.name === name).length; + + return { name, type, count }; + }) + .sort((a, b) => a.name.localeCompare(b.name)); + + return groupBy(uniqueTags, (item) => item.name.charAt(0).toUpperCase()); + }, +}; diff --git a/src/application/dto/tag/utils/groupBy/groupBy.ts b/src/application/dto/tag/utils/groupBy/groupBy.ts index 7842c47d..e2b389bf 100644 --- a/src/application/dto/tag/utils/groupBy/groupBy.ts +++ b/src/application/dto/tag/utils/groupBy/groupBy.ts @@ -1,10 +1,13 @@ -export function groupBy(array: T[], keyFn: (item: T) => K): Record { - return array.reduce((acc, currentItem) => { - const key = keyFn(currentItem); - - if (!acc[key]) acc[key] = []; - acc[key].push(currentItem); - - return acc; - }, {} as Record); -} \ No newline at end of file +export function groupBy(array: T[], keyFn: (item: T) => K): Record { + return array.reduce( + (acc, currentItem) => { + const key = keyFn(currentItem); + + if (!acc[key]) acc[key] = []; + acc[key].push(currentItem); + + return acc; + }, + {} as Record, + ); +} diff --git a/src/application/dto/tag/utils/groupBy/index.ts b/src/application/dto/tag/utils/groupBy/index.ts index afa7ad42..7a62d249 100644 --- a/src/application/dto/tag/utils/groupBy/index.ts +++ b/src/application/dto/tag/utils/groupBy/index.ts @@ -1 +1 @@ -export * from './groupBy' \ No newline at end of file +export * from "./groupBy"; diff --git a/src/const/types.ts b/src/const/types.ts index b2d35395..19177fe4 100644 --- a/src/const/types.ts +++ b/src/const/types.ts @@ -24,8 +24,8 @@ export interface SeoMetadata { title: string; description: string; robots?: { - index?: boolean; - follow?: boolean; + index: boolean; + follow: boolean; }; image: string; } diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 003dd843..e7566592 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,6 +1,6 @@ import rss from "@astrojs/rss"; import { getCollection } from "astro:content"; -import { DEFAULT_SEO_PARAMS } from '@const/index.js'; +import { DEFAULT_SEO_PARAMS } from "@const/index.js"; export async function GET(context) { const posts = await getCollection("articles");