title: Diaryx Core Library
author: adammharris
audience:
- public
part_of: ../../README.md
Diaryx Core Library
This is the diaryx_core library! It contains shared code for the Diaryx clients.
NOTE: this README is not finished yet!
Quick overview
diaryx_core
└── src
Note: writing after this point may be outdated.
Provided functionality
Managing frontmatter
Full key-value operations for managing frontmatter properties:
set_frontmatter_propertyget_frontmatter_propertyrename_frontmatter_propertyremove_frontmatter_propertyget_all_frontmatter
Also, sorting frontmatter properties:
sort_frontmattersort_alphabeticallysort_by_pattern
Managing file content
Operations for managing content of markdown files separate from frontmatter:
set_contentget_contentappend_contentclear_content
Search
Search frontmatter or content separately:
SearchQuery::contentSearchQuery::frontmatter
Export
use ;
use RealFileSystem;
use Path;
let workspace_root = new;
let audience = "public";
let destination = new;
let fs = RealFileSystem;
let exporter = new;
let plan = match exporter.plan_export ;
let force = false;
let keep_audience = false;
let options = ExportOptions ;
match exporter.execute_export
Validation
The validate module provides functionality to check workspace link integrity and automatically fix issues.
Validator
The Validator struct checks part_of and contents references within a workspace:
use Validator;
use RealFileSystem;
use Path;
let validator = new;
// Validate entire workspace starting from root index
let root_path = new;
let result = validator.validate_workspace.unwrap;
// Or validate a single file
let file_path = new;
let result = validator.validate_file.unwrap;
if result.is_ok else
Validation Errors
BrokenPartOf- A file'spart_ofpoints to a non-existent fileBrokenContentsRef- An index'scontentsreferences a non-existent fileBrokenAttachment- A file'sattachmentsreferences a non-existent file
Validation Warnings
OrphanFile- A markdown file not referenced by any indexUnlinkedEntry- A file/directory not in the contents hierarchyUnlistedFile- A markdown file in a directory but not in the index's contentsCircularReference- Circular reference detected in workspace hierarchyNonPortablePath- A path contains absolute paths or./..componentsMultipleIndexes- Multiple index files in the same directoryOrphanBinaryFile- A binary file not referenced by any attachmentsMissingPartOf- A non-index file has nopart_ofproperty
ValidationFixer
The ValidationFixer struct provides methods to automatically fix validation issues:
use ;
use RealFileSystem;
use Path;
let validator = new;
let fixer = new;
// Validate workspace
let root_path = new;
let result = validator.validate_workspace.unwrap;
// Fix all issues at once
let = fixer.fix_all;
for fix in error_fixes.iter.chain
// Or fix individual issues
fixer.fix_broken_part_of;
fixer.fix_broken_contents_ref;
fixer.fix_unlisted_file;
fixer.fix_missing_part_of;