Improve Recraft and ImageKit API scripts
Summary
From
ai-labs
submodule, refined the Recraft image generation and ImageKit upload script to generate, download, upload, store, and reference in a user-specified directory. Recraft URLs, migrated essay image frontmatter fields to ImageKit URLs, and added required dependencies to both Python and Node environments.Why Care
This change ensures accessible, creative, on-brand, and appropriate images are always present. Once we fully run the scripts, it ensures permanent, accessible images for all content items. The script improvements guarantee on-brand, high-quality portrait and banner images are generated by Recraft and uploaded to ImageKit, prevents redundant or accidental uploads, and standardizes asset hosting. Explicitly documenting new dependencies ensures reproducibility and clarity for future contributors.
Implementation
Changes Made
- ai-labs/apis/recraft/generate-banner-and-portrait-images-recraft.py
- Now processes both banner and portrait images with appropriate dimensions.
- Added auto-generated tags from the source file.
- Improved commenting, logic, etc.
- ai-labs/apis/imagekit/convertImageToImagkitUrl.cjs
- Now processes only image URLs starting with
https://img.recraft.ai/
. - Added/updated logic, comments, and debug logging for clarity and traceability.
- content/essays/ and content/lost-in-public/prompts (all files)
- Updated
portrait_image
fields from Recraft URLs to new ImageKit URLs.
- ai-labs/package.json
- Added
node-fetch
as a dependency for image downloading.
- ai-labs/python-requirements.txt
- Added
aiohttp
for async HTTP requests in Python scripts.
Technical Details
- Strict URL match (
imgUrl.startsWith('https://img.recraft.ai/')
) now gates image processing in the Node script. - Skips all non-Recraft and already-ImageKit URLs.
OVERWRITE_IMAGEKIT_URL = false
remains to prevent redundant uploads.- Markdown frontmatter is updated in-place after successful upload.
node-fetch
is used for HTTP requests in JS, andaiohttp
for async operations in Python.
Integration Points
- Markdown essays now reference ImageKit URLs, compatible with Astro content collections and CDN delivery.
- No migration steps required for downstream consumers, as URLs are backward compatible.
- No breaking changes; all additions are backward compatible.
Documentation
- See: content/lost-in-public/prompts/workflow/Write-a-Code-Changelog-Entry.md for changelog standards.
- Usage examples for scripts are in their respective headers.
- For image pipeline and CDN integration, see project documentation on content collections and image utilities.