script_meditate/json.rs
1#[allow(clippy::module_name_repetitions)]
2#[doc(hidden)]
3pub use serde_json;
4
5/// Extracts, parses, and returns the JSON frontmatter.
6///
7/// # Panics
8///
9/// Panics if the frontmatter cannot be found or if its contents cannot be parsed.
10#[macro_export]
11macro_rules! extract_json_frontmatter {
12 () => {{
13 // Works only if this script is not directly in the user's directory
14 let source = include_str!(file!());
15 let frontmatter = $crate::extract_frontmatter(source, "json")
16 .expect("script file should contain a JSON frontmatter");
17 $crate::serde_json::from_str(frontmatter).expect("could not parse the data")
18 }};
19}