pub struct Context {
pub destination: PathBuf,
pub frontmatter: Frontmatter,
/* private fields */
}
Expand description
Context holds metadata about a note which is being parsed.
This is used internally to keep track of nesting and help with constructing proper references to other notes.
It is also passed to postprocessors to provide contextual information and allow modification of a note’s frontmatter.
Fields§
§destination: PathBuf
The path where this note will be written to when exported.
Changing this path will result in the note being written to that new path instead, but beware: links will not be updated automatically. If this is changed by a postprocessor, it’s up to that postprocessor to rewrite any existing links to this new path.
frontmatter: Frontmatter
The Frontmatter for this note. Frontmatter may be modified in-place (see
serde_yaml::Mapping
for available methods) or replaced entirely.
§Example
Insert foo: bar
into a note’s frontmatter:
use obsidian_export::serde_yaml::Value;
let key = Value::String("foo".to_string());
context
.frontmatter
.insert(key.clone(), Value::String("bar".to_string()));
Implementations§
Source§impl Context
impl Context
Sourcepub fn from_parent(context: &Self, child: &Path) -> Self
pub fn from_parent(context: &Self, child: &Path) -> Self
Create a new Context
which inherits from a parent Context.
Sourcepub fn current_file(&self) -> &PathBuf
pub fn current_file(&self) -> &PathBuf
Return the path of the file currently being parsed.
Sourcepub fn root_file(&self) -> &PathBuf
pub fn root_file(&self) -> &PathBuf
Return the path of the root file.
Typically this will yield the same element as current_file
, but when a note is embedded
within another note, this will return the outer-most note.
Sourcepub fn note_depth(&self) -> usize
pub fn note_depth(&self) -> usize
Return the note depth (nesting level) for this context.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more