-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interactive --series flag to cli
- Loading branch information
1 parent
0c55ccf
commit 79ce6bd
Showing
3 changed files
with
77 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashSet; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
/// Gets all existing series from the _posts directory based on their frontmatter | ||
// TODO: Make this work for drafts as well | ||
// NOTE: Drafts may want to be part of a published series in _posts, so this requires some thought | ||
pub(crate) fn get_existing_series() -> HashSet<String> { | ||
let mut series_keys = HashSet::new(); | ||
let posts_dir = Path::new("_posts"); | ||
|
||
if let Ok(entries) = fs::read_dir(posts_dir) { | ||
for entry in entries.flatten() { | ||
if let Ok(content) = fs::read_to_string(entry.path()) { | ||
if let Some(start) = content.find("series_key:") { | ||
if let Some(end) = content[start..].find('\n') { | ||
let series_key = content[start + 11..start + end].trim().trim_matches('"'); | ||
series_keys.insert(series_key.to_string()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
series_keys | ||
} |