[][src]Function bloguen::ops::machine_output_json

pub fn machine_output_json<W, E, Tz, St, Sc>(
    blog_name: &str,
    language: &LanguageTag,
    additional_data_sets: &[&BTreeMap<String, String>],
    raw_post_name: &str,
    number: usize,
    title: &str,
    author: &str,
    post_date: &DateTime<Tz>,
    tags: &[&[TagName]],
    styles: &[&[St]],
    scripts: &[&[Sc]],
    into: &mut W,
    out_name_err: E
) -> Result<Cow<'static, str>, Error> where
    W: Write,
    E: Into<Cow<'static, str>>,
    Tz: TimeZone,
    St: WrappedElement,
    Sc: WrappedElement

Output a JSON blob of post metadata.

Care should be taken to ensure the arguments to this funxion are as close as possible to the arguments to format_output()

Examples

let global_data = vec![].into_iter().collect();
let local_data =
    vec![("desc".to_string(),
          "Każdy koniec to nowy początek [PL]".to_string())].into_iter().collect();
let mut out = vec![];
let res = machine_output_json(
    "Блогг", &LANGUAGE_EN_GB, &[&global_data, &local_data],
    "003. 2018-02-05 release-front - a generic release front-end, like Patchwork's",
    3, "release-front - a generic release front-end, like Patchwork's", "nabijaczleweli",
    &DateTime::parse_from_rfc3339("2018-09-06T18:32:22+02:00").unwrap(),
    &[&["vodka".parse().unwrap(), "depression".parse().unwrap()][..],
      &["коммунизм".parse().unwrap()][..]],
    &[&[StyleElement::from_link("//nabijaczleweli.xyz/kaschism/assets/column.css")],
      &[StyleElement::from_literal(".indented { text-indent: 1em; }")]],
    &[&[ScriptElement::from_link("/content/assets/syllable.js")],
      &[ScriptElement::from_literal("alert(\"You're the 1`000`000th visitor!\");")]],
    &mut out, "test blog");
assert_eq!(res, Ok("test blog".into()));

let out = str::from_utf8(&out).unwrap();
let (gendate_utc_rfc3339, gendate_utc_rfc2822, gendate_local_rfc3339, gendate_local_rfc2822) =
    /* extracted from output, format p.a. to post_date_* */;
assert_eq!(out, format!(r###"{{
    "number": 3,
    "language": "en-GB",
    "title": "release-front - a generic release front-end, like Patchwork\'s",
    "author": "nabijaczleweli",

    "raw_post_name": "003. 2018-02-05 release-front - a generic release front-end, like Patchwork\'s",
    "blog_name": "Блогг",

    "post_date_rfc3339": "2018-09-06T18:32:22+02:00",
    "post_date_rfc2822": "Thu,  6 Sep 2018 18:32:22 +0200",
    "generation_date_utc_rfc3339": "{}",
    "generation_date_utc_rfc2822": "{}",
    "generation_date_local_rfc3339": "{}",
    "generation_date_local_rfc2822": "{}",

    "tags": [
        "vodka",
        "depression",
        "коммунизм"
    ],
    "additional_data": {{
        "desc": "Każdy koniec to nowy początek [PL]"
    }},

    "styles": [
        "//nabijaczleweli.xyz/kaschism/assets/column.css",
        ".indented {{ text-indent: 1em; }}"
    ],
    "scripts": [
        "/content/assets/syllable.js",
        "alert(\"You\'re the 1`000`000th visitor!\");"
    ],

    "bloguen-version": "0.1.1"
}}"###,
    gendate_utc_rfc3339, gendate_utc_rfc2822, gendate_local_rfc3339, gendate_local_rfc2822));