Skip to content

Commit 4891920

Browse files
authored
[refactor] description truncate 방법 변경 (#75)
1 parent bf631ba commit 4891920

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/core/rss.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::BTreeMap;
22

33
use rss::{
4-
ChannelBuilder, ItemBuilder,
54
extension::{Extension, ExtensionBuilder},
5+
ChannelBuilder, ItemBuilder,
66
};
77
use time::format_description::well_known::{Rfc2822, Rfc3339};
88

@@ -14,21 +14,13 @@ impl From<SsufidPost> for rss::Item {
1414
fn from(post: SsufidPost) -> Self {
1515
let mut builder = ItemBuilder::default();
1616

17-
let description = {
18-
let truncate_idx = post
19-
.content
20-
.char_indices()
21-
.nth(50)
22-
.map_or(post.content.len(), |(i, _)| i);
23-
if truncate_idx < post.content.len() {
24-
let mut truncated = post.content.clone();
25-
truncated.truncate(truncate_idx);
26-
truncated.push_str("...");
27-
truncated
28-
} else {
29-
post.content.clone()
30-
}
31-
};
17+
let description = post
18+
.content
19+
.char_indices()
20+
.nth(50)
21+
.map_or_else(|| post.content.clone(), |(i, _)| {
22+
format!("{}...", &post.content[..i])
23+
});
3224

3325
builder
3426
.title(post.title)

0 commit comments

Comments
 (0)