From 9311bf355e433b9804ff4941ca390b6700fc457d Mon Sep 17 00:00:00 2001 From: Julian Jark Date: Tue, 6 Jun 2023 23:23:25 +0200 Subject: [PATCH] :sparkles: add getCover helper function --- packages/notion-utils/CHANGELOG.md | 6 ++++++ packages/notion-utils/package.json | 2 +- packages/notion-utils/src/helpers.ts | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/notion-utils/CHANGELOG.md b/packages/notion-utils/CHANGELOG.md index fa3e1ac..3afc02e 100644 --- a/packages/notion-utils/CHANGELOG.md +++ b/packages/notion-utils/CHANGELOG.md @@ -1,5 +1,11 @@ # @vargtech/notion-utils +## 0.0.6 + +### Patch Changes + +- add getCover + ## 0.0.5 ### Patch Changes diff --git a/packages/notion-utils/package.json b/packages/notion-utils/package.json index b4e251c..f76cde3 100644 --- a/packages/notion-utils/package.json +++ b/packages/notion-utils/package.json @@ -1,6 +1,6 @@ { "name": "@vargtech/notion-utils", - "version": "0.0.5", + "version": "0.0.6", "description": "Helper functions for the Notion API", "author": "Julian Jark", "license": "ISC", diff --git a/packages/notion-utils/src/helpers.ts b/packages/notion-utils/src/helpers.ts index 4466e63..ff45f0d 100644 --- a/packages/notion-utils/src/helpers.ts +++ b/packages/notion-utils/src/helpers.ts @@ -86,6 +86,15 @@ export const getDate = (name: string, fromPage: PageObjectResponse) => { return undefined; }; +export const getCover = (fromPage: PageObjectResponse) => { + if (fromPage.cover?.type === "external") { + return fromPage.cover.external.url; + } else if (fromPage.cover?.type === "file") { + return fromPage.cover.file.url; + } + return undefined; +}; + export const getImage = (name: string, fromPage: PageObjectResponse) => { const property = fromPage.properties[name]; if (property?.type === "files") {