Function create_diary_file

Source
pub fn create_diary_file(
    full_diary_file_path: &str,
    commit_saver_struct: &mut CommitSaver,
) -> Result<(), Box<dyn Error>>
Expand description

Creates a new diary file with Obsidian frontmatter and table template.

Generates a diary entry file with:

  • YAML frontmatter containing metadata and tags for Obsidian organization
  • A markdown table header for commit entries (folder, time, message, repo, branch, hash)
  • Pre-formatted for use with CommitSaver::append_entry_to_diary()

§Template Structure

The generated file uses the internal DiaryFileEntry markup template:

---
category: diary
section: commits
tags:
- '#datetime/week/02'
- '#datetime/days/Monday'
- '#diary/commits'
date: 2025-01-14
---

# 2025-01-14

| FOLDER | TIME | COMMIT MESSAGE | REPOSITORY URL | BRANCH | COMMIT HASH |
|--------|------|----------------|----------------|--------|-------------|

§Arguments

… (rest of your existing documentation)

The created file is ready for commit entries to be appended to its table.

§Arguments

  • full_diary_file_path - The complete path where the file should be created
  • commit_saver_struct - The CommitSaver instance to extract metadata from

§Returns

  • Ok(()) - File was successfully created with the template
  • Err(Box<dyn Error>) - File creation or write operation failed

§Errors

Returns an error if:

  • The file cannot be created (parent directory doesn’t exist, permission denied)
  • Write operations fail (disk full, I/O error)
  • Path is invalid or contains invalid UTF-8

§Examples

use rusty_commit_saver::vim_commit::create_diary_file;
use rusty_commit_saver::CommitSaver;
use chrono::{TimeZone, Utc};
use std::fs;

let mut saver = CommitSaver {
    repository_url: "https://github.com/example/repo.git".to_string(),
    commit_branch_name: "main".to_string(),
    commit_hash: "abc123def456".to_string(),
    commit_msg: "feat: implement feature".to_string(),
    commit_datetime: Utc.with_ymd_and_hms(2025, 1, 14, 10, 30, 0).unwrap(),
};

let file_path = "/home/user/diary/2025-01-14.md";
create_diary_file(file_path, &mut saver).unwrap();

// Verify file was created with proper structure
let content = fs::read_to_string(file_path).unwrap();
assert!(content.contains("---")); // Frontmatter markers
assert!(content.contains("category: diary"));
assert!(content.contains("| FOLDER | TIME | COMMIT MESSAGE")); // Table header