MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_frontmatter_field

Function write_frontmatter_field

atomic-repository/src/repository/vault.rs:732–774  ·  view source on GitHub ↗

Write a single frontmatter field in YAML format.

(output: &mut String, key: &str, value: &serde_json::Value)

Source from the content-addressed store, hash-verified

730
731/// Write a single frontmatter field in YAML format.
732fn write_frontmatter_field(output: &mut String, key: &str, value: &serde_json::Value) {
733 use std::fmt::Write;
734 match value {
735 serde_json::Value::String(s) => {
736 // Use bare value for simple strings, quoted for strings with special chars.
737 // Note: bare colons are fine in YAML values (e.g. timestamps "12:00:00");
738 // only ": " (colon-space) is ambiguous as a nested key-value separator.
739 if s.contains(": ")
740 || s.contains('#')
741 || s.contains('\n')
742 || s.starts_with('{')
743 || s.starts_with('[')
744 {
745 let _ = writeln!(output, "{}: \"{}\"", key, s.replace('\"', "\\\""));
746 } else {
747 let _ = writeln!(output, "{}: {}", key, s);
748 }
749 }
750 serde_json::Value::Number(n) => {
751 let _ = writeln!(output, "{}: {}", key, n);
752 }
753 serde_json::Value::Bool(b) => {
754 let _ = writeln!(output, "{}: {}", key, b);
755 }
756 serde_json::Value::Array(arr) => {
757 let items: Vec<String> = arr
758 .iter()
759 .map(|v| match v {
760 serde_json::Value::String(s) => s.clone(),
761 other => other.to_string(),
762 })
763 .collect();
764 let _ = writeln!(output, "{}: [{}]", key, items.join(", "));
765 }
766 serde_json::Value::Object(_) => {
767 // Inline JSON for nested objects
768 let _ = writeln!(output, "{}: {}", key, value);
769 }
770 serde_json::Value::Null => {
771 let _ = writeln!(output, "{}: null", key);
772 }
773 }
774}
775
776// ── Deflation helpers ───────────────────────────────────────────────────
777

Callers 1

render_entry_to_markdownFunction · 0.85

Calls 3

containsMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected