|
|
|
@ -12,6 +12,7 @@ use std::{
|
|
|
|
|
io::Read,
|
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
};
|
|
|
|
|
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
|
|
|
|
|
|
|
|
|
|
const IMAGE_EXTS: [&str; 5] = ["png", "jpeg", "jpg", "webp", "gif"];
|
|
|
|
|
|
|
|
|
@ -78,6 +79,25 @@ impl Input {
|
|
|
|
|
self.data_urls.clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn summary(&self) -> String {
|
|
|
|
|
let text = &self.text;
|
|
|
|
|
if text.width_cjk() > 70 {
|
|
|
|
|
let mut sum_width = 0;
|
|
|
|
|
let mut chars = vec![];
|
|
|
|
|
for c in text.chars() {
|
|
|
|
|
sum_width += c.width_cjk().unwrap_or(1);
|
|
|
|
|
if sum_width > 67 {
|
|
|
|
|
chars.extend(['.', '.', '.']);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
chars.push(c);
|
|
|
|
|
}
|
|
|
|
|
chars.into_iter().collect()
|
|
|
|
|
} else {
|
|
|
|
|
text.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn render(&self) -> String {
|
|
|
|
|
if self.medias.is_empty() {
|
|
|
|
|
return self.text.clone();
|
|
|
|
|