Skip to content

module

contentful

Contentful: entries from the Content Delivery (or Preview) API, with linked entries and assets resolved and rich text turned into Markdown.

let cms = Contentful::new(env!("CONTENTFUL_SPACE_ID"), env!("CONTENTFUL_ACCESS_TOKEN"));
let req = cms.entries(&Entries::of("blogPost").order("-fields.publishDate").limit(10));
let posts = contentful::parse_entries(&weft::web::fetch(req).await?)?; // a list of records

Structs

  • Contentful

    A Contentful space, read through its Content Delivery API (or the Preview API).

  • Entries

    Query parameters for entries.

Functions

parse_entries

pub fn parse_entries(res: &Response) -> Result<Value, Error>

Parse an entries (or assets) response into a list of flat records: id, content_type, created_at, updated_at plus every field, with links resolved, assets as {id, title, description, url, content_type, width, height} and rich text as Markdown.

rich_text_to_markdown

pub fn rich_text_to_markdown(doc: &Value) -> String

Contentful rich text (a document node) → Markdown.

total

pub fn total(res: &Response) -> Option<usize>

The total number of matches in an entries response.