Freeware
Freeware Records in Algolia
Section titled “Freeware Records in Algolia”When a Freeware item is published or updated in Sanity, the system fetches type-specific fields in addition to the general variables. Freeware is the most complex resource type because it includes form handling and download logic needed to render the download modal 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?.attributes?.date | Publication date |
freeware_form | Hero configuration | Complete form configuration object for the download modal |
Form Configuration
Section titled “Form Configuration”The freeware form data is extracted from the hero section of the Sanity document. The hero determines whether a form or a button is displayed, and what happens after submission.
Form Fields
Section titled “Form Fields”| Field | Description |
|---|---|
form_script | The form embed script from the forms document |
form_ty_message | Thank-you message displayed after form submission |
form_has_download | Whether the form triggers a file download |
form_download_type | Download type (file or external) |
form_modal_download_file | URL of the downloadable file (resolved from asset reference) |
form_file | Raw file reference |
form_external_reference | External URL for non-file downloads |
form_has_redirect | Whether the form redirects after submission |
form_redirect | Redirect configuration (target page slug, option) |
How It Works
Section titled “How It Works”date = props.draft?.attributes?.date;Hero & Form Detection
Section titled “Hero & Form Detection”The system reads the first hero of the document to determine if a form or button is included:
var hero = props?.draft?.heros[0];var include_form = hero?.include_formvar include_button = hero?.include_buttonvar form = include_form ? hero.form_script?._ref : include_button ? hero.hero_button?.modal_form_script?._ref : '';Download File Resolution
Section titled “Download File Resolution”If the download type is file, the system resolves the file asset URL from Sanity:
if (form_download_type == 'file' && form_modal_download_file) { var queryForm = `*[_id == "${form_modal_download_file?.asset?._ref}"][0]` await client.fetch(queryForm).then((form) => { form_modal_download_file = form.url; })}Redirect Page Resolution
Section titled “Redirect Page Resolution”If the form has a redirect to an internal page, the system resolves the page slug:
if (form_has_redirect && form_redirect.option == 'target_self' && form_redirect?.pages) { var queryForm = `*[_id == "${form_redirect.pages?._ref}"][0]{'slug': attributes.slug}`; await client.fetch(queryForm).then((form) => { form_redirect.slug = form.slug; })}Form Script & Thank-You Message
Section titled “Form Script & Thank-You Message”The form embed script and thank-you message are fetched from the forms document type:
var queryForm = `*[_type == "forms" && _id == "${form}"][0]{ 'script': text, 'thank_you_message': thank_you_message}`
await client.fetch(queryForm).then((form) => { form_script = form?.script form_ty_message = form?.thank_you_message})Final Form Object
Section titled “Final Form Object”All form-related fields are grouped into a single freeware_form object:
freeware_form = { form_script, form_ty_message, form_has_download, form_download_type, form_modal_download_file, form_file, form_external_reference, form_has_redirect, form_redirect,}This object is included in the Algolia record so the Resource Center can render the download modal without additional API calls.