Note
This repository was branched out of storiny/web which was originally a monolith. If you're looking for the original git history before the split, you can find it over on the original repository.
A fast, lightweight microservice responsible for dynamically generating open graph images for Storiny stories and tags on-the-fly.
| Story | Tag |
|---|---|
- Framework: Actix Web serves our HTTP endpoints
- RPC: Tonic (gRPC) is used to fetch live story and tag metadata directly from the
storiny/apiservice - Templating: Sailfish provides fast HTML/SVG macro-based templating
- Rasterization: resvg and tiny-skia parse and render the SVG into a PNG
- Caching: Redis handles rate limiting
- gRPC data fetching: When a request arrives for a story or tag, the service dispatches a gRPC request to the API microservice
- Dynamic text: Text wrapping and truncation are calculated dynamically using
textwrapand custom font metric utils to ensures titles and descriptions fit perfectly within the card bounds without bleeding over - SVG templating: The resolved metadata (cover image, author avatar, title...) is injected into an SVG template using Sailfish
- Rasterization: Finally,
resvgparses the populated SVG and rasterizes it into a PNG. This raster image is returned to the client with suitable caching with the help of Cloudflare.
GET /stories/{id}: Fetches story metadata via gRPC, renders the story template, and returns a dynamic PNG opengraph imageGET /tags/{id}: Fetches tag metadata via gRPC, renders the tag template, and returns a dynamic PNG opengraph imageGET /health: Health check endpoint. ReturnsOK.
Make sure you have Rust installed. You will also need the main storiny-api running locally for the gRPC calls to succeed.
# clone
git clone https://github.com/storiny/og.git
cd og
# install deps and run the service
cargo run