|
1 | 1 | use crate::api::post::get_comment_list::PostCommentEntry;
|
2 | 2 | use crate::api::post::get_one::PostEntry;
|
| 3 | +use crate::api::post::search_site::SearchResultEntry; |
3 | 4 | use crate::args::TimeStyle;
|
4 | 5 | use crate::display::colorful::fmt_err;
|
5 | 6 | use crate::infra::result::WrapResult;
|
@@ -136,3 +137,34 @@ pub fn search_self_post(
|
136 | 137 | },
|
137 | 138 | )
|
138 | 139 | }
|
| 140 | + |
| 141 | +pub fn search_site_post( |
| 142 | + time_style: &TimeStyle, |
| 143 | + entry_iter: Result<impl ExactSizeIterator<Item = SearchResultEntry>>, |
| 144 | +) -> Result<String> { |
| 145 | + let entry_iter = match entry_iter { |
| 146 | + Ok(o) => o, |
| 147 | + Err(e) => return fmt_err(&e).wrap_ok(), |
| 148 | + }; |
| 149 | + |
| 150 | + entry_iter |
| 151 | + .map(|entry| try { |
| 152 | + let mut buf = String::new(); |
| 153 | + { |
| 154 | + let buf = &mut buf; |
| 155 | + let create_time = display_cnb_time(&entry.create_time, time_style); |
| 156 | + writeln!(buf, "{} {}", create_time.dimmed(), entry.url.dimmed())?; |
| 157 | + writeln!(buf, " {}", entry.title)?; |
| 158 | + let view_vote_comment_count = format!( |
| 159 | + "View {} Vote {} Comment {}", |
| 160 | + entry.view_count, entry.vote_count, entry.comment_count |
| 161 | + ); |
| 162 | + writeln!(buf, " {}", view_vote_comment_count.dimmed())?; |
| 163 | + } |
| 164 | + buf |
| 165 | + }) |
| 166 | + .try_fold(String::new(), |mut acc, buf: Result<String>| try { |
| 167 | + writeln!(&mut acc, "{}", buf?)?; |
| 168 | + acc |
| 169 | + }) |
| 170 | +} |
0 commit comments