From 6a2850414eb84896d48527c19279860e0e47307d Mon Sep 17 00:00:00 2001 From: Luan Argolo Lemos Date: Mon, 6 Jan 2025 16:22:16 -0300 Subject: [PATCH] feat(blog): expose unique identifier (#983) * feat(blog): expose unique identifier * feat(blog): define id prop to optional --- blog/types.ts | 2 ++ blog/utils/records.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/blog/types.ts b/blog/types.ts index 222b953e0..0450ce82a 100644 --- a/blog/types.ts +++ b/blog/types.ts @@ -58,6 +58,8 @@ export interface BlogPost { * @title Extra Props */ extraProps?: ExtraProps[]; + /** @hide true */ + id?: string; } export interface ExtraProps { diff --git a/blog/utils/records.ts b/blog/utils/records.ts index 6e19e463b..e65890417 100644 --- a/blog/utils/records.ts +++ b/blog/utils/records.ts @@ -11,5 +11,11 @@ export async function getRecordsByPath( const current = Object.entries(resolvables).flatMap(([key, value]) => { return key.startsWith(path) ? value : []; }); - return (current as Record[]).map((item) => item[accessor]); + return (current as Record[]).map((item) => { + const id = (item.name as string).split(path)[1]?.replace("/", ""); + return { + ...item[accessor], + id, + }; + }); }