Skip to main content

Overview

The getMetadata utility function fetches metadata from a given URL using a Supabase Edge Function. It extracts information like title, description, images, and domain from web pages.

Function Signature

const getMetadata = async (url: string): Promise<Metadata | null>

Parameters

url
string
required
The URL to extract metadata from

Return Value

Metadata
object | null
Returns a Metadata object on success, or null if the request fails

Usage Example

import getMetadata from "../utils/getMetadata"
import { showErrorToast, showSuccessToast } from "../utils/showToast"

const refreshMetadata = async (url: string) => {
  const toastId = showLoadingToast("Searching for new metadata...")
  const newMetadata = await getMetadata(url)
  
  if (!newMetadata) {
    return showErrorToast("Failed to retrieve new metadata.", { id: toastId })
  }
  
  const { title, domain, description, images } = newMetadata
  
  // Update bookmark with new metadata
  const response = await updateBookmark(bookmark.id, {
    ...bookmark,
    title: title || domain,
    description,
    image: images[0]
  })
  
  if (!response.success) {
    return showErrorToast(response.data, { id: toastId })
  }
  
  showSuccessToast("Bookmark refreshed successfully!", { id: toastId })
}

Implementation Details

The function:
  1. Sends a POST request to a Supabase Edge Function endpoint
  2. Includes authorization headers with an anonymous key
  3. Returns null if the request fails or if an error occurs
  4. Does not throw exceptions - errors are handled gracefully

Source Location

~/workspace/source/src/utils/getMetadata.ts:4

Build docs developers (and LLMs) love