aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2021-07-07 21:17:01 -0400
committerChristine Dodrill <me@christine.website>2021-07-07 21:17:46 -0400
commit7dfdd131e4346bdfda6a709e9de0c1e543d8554e (patch)
treee7c216b2e77d007691f9a6126ed95867334b83f2
parent0019b0a4e9d48e4c8f660fc25a94af0deacf99e3 (diff)
downloadxesite-7dfdd131e4346bdfda6a709e9de0c1e543d8554e.tar.xz
xesite-7dfdd131e4346bdfda6a709e9de0c1e543d8554e.zip
closer integration into android, read estimates
Signed-off-by: Christine Dodrill <me@christine.website>
-rw-r--r--Cargo.lock9
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs4
-rw-r--r--src/post/mod.rs39
-rw-r--r--static/assetlinks.json9
5 files changed, 33 insertions, 29 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 02bb7c8..266d626 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "abnf"
version = "0.6.1"
@@ -474,6 +476,12 @@ dependencies = [
]
[[package]]
+name = "estimated_read_time"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "649cfd341410b1f8906e8ca1b39e5534be9312fda9182edd770cec34dfbce8d7"
+
+[[package]]
name = "eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2593,6 +2601,7 @@ dependencies = [
"color-eyre",
"comrak",
"envy",
+ "estimated_read_time",
"eyre",
"futures",
"glob",
diff --git a/Cargo.toml b/Cargo.toml
index 4839729..45cc8a3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,7 @@ color-eyre = "0.5"
chrono = "0.4"
comrak = "0.10"
envy = "0.4"
+estimated_read_time = "1"
futures = "0.3"
glob = "0.3"
hyper = "0.14"
diff --git a/src/main.rs b/src/main.rs
index 0576f97..bbe5658 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -142,6 +142,8 @@ async fn main() -> Result<()> {
let sitemap = warp::path("sitemap.xml")
.and(with_state(state.clone()))
.and_then(handlers::feeds::sitemap);
+ let asset_links = warp::path!(".well-known" / "assetlinks.json")
+ .and(warp::fs::file("./static/assetlinks.json"));
let go_vanity_jsonfeed = warp::path("jsonfeed")
.and(warp::any().map(move || "christine.website/jsonfeed"))
@@ -162,7 +164,7 @@ async fn main() -> Result<()> {
});
let static_pages = index
- .or(feeds)
+ .or(feeds.or(asset_links))
.or(resume.or(signalboost))
.or(patrons)
.or(jsonfeed.or(atom.or(sitemap)).or(rss))
diff --git a/src/post/mod.rs b/src/post/mod.rs
index 4c54404..acdd325 100644
--- a/src/post/mod.rs
+++ b/src/post/mod.rs
@@ -15,6 +15,7 @@ pub struct Post {
pub date: DateTime<FixedOffset>,
pub mentions: Vec<mi::WebMention>,
pub new_post: NewPost,
+ pub read_time_estimate_minutes: u64,
}
/// Used with the Android app to show information in a widget.
@@ -80,33 +81,6 @@ impl Post {
}
}
-fn trim(string: &str) -> String {
- let mut buf = String::new();
- let mut capturing = false;
-
- for line in string.lines() {
- if line.starts_with("#") {
- continue;
- }
-
- if line == "" {
- if capturing && buf.len() > 260 {
- break;
- } else {
- capturing = true;
- continue;
- }
- }
-
- if capturing {
- buf.push_str(" ");
- buf.push_str(line);
- }
- }
-
- buf
-}
-
async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
let body = fs::read_to_string(fname.clone())
.await
@@ -133,9 +107,17 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
Err(_) => vec![],
};
+ let time_taken = estimated_read_time::text(
+ &body,
+ &estimated_read_time::Options::new()
+ .build()
+ .unwrap_or_default(),
+ );
+ let read_time_estimate_minutes = time_taken.seconds() / 60;
+
let new_post = NewPost {
title: front_matter.title.clone(),
- summary: trim(body).to_string(),
+ summary: format!("{} minute read", read_time_estimate_minutes),
link: format!("https://christine.website/{}", link),
};
@@ -146,6 +128,7 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
date,
mentions,
new_post,
+ read_time_estimate_minutes,
})
}
diff --git a/static/assetlinks.json b/static/assetlinks.json
new file mode 100644
index 0000000..12e1053
--- /dev/null
+++ b/static/assetlinks.json
@@ -0,0 +1,9 @@
+[{
+ "relation": ["delegate_permission/common.handle_all_urls"],
+ "target": {
+ "namespace": "android_app",
+ "package_name": "website.christine.xesite",
+ "sha256_cert_fingerprints":
+ ["C9:5B:9C:65:85:FF:D5:6F:6C:12:46:61:1D:1F:2E:A3:C7:E1:7E:8F:B0:F1:F6:7C:EF:24:DE:54:2E:94:24:0C"]
+ }
+}] \ No newline at end of file