module
wordpress
Headless WordPress through the REST API (/wp-json/wp/v2): posts, pages, categories, tags and media. Content arrives as Markdown, ready for markdown(source: post.body).
let wp = WordPress::new("https://example.com");
let req = wp.posts(&Posts::new().per_page(6).category(12));
let res = weft::web::fetch(req).await?;
let posts = wordpress::parse_posts(&res)?; // list of records
let pages = wordpress::total_pages(&res).unwrap_or(1);Structs
Functions
format_date
pub fn format_date(iso: &str, fmt: &str) -> StringA post's date (2018-01-09T15:24:56) the way WordPress formats it, from a PHP date format: F j, Y → January 9, 2018. Supports d j S F M m n Y y and \-escaped literals; anything else is copied.
localize
pub fn localize(v: &Value, site: &str) -> Valuev with links to the WordPress site itself made relative (https://example.com/about/ → /about/), so a frontend on another host keeps its visitors. Media, the API and admin (/wp-content/, /wp-json, /wp-admin, /wp-includes/) stay on the site.
parse_posts
pub fn parse_posts(res: &Response) -> Result<Value, Error>Posts or pages as records: id, slug, date, modified, link, title, excerpt (text), body (Markdown), html, author, image / image_alt (featured media), categories and tags (lists of names), and category_links / tag_links ({label, slug, href} records).
parse_terms
pub fn parse_terms(res: &Response) -> Result<Value, Error>Categories or tags as {id, name, slug, count, href} records.