-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d4a41d
commit a06428f
Showing
5 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ extern crate log; | |
mod bot; | ||
mod config; | ||
mod error; | ||
mod render; | ||
mod store; | ||
mod utils; | ||
|
||
|
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,49 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Read; | ||
|
||
use crate::store::News; | ||
|
||
pub fn render(news: Vec<News>, editor: String) -> String { | ||
let path = match env::var("TEMPLATE_PATH") { | ||
Ok(val) => val, | ||
Err(_) => "./template.md".to_string(), | ||
}; | ||
|
||
let mut file = File::open(path).expect("Unable to open template file"); | ||
let mut template = String::new(); | ||
file.read_to_string(&mut template) | ||
.expect("Unable to read template file"); | ||
|
||
let mut report = String::new(); | ||
for n in news { | ||
// skip not approved news | ||
if !n.approved { | ||
continue; | ||
} | ||
|
||
let section = "Section header (not implemented yet)"; | ||
let user = format!( | ||
"[{}](https://matrix.to/#/{})", | ||
n.reporter_display_name, n.reporter_id | ||
); | ||
|
||
let section = format!( | ||
"# {}\n\ | ||
{} reports that\n\ | ||
> {}\n\n", | ||
section, user, n.message | ||
); | ||
|
||
report = (report + §ion).to_string(); | ||
} | ||
|
||
let now: chrono::DateTime<chrono::Utc> = chrono::Utc::now(); | ||
let today = now.format("%Y-%m-%d"); | ||
|
||
template = template.replace("{{today}}", &today.to_string()); | ||
template = template.replace("{{author}}", &editor); | ||
template = template.replace("{{report}}", &report); | ||
|
||
template | ||
} |