Skip to content

Commit

Permalink
feat: next-file & prev-file headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Teajey committed Feb 6, 2024
1 parent 1141288 commit 6e38104
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 167 deletions.
10 changes: 5 additions & 5 deletions src/frontmatter_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub use keeper::Keeper;

#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct FrontmatterFile {
name: String,
frontmatter: Option<serde_yaml::Mapping>,
body: String,
modified: DateTime<Utc>,
created: DateTime<Utc>,
pub name: String,
pub frontmatter: Option<serde_yaml::Mapping>,
pub body: String,
pub modified: DateTime<Utc>,
pub created: DateTime<Utc>,
}

impl PartialOrd for FrontmatterFile {
Expand Down
2 changes: 1 addition & 1 deletion src/frontmatter_file/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<notify::EventKind> for FsEvent {
}

pub struct Keeper {
inner: HashMap<Utf8PathBuf, FrontmatterFile>,
pub inner: HashMap<Utf8PathBuf, FrontmatterFile>,
}

#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion src/frontmatter_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl QueryValue {
}

#[derive(Deserialize, Debug)]
pub struct FrontmatterQuery(HashMap<String, QueryValue>);
pub struct FrontmatterQuery(pub HashMap<String, QueryValue>);

impl FrontmatterQuery {
pub fn is_subset(&self, json_frontmatter: &serde_json::Map<String, serde_json::Value>) -> bool {
Expand Down
18 changes: 1 addition & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@ use axum::{
routing, Json, Router,
};
use camino::Utf8PathBuf;
use chrono::{DateTime, TimeZone};
use notify::{RecursiveMode, Watcher};
use serde_yaml::Mapping;

fn get_sort_value<Tz: TimeZone>(
mapping: Option<&Mapping>,
sort_key: &str,
created: &DateTime<Tz>,
) -> String {
mapping
.and_then(|m| m.get(sort_key))
.map(serde_yaml::to_string)
.transpose()
.ok()
.flatten()
.unwrap_or_else(|| serde_yaml::to_string(created).expect("DateTime<Utc> must serialize"))
}

async fn frontmatter_collate_strings_get(
State(markdown_files): State<frontmatter_file::keeper::ArcMutex>,
Expand Down Expand Up @@ -86,7 +70,7 @@ async fn run() -> Result<()> {
)
.route(
"/frontmatter/file/:name",
routing::get(route::frontmatter_file::get).post(route::frontmatter_file::post),
routing::post(route::frontmatter_file::post).get(route::frontmatter_file::get),
)
.route(
"/frontmatter/collate_strings/:key",
Expand Down
Loading

0 comments on commit 6e38104

Please sign in to comment.