working truncation
This commit is contained in:
parent
93d22bfe3f
commit
0012478dfb
11 changed files with 171 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/target
|
||||
blogdor.db
|
||||
*.db
|
||||
secrets
|
||||
.env
|
||||
.#*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "insert into runs (feed, fetched, posted) values (?, ?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "09ec0320ccf5156d109f328f5aee1b38376496762b910e1b0637a84550e71c25"
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "select url, active from feeds left join (select active, feed, max(id) from status group by feed) s on s.feed = feeds.id where feeds.owner = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "url",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "active",
|
||||
"ordinal": 1,
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "0e3ab12f01a4bb5650bafe964a4578cfe3839040e801d305e990a862580d7a09"
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "insert into status (feed, active) values (?, true)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "2acd17df4d97ab738112dfc698fa817269a2e593afcadeb90c21b9499c4c32ce"
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "select id from feeds where url = ? and owner = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Integer"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "2d37d674e60702e925683c98751be89282f5abe93080ccd2fce85f932c6cdc39"
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "insert into feeds (url, owner) values (?, ?) returning id",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Integer"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "5dab8e2e0eb9cff50671713adb2b596193e20d0017101603f6bb4a6731e4dc2d"
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "insert into status (feed, active) values (?, false)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "64785d20fde925362b4eb9fcf0b8cf2436d679ed84f6b912cc563f753c19d92f"
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "select id from feeds where owner = ? and url = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Integer"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "8ae828d3409fc5bf26d592505438d1fdb8aded5f304e203f80013c9bdae2c330"
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "insert into users (zulip_id) values (?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "90c3678442a477d5315fcc66b604a0a071a99d62e33cdac4fdc9b0f65243ab33"
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "select max(posted) posted from runs where feed = ? limit 1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "posted",
|
||||
"ordinal": 0,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "e717efe17105e6a2983dd360cd8f742a098913feb7c07bdd80da0d268998219d"
|
||||
}
|
||||
35
src/lib.rs
35
src/lib.rs
|
|
@ -79,10 +79,11 @@ pub enum Action {
|
|||
List,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
enum PostBody {
|
||||
Full(String),
|
||||
Truncated(String),
|
||||
#[default]
|
||||
Empty,
|
||||
}
|
||||
|
||||
|
|
@ -438,13 +439,7 @@ impl BlogdorTheAggregator {
|
|||
|
||||
for post in entries.iter() {
|
||||
let owner = post.owner;
|
||||
let body = post.body.as_deref().unwrap_or("");
|
||||
|
||||
let tail = if body.len() <= ZULIP_MESSAGE_CUTOFF {
|
||||
""
|
||||
} else {
|
||||
"..."
|
||||
};
|
||||
let body = &post.body;
|
||||
|
||||
let url = post.post_url.as_str();
|
||||
let title = post.title.as_str();
|
||||
|
|
@ -452,7 +447,7 @@ impl BlogdorTheAggregator {
|
|||
let header = format!("New post in a feed added by @**|{owner}**: {title}");
|
||||
|
||||
let content = format!(
|
||||
"{header}\n---\n{body}{tail}\n\n---\noriginally posted to {url}, on {}",
|
||||
"{header}\n```quote\n{body}\n```\n---\noriginally posted to {url}, on {}",
|
||||
post.published.format("%B %e, %Y"),
|
||||
);
|
||||
|
||||
|
|
@ -593,21 +588,23 @@ async fn check_feed(
|
|||
for post in feed.entries.into_iter().take(5) {
|
||||
let body = post
|
||||
.content
|
||||
.and_then(|c| match c.body {
|
||||
.as_ref()
|
||||
.map(|c| match c.body {
|
||||
None => PostBody::Empty,
|
||||
Some(c) => {
|
||||
let s = html2md::parse_html_custom(&c, &handlers)
|
||||
.graphemes(false)
|
||||
.take(ZULIP_MESSAGE_CUTOFF)
|
||||
.collect::<String>();
|
||||
if s.len() == c.len() {
|
||||
PostBody::Full(s)
|
||||
Some(ref c) => {
|
||||
let full = html2md::parse_html_custom(c, &handlers);
|
||||
if full.len() <= ZULIP_MESSAGE_CUTOFF {
|
||||
PostBody::Full(full)
|
||||
} else {
|
||||
PostBody::Truncated(s)
|
||||
let trunc = full
|
||||
.graphemes(false)
|
||||
.take(ZULIP_MESSAGE_CUTOFF)
|
||||
.collect::<String>();
|
||||
PostBody::Truncated(trunc)
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap_or(PostBody::Empty);
|
||||
.unwrap_or_default();
|
||||
|
||||
if post.posted().unwrap_or(LAST_FETCHED) > last_fetched {
|
||||
let entry = FeedEntry {
|
||||
|
|
|
|||
Loading…
Reference in a new issue