Refactored navigation icon processing and improved error handling in transformNavigation function
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-09-24 21:58:08 +01:00
parent b406165866
commit f36dfb63df
3 changed files with 24 additions and 10 deletions

View File

@ -7,12 +7,10 @@ export async function importNotionNavigation(env) {
const notionProperties = await queryNotionDataSource(env.PROPERTIES_DB);
// Transform the incoming pages for the given type
const navigationItems = (
await Promise.all(
notionPages.map(async (item) => transformNavigation(item, "page")),
notionProperties.map(async (item) =>
transformNavigation(item, "property")
)
)
await Promise.all([
...notionPages.map((item) => transformNavigation(item, "page")),
...notionProperties.map((item) => transformNavigation(item, "property")),
])
).filter(Boolean);
// Store the updated cache

View File

@ -22,13 +22,25 @@ async function processSVG(svgText, cssClass) {
}
}
function notionIconUrl(iconObj) {
return (
iconObj?.external?.url ||
iconObj?.file?.url ||
iconObj?.custom_emoji?.url ||
iconObj?.url
);
}
// processNotionIcon fetches and validates the SVG
export async function processNotionIcon(iconObj, cssClass = "") {
if (iconObj?.external?.url && iconObj?.url) {
return undefined;
if (iconObj?.type === "emoji") {
return iconObj.emoji;
}
const url = iconObj?.external?.url || iconObj.url;
const url = notionIconUrl(iconObj);
if (!url) {
return undefined;
}
const urlObject = new URL(url);

View File

@ -72,7 +72,11 @@ export async function storeNavigation(env, navigation) {
export async function transformNavigation(notionPage, type) {
var icon = undefined;
if (notionPage.icon) {
try {
icon = await processNotionIcon(notionPage.icon, "th-icon");
} catch (error) {
console.error("Error processing navigation icon:", error);
}
}
const properties = notionPage.properties;
const id = notionPage.id;