chore: replaced anon with feed title
16c1c7a2
1 file(s) · +14 −7
| 20 | 20 | .map(|url| parse_url(url, None, None, None)) |
|
| 21 | 21 | .collect::<Result<_, _>>()?; |
|
| 22 | 22 | ||
| 23 | - | let mut entries: Vec<&Entry> = feeds.iter().flat_map(|f| f.entries.iter()).collect(); |
|
| 23 | + | let mut entries: Vec<(&Entry, Option<&str>)> = feeds |
|
| 24 | + | .iter() |
|
| 25 | + | .flat_map(|f| { |
|
| 26 | + | let title = f.feed.title.as_deref(); |
|
| 27 | + | f.entries.iter().map(move |e| (e, title)) |
|
| 28 | + | }) |
|
| 29 | + | .collect(); |
|
| 24 | 30 | entries.sort_by(|a, b| { |
|
| 25 | - | let da = a.published.as_ref().map(|d| d.to_string()); |
|
| 26 | - | let db = b.published.as_ref().map(|d| d.to_string()); |
|
| 31 | + | let da = a.0.published.as_ref().map(|d| d.to_string()); |
|
| 32 | + | let db = b.0.published.as_ref().map(|d| d.to_string()); |
|
| 27 | 33 | db.cmp(&da) |
|
| 28 | 34 | }); |
|
| 29 | 35 | ||
| 31 | 37 | Ok(()) |
|
| 32 | 38 | } |
|
| 33 | 39 | ||
| 34 | - | fn app(terminal: &mut DefaultTerminal, entries: &[&Entry]) -> std::io::Result<()> { |
|
| 40 | + | fn app(terminal: &mut DefaultTerminal, entries: &[(&Entry, Option<&str>)]) -> std::io::Result<()> { |
|
| 35 | 41 | let mut state = ListState::default(); |
|
| 36 | 42 | state.select(Some(0)); |
|
| 37 | 43 | ||
| 52 | 58 | } |
|
| 53 | 59 | KeyCode::Enter => { |
|
| 54 | 60 | if let Some(i) = state.selected() { |
|
| 55 | - | if let Some(url) = entries[i].links.first().map(|l| l.href.as_str()) { |
|
| 61 | + | if let Some(url) = entries[i].0.links.first().map(|l| l.href.as_str()) { |
|
| 56 | 62 | let _ = open::that(url); |
|
| 57 | 63 | } |
|
| 58 | 64 | } |
|
| 79 | 85 | format!("{} {}{}, {}", dt.format("%B"), day, suffix, dt.format("%Y")) |
|
| 80 | 86 | } |
|
| 81 | 87 | ||
| 82 | - | fn render(frame: &mut Frame, entries: &[&Entry], state: &mut ListState) { |
|
| 88 | + | fn render(frame: &mut Frame, entries: &[(&Entry, Option<&str>)], state: &mut ListState) { |
|
| 83 | 89 | let dim = Style::new().fg(Color::DarkGray); |
|
| 84 | 90 | let author_style = Style::new() |
|
| 85 | 91 | .fg(Color::DarkGray) |
|
| 90 | 96 | let items: Vec<ListItem> = entries |
|
| 91 | 97 | .iter() |
|
| 92 | 98 | .enumerate() |
|
| 93 | - | .map(|(i, e)| { |
|
| 99 | + | .map(|(i, (e, feed_title))| { |
|
| 94 | 100 | let bar = if selected == Some(i) { "▌ " } else { " " }; |
|
| 95 | 101 | let date = e |
|
| 96 | 102 | .published |
|
| 102 | 108 | .authors |
|
| 103 | 109 | .first() |
|
| 104 | 110 | .and_then(|a| a.name.as_deref()) |
|
| 111 | + | .or(*feed_title) |
|
| 105 | 112 | .unwrap_or("anon"); |
|
| 106 | 113 | ListItem::new(Text::from(vec![ |
|
| 107 | 114 | Line::from(vec![Span::raw(bar), Span::styled(date, dim)]), |
|