Blogs
Blog Records in Algolia
Section titled “Blog Records in Algolia”When a Blog is published or updated in Sanity, the system fetches type-specific fields in addition to the general variables. These fields provide the data needed for card display and filtering in the Resource Center.
Source file: algolia/custom_actions/types/getResourcesData.js
Type-Specific Fields
Section titled “Type-Specific Fields”| Field | Source | Description |
|---|---|---|
date | props.draft?.update_date or props.draft?.date | Publish date; prefers update_date if available |
card_image | GROQ query on featured_image | Featured image URL for the Resource Center card |
organizers | GROQ query on people document | Author name and avatar image |
How It Works
Section titled “How It Works”Date Selection
Section titled “Date Selection”The blog date uses the update_date field if available, falling back to the original date:
date = props.draft?.update_date ? props.draft?.update_date : props.draft?.dateCard Image
Section titled “Card Image”The system queries Sanity for the blog’s image assets. It prioritizes the featured_image for the card:
var queryImage = `*[_type == "blogs" && _id == "${id}"][0]{ 'index_image': attributes.asset_type.image.asset->url, 'featured_image': attributes.featured_image.image.asset->url}`
await client.fetch(queryImage).then((imageUrl) => { card_image = imageUrl?.featured_image ? imageUrl?.featured_image : ''})Author (Organizer)
Section titled “Author (Organizer)”The author is fetched from the people document type using the author reference:
var queryAuthor = `*[_type == "people" && _id == "${props.draft?.author?._ref}"][0]{ 'title': title, 'image': asset_type.image.asset->url}`
await client.fetch(queryAuthor).then((author) => { organizers = [{ title: author?.title, image: author?.image }]})The organizers field is an array with a single object containing the author’s title and image.