Compare commits

..

23 Commits

Author SHA1 Message Date
1cccef12a4 Add settings helper for HLS toggle 2021-11-23 22:43:25 -08:00
8e332b0630 Show full subreddit results in search 2021-11-23 22:24:23 -08:00
85ae7c1f60 Fix indentation and formatting 2021-11-23 22:23:29 -08:00
6d73024183 Remove obselete HTML comment 2021-11-22 18:16:06 -08:00
923ff776bd Fix HLS + autoplay from breaking videos 2021-11-22 18:07:00 -08:00
e181e3f57d Improve Replit deployment method 2021-11-22 13:01:34 -08:00
79bb913fa6 Condense free hosting options into one deployment method 2021-11-22 13:00:39 -08:00
632b64c98b Add Glitch deployment option. Closes 2021-11-22 20:50:12 +00:00
2878d9c799 Shrink and widen comment scores to fit better 2021-11-22 12:19:51 -08:00
9f8d36cb00 Prevent post previews from overflowing on Chromium 2021-11-22 08:40:36 -08:00
25e641e7b3 Don't run GitHub Workflow when README.md changes 2021-11-21 22:46:01 -08:00
4faa9d46d6 Fix HTTPS connector 2021-11-21 22:44:05 -08:00
7220190811 Link subscriptions in settings to their respective feeds 2021-11-21 22:30:44 -08:00
768820cd4c Render markdown correctly in text post previews by using selftext_html. ()
* Render markdown correctly in text post previews by using selftext_html.

I was mistakenly under the impression that we somehow render markdown ourselves, but turns out we just take whatever HTML reddit gives us, and we also need to do this for text previews.

Use CSS to limit the size of the previews instead of truncating in the template.

Fix table CSS.

* Fix post_body padding and trim post_previews

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
2021-11-21 23:17:52 +00:00
2ef7957a66 Create feature parity issue template 2021-11-21 19:48:48 +00:00
7df8e7b4c6 Tweak feature request template 2021-11-21 19:27:33 +00:00
67d3be06e1 Fix Jamie's instance address 2021-11-21 04:17:06 +00:00
6be5eb8991 Update README.md 2021-11-21 04:15:35 +00:00
5d9c320a7e Format post and comment votes with a decimal place, like vanilla reddit does. ()
* Format post and comment votes with a decimal place, like vanilla reddit does.

Before this change, a vote count of 1999 was displayed as 1k, which is a pretty big gap. The displayed count also differed from what Reddit does. Now, the behaviour is consistent.

Added some tests for format_num.

* Provide more space for post scores

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
2021-11-21 04:07:45 +00:00
f7de5285e4 Hide post preview in compact mode. () 2021-11-21 02:05:37 +00:00
c2053524c7 Add text post previews. ()
* Add text post previews.

* Add mask gradient over post preview text

* Increase post title font weight for contrast

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
2021-11-20 21:13:50 +00:00
3a9e6b4ca0 Add mutahar.rocks instance 2021-11-20 17:29:27 +00:00
731a407466 Collapse (sticky) bot comments by default. ()
* Collapse bot comments by default.

Comments are considered bot comments if they are posted by a moderator and are stickied. Some false positives are expected.

* Remove unneeded String conversion

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
2021-11-19 05:42:53 +00:00
21 changed files with 241 additions and 129 deletions

@ -0,0 +1,28 @@
---
name: ✨ Feature parity
about: Suggest implementing a feature into Libreddit that is found in Reddit.com
title: ''
labels: feature parity
assignees: ''
---
## How does this feature work on Reddit?
<!--
A clear and concise description of what the feature is.
-->
## Describe the implementation into Libreddit
<!--
A clear and concise description of what you want to happen.
-->
## Describe alternatives you've considered
<!--
A clear and concise description of any alternative solutions or features you've considered.
-->
## Additional context
<!--
Add any other context or screenshots about the feature parity request here.
-->

@ -1,6 +1,6 @@
--- ---
name: 💡 Feature request name: 💡 Feature request
about: Suggest an idea for this project about: Suggest a feature for Libreddit that is not found in Reddit
title: '' title: ''
labels: enhancement labels: enhancement
assignees: '' assignees: ''

@ -2,9 +2,10 @@ name: Rust
on: on:
push: push:
branches: [master] paths-ignore:
pull_request: - "**.md"
branches: [master] branches:
- master
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always

2
.replit Normal file

@ -0,0 +1,2 @@
run = "while true; do wget -O libreddit https://github.com/spikecodes/libreddit/releases/latest/download/libreddit;chmod +x libreddit;./libreddit -H 63115200;sleep 1;done"
language = "bash"

79
Cargo.lock generated

@ -125,9 +125,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitvec" name = "bitvec"
version = "0.19.5" version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33"
dependencies = [ dependencies = [
"funty", "funty",
"radium", "radium",
@ -236,15 +236,6 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "ct-logs"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8"
dependencies = [
"sct",
]
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.13.0" version = "0.13.0"
@ -496,15 +487,15 @@ checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503"
[[package]] [[package]]
name = "httpdate" name = "httpdate"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.14" version = "0.14.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b" checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -526,19 +517,17 @@ dependencies = [
[[package]] [[package]]
name = "hyper-rustls" name = "hyper-rustls"
version = "0.22.1" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac"
dependencies = [ dependencies = [
"ct-logs", "http",
"futures-util",
"hyper", "hyper",
"log", "log",
"rustls", "rustls",
"rustls-native-certs", "rustls-native-certs",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
"webpki",
] ]
[[package]] [[package]]
@ -613,13 +602,13 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.107" version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]] [[package]]
name = "libreddit" name = "libreddit"
version = "0.17.0" version = "0.19.1"
dependencies = [ dependencies = [
"askama", "askama",
"async-recursion", "async-recursion",
@ -877,11 +866,10 @@ dependencies = [
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.19.1" version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84"
dependencies = [ dependencies = [
"base64",
"log", "log",
"ring", "ring",
"sct", "sct",
@ -890,16 +878,25 @@ dependencies = [
[[package]] [[package]]
name = "rustls-native-certs" name = "rustls-native-certs"
version = "0.5.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" checksum = "5ca9ebdfa27d3fc180e42879037b5338ab1c040c06affd00d8338598e7800943"
dependencies = [ dependencies = [
"openssl-probe", "openssl-probe",
"rustls", "rustls-pemfile",
"schannel", "schannel",
"security-framework", "security-framework",
] ]
[[package]]
name = "rustls-pemfile"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9"
dependencies = [
"base64",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.5"
@ -924,9 +921,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "sct" name = "sct"
version = "0.6.1" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
dependencies = [ dependencies = [
"ring", "ring",
"untrusted", "untrusted",
@ -992,9 +989,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.70" version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e277c495ac6cd1a01a58d0a0c574568b4d1ddf14f59965c6a58b8d96400b54f3" checksum = "063bf466a64011ac24040a49009724ee60a57da1b437617ceb32e53ad61bfb19"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -1195,9 +1192,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.13.0" version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "588b2d10a336da58d877567cd8fb8a14b463e2104910f8132cd054b4b96e29ee" checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes", "bytes",
@ -1215,9 +1212,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "1.5.1" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "114383b041aa6212c579467afa0075fbbdd0718de036100bc0ba7961d8cb9095" checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1226,9 +1223,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.22.0" version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" checksum = "4baa378e417d780beff82bf54ceb0d195193ea6a00c14e22359e7f39456b5689"
dependencies = [ dependencies = [
"rustls", "rustls",
"tokio", "tokio",
@ -1414,9 +1411,9 @@ dependencies = [
[[package]] [[package]]
name = "webpki" name = "webpki"
version = "0.21.4" version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
dependencies = [ dependencies = [
"ring", "ring",
"untrusted", "untrusted",

@ -3,7 +3,7 @@ name = "libreddit"
description = " Alternative private front-end to Reddit" description = " Alternative private front-end to Reddit"
license = "AGPL-3.0" license = "AGPL-3.0"
repository = "https://github.com/spikecodes/libreddit" repository = "https://github.com/spikecodes/libreddit"
version = "0.17.0" version = "0.19.1"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"
@ -16,10 +16,10 @@ regex = "1.5.4"
serde = { version = "1.0.130", features = ["derive"] } serde = { version = "1.0.130", features = ["derive"] }
cookie = "0.15.1" cookie = "0.15.1"
futures-lite = "1.12.0" futures-lite = "1.12.0"
hyper = { version = "0.14.14", features = ["full"] } hyper = { version = "0.14.15", features = ["full"] }
hyper-rustls = "0.22.1" hyper-rustls = "0.23.0"
route-recognizer = "0.3.1" route-recognizer = "0.3.1"
serde_json = "1.0.70" serde_json = "1.0.71"
tokio = { version = "1.13.0", features = ["full"] } tokio = { version = "1.14.0", features = ["full"] }
time = "0.2.7" time = "0.2.7"
url = "2.2.2" url = "2.2.2"

@ -40,7 +40,7 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
| [libreddit.exonip.de](https://libreddit.exonip.de) | 🇩🇪 DE | | | [libreddit.exonip.de](https://libreddit.exonip.de) | 🇩🇪 DE | |
| [libreddit.domain.glass](https://libreddit.domain.glass) | 🇺🇸 US | ✅ | | [libreddit.domain.glass](https://libreddit.domain.glass) | 🇺🇸 US | ✅ |
| [libreddit.sugoma.tk](https://libreddit.sugoma.tk) | 🇺🇸 US | | | [libreddit.sugoma.tk](https://libreddit.sugoma.tk) | 🇺🇸 US | |
| [libreddit.trevorthalacker.com](https://libreddit.trevorthalacker.com) | 🇺🇸 US | ✅ | | [libreddit.jamiethalacker.dev](https://libreddit.jamiethalacker.dev) | 🇺🇸 US | ✅ |
| [reddit.artemislena.eu](https://reddit.artemislena.eu) | 🇩🇪 DE | | | [reddit.artemislena.eu](https://reddit.artemislena.eu) | 🇩🇪 DE | |
| [r.nf](https://r.nf) | 🇩🇪 DE | ✅ | | [r.nf](https://r.nf) | 🇩🇪 DE | ✅ |
| [libreddit.awesomehub.io](https://libreddit.awesomehub.io) | 🇫🇮 FI | | | [libreddit.awesomehub.io](https://libreddit.awesomehub.io) | 🇫🇮 FI | |
@ -55,6 +55,7 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
| [lr.oversold.host](https://lr.oversold.host) | 🇱🇺 LU | | | [lr.oversold.host](https://lr.oversold.host) | 🇱🇺 LU | |
| [libreddit.de](https://libreddit.de) | 🇩🇪 DE | | | [libreddit.de](https://libreddit.de) | 🇩🇪 DE | |
| [libreddit.pussthecat.org](https://libreddit.pussthecat.org) | 🇩🇪 DE | | | [libreddit.pussthecat.org](https://libreddit.pussthecat.org) | 🇩🇪 DE | |
| [libreddit.mutahar.rocks](https://libreddit.mutahar.rocks) | 🇫🇷 FR | |
| [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | | | [spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion](http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion) | 🇮🇳 IN | |
| [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | | | [fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion](http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion) | 🇩🇪 DE | |
| [kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion](http://kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion) | 🇳🇱 NL | | | [kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion](http://kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion) | 🇳🇱 NL | |
@ -194,19 +195,13 @@ yay -S libreddit-git
If you're on Linux and none of these methods work for you, you can grab a Linux binary from [the newest release](https://github.com/spikecodes/libreddit/releases/latest). If you're on Linux and none of these methods work for you, you can grab a Linux binary from [the newest release](https://github.com/spikecodes/libreddit/releases/latest).
## 5) Replit ## 5) Replit/Heroku/Glitch
**Note:** Replit is a free option but they are *not* private and will monitor server usage to prevent abuse. If you need a free and easy setup, this method may work best for you. **Note:** These are free hosting options but they are *not* private and will monitor server usage to prevent abuse. If you need a free and easy setup, this method may work best for you.
1. Create a Replit account (see note above)
2. Visit [the official Repl](https://replit.com/@spikethecoder/libreddit) and fork it
3. Hit the run button to download the latest Libreddit version and start it
In the web preview (defaults to top right), you should see your instance hosted where you can assign a [custom domain](https://docs.replit.com/repls/web-hosting#custom-domains).
## 6) Heroku
<a href="https://repl.it/github/spikecodes/libreddit"><img src="https://repl.it/badge/github/spikecodes/libreddit" alt="Run on Repl.it" height="32" /></a>
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/spikecodes/libreddit) [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/spikecodes/libreddit)
[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button-v2.svg)](https://glitch.com/edit/#!/remix/libreddit)
--- ---

@ -23,7 +23,7 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String
let url = Uri::from_str(url).map_err(|_| "Couldn't parse URL".to_string())?; let url = Uri::from_str(url).map_err(|_| "Couldn't parse URL".to_string())?;
// Prepare the HTTPS connector. // Prepare the HTTPS connector.
let https = hyper_rustls::HttpsConnector::with_native_roots(); let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
// Build the hyper client from the HTTPS connector. // Build the hyper client from the HTTPS connector.
let client: client::Client<_, hyper::Body> = client::Client::builder().build(https); let client: client::Client<_, hyper::Body> = client::Client::builder().build(https);
@ -63,7 +63,7 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String
fn request(url: String, quarantine: bool) -> Boxed<Result<Response<Body>, String>> { fn request(url: String, quarantine: bool) -> Boxed<Result<Response<Body>, String>> {
// Prepare the HTTPS connector. // Prepare the HTTPS connector.
let https = hyper_rustls::HttpsConnector::with_native_roots(); let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().build();
// Construct the hyper client from the HTTPS connector. // Construct the hyper client from the HTTPS connector.
let client: client::Client<_, hyper::Body> = client::Client::builder().build(https); let client: client::Client<_, hyper::Body> = client::Client::builder().build(https);

@ -133,8 +133,7 @@ async fn main() {
.get_matches(); .get_matches();
let address = matches.value_of("address").unwrap_or("0.0.0.0"); let address = matches.value_of("address").unwrap_or("0.0.0.0");
let port = std::env::var("PORT") let port = std::env::var("PORT").unwrap_or_else(|_| matches.value_of("port").unwrap_or("8080").to_string());
.unwrap_or_else(|_| matches.value_of("port").unwrap_or("8080").to_string());
let hsts = matches.value_of("hsts"); let hsts = matches.value_of("hsts");
let listener = [address, ":", &port].concat(); let listener = [address, ":", &port].concat();

@ -184,6 +184,14 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
let id = val(&comment, "id"); let id = val(&comment, "id");
let highlighted = id == highlighted_comment; let highlighted = id == highlighted_comment;
// Many subreddits have a default comment posted about the sub's rules etc.
// Many libreddit users do not wish to see this kind of comment by default.
// Reddit does not tell us which users are "bots", so a good heuristic is to
// collapse stickied moderator comments.
let is_moderator_comment = data["distinguished"].as_str().unwrap_or_default() == "moderator";
let is_stickied = data["stickied"].as_bool().unwrap_or_default();
let collapsed = is_moderator_comment && is_stickied;
Comment { Comment {
id, id,
kind, kind,
@ -216,6 +224,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
edited, edited,
replies, replies,
highlighted, highlighted,
collapsed,
} }
}) })
.collect() .collect()

@ -16,6 +16,7 @@ struct SearchParams {
before: String, before: String,
after: String, after: String,
restrict_sr: String, restrict_sr: String,
typed: String,
} }
// STRUCTS // STRUCTS
@ -55,10 +56,12 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
return Ok(random); return Ok(random);
} }
let typed = param(&path, "type").unwrap_or_default();
let sort = param(&path, "sort").unwrap_or_else(|| "relevance".to_string()); let sort = param(&path, "sort").unwrap_or_else(|| "relevance".to_string());
// If search is not restricted to this subreddit, show other subreddits in search results // If search is not restricted to this subreddit, show other subreddits in search results
let subreddits = param(&path, "restrict_sr").map_or(search_subreddits(&query).await, |_| Vec::new()); let subreddits = param(&path, "restrict_sr").map_or(search_subreddits(&query, &typed).await, |_| Vec::new());
let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str())); let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str()));
@ -74,6 +77,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
before: param(&path, "after").unwrap_or_default(), before: param(&path, "after").unwrap_or_default(),
after, after,
restrict_sr: param(&path, "restrict_sr").unwrap_or_default(), restrict_sr: param(&path, "restrict_sr").unwrap_or_default(),
typed,
}, },
prefs: Preferences::new(req), prefs: Preferences::new(req),
url, url,
@ -89,8 +93,9 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
} }
} }
async fn search_subreddits(q: &str) -> Vec<Subreddit> { async fn search_subreddits(q: &str, typed: &str) -> Vec<Subreddit> {
let subreddit_search_path = format!("/subreddits/search.json?q={}&limit=3", q.replace(' ', "+")); let limit = if typed == "sr_user" { "50" } else { "3" };
let subreddit_search_path = format!("/subreddits/search.json?q={}&limit={}", q.replace(' ', "+"), limit);
// Send a request to the url // Send a request to the url
json(subreddit_search_path, false).await.unwrap_or_default()["data"]["children"] json(subreddit_search_path, false).await.unwrap_or_default()["data"]["children"]
@ -101,9 +106,7 @@ async fn search_subreddits(q: &str) -> Vec<Subreddit> {
.map(|subreddit| { .map(|subreddit| {
// For each subreddit from subreddit list // For each subreddit from subreddit list
// Fetch subreddit icon either from the community_icon or icon_img value // Fetch subreddit icon either from the community_icon or icon_img value
let icon = subreddit["data"]["community_icon"] let icon = subreddit["data"]["community_icon"].as_str().map_or_else(|| val(subreddit, "icon_img"), ToString::to_string);
.as_str()
.map_or_else(|| val(subreddit, "icon_img"), ToString::to_string);
Subreddit { Subreddit {
name: val(subreddit, "display_name_prefixed"), name: val(subreddit, "display_name_prefixed"),

@ -251,11 +251,17 @@ impl Post {
// Determine the type of media along with the media URL // Determine the type of media along with the media URL
let (post_type, media, gallery) = Media::parse(data).await; let (post_type, media, gallery) = Media::parse(data).await;
// selftext_html is set for text posts when browsing.
let mut body = rewrite_urls(&val(post, "selftext_html"));
if body == "" {
body = rewrite_urls(&val(post, "body_html"))
}
posts.push(Self { posts.push(Self {
id: val(post, "id"), id: val(post, "id"),
title: esc!(if title.is_empty() { fallback_title.clone() } else { title }), title: esc!(if title.is_empty() { fallback_title.clone() } else { title }),
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_urls(&val(post, "body_html")), body,
author: Author { author: Author {
name: val(post, "author"), name: val(post, "author"),
flair: Flair { flair: Flair {
@ -334,6 +340,7 @@ pub struct Comment {
pub edited: (String, String), pub edited: (String, String),
pub replies: Vec<Comment>, pub replies: Vec<Comment>,
pub highlighted: bool, pub highlighted: bool,
pub collapsed: bool,
} }
#[derive(Template)] #[derive(Template)]
@ -534,12 +541,14 @@ pub fn rewrite_urls(input_text: &str) -> String {
}) })
} }
// Append `m` and `k` for millions and thousands respectively // Format vote count to a string that will be displayed.
// Append `m` and `k` for millions and thousands respectively, and
// round to the nearest tenth.
pub fn format_num(num: i64) -> (String, String) { pub fn format_num(num: i64) -> (String, String) {
let truncated = if num >= 1_000_000 || num <= -1_000_000 { let truncated = if num >= 1_000_000 || num <= -1_000_000 {
format!("{}m", num / 1_000_000) format!("{:.1}m", num as f64 / 1_000_000.0)
} else if num >= 1000 || num <= -1000 { } else if num >= 1000 || num <= -1000 {
format!("{}k", num / 1_000) format!("{:.1}k", num as f64 / 1_000.0)
} else { } else {
num.to_string() num.to_string()
}; };
@ -618,3 +627,17 @@ pub async fn error(req: Request<Body>, msg: String) -> Result<Response<Body>, St
Ok(Response::builder().status(404).header("content-type", "text/html").body(body.into()).unwrap_or_default()) Ok(Response::builder().status(404).header("content-type", "text/html").body(body.into()).unwrap_or_default())
} }
#[cfg(test)]
mod tests {
use super::format_num;
#[test]
fn format_num_works() {
assert_eq!(format_num(567), ("567".to_string(), "567".to_string()));
assert_eq!(format_num(1234), ("1.2k".to_string(), "1234".to_string()));
assert_eq!(format_num(1999), ("2.0k".to_string(), "1999".to_string()));
assert_eq!(format_num(1001), ("1.0k".to_string(), "1001".to_string()));
assert_eq!(format_num(1_999_999), ("2.0m".to_string(), "1999999".to_string()));
}
}

@ -658,6 +658,13 @@ a.search_subreddit:hover {
opacity: 0.5; opacity: 0.5;
} }
#more_subreddits {
justify-content: center;
color: var(--accent);
font-weight: 600;
text-align: center;
}
/* Post */ /* Post */
.sep { .sep {
@ -697,12 +704,12 @@ a.search_subreddit:hover {
.post_score { .post_score {
padding-top: 16px; padding-top: 16px;
padding-left: 12px;
font-size: 13px; font-size: 13px;
font-weight: bold; font-weight: bold;
text-align: end;
color: var(--accent); color: var(--accent);
grid-area: post_score; grid-area: post_score;
text-align: end; text-align: center;
border-radius: 5px 0 0 5px; border-radius: 5px 0 0 5px;
transition: 0.2s background; transition: 0.2s background;
} }
@ -712,7 +719,7 @@ a.search_subreddit:hover {
} }
.post_header { .post_header {
margin: 15px 20px 5px 15px; margin: 15px 20px 5px 12px;
grid-area: post_header; grid-area: post_header;
} }
@ -722,8 +729,9 @@ a.search_subreddit:hover {
.post_title { .post_title {
font-size: 16px; font-size: 16px;
font-weight: 500;
line-height: 1.5; line-height: 1.5;
margin: 5px 15px; margin: 5px 15px 5px 12px;
grid-area: post_title; grid-area: post_title;
} }
@ -837,11 +845,20 @@ a.search_subreddit:hover {
.post_body { .post_body {
opacity: 0.9; opacity: 0.9;
font-weight: normal; font-weight: normal;
margin: 5px 15px; padding: 5px 15px 5px 12px;
grid-area: post_body; grid-area: post_body;
width: calc(100% - 30px); width: calc(100% - 30px);
} }
/* Used only for text post preview */
.post_preview {
-webkit-mask-image: linear-gradient(180deg,#000 60%,transparent);;
mask-image: linear-gradient(180deg,#000 60%,transparent);
opacity: 0.8;
max-height: 250px;
overflow: hidden;
}
.post_footer { .post_footer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -961,7 +978,8 @@ a.search_subreddit:hover {
min-width: 40px; min-width: 40px;
border-radius: 5px; border-radius: 5px;
padding: 10px 0; padding: 10px 0;
font-size: 16px; font-size: 14px;
font-weight: 600;
} }
.comment_right { .comment_right {
@ -1070,7 +1088,7 @@ summary.comment_data {
} }
.compact .post_header { .compact .post_header {
margin: 15px 15px 2.5px 15px; margin: 15px 15px 2.5px 12px;
font-size: 14px; font-size: 14px;
} }
@ -1078,6 +1096,10 @@ summary.comment_data {
margin: 2.5px 15px; margin: 2.5px 15px;
} }
.compact .post_preview {
display: none;
}
.compact .post_media { .compact .post_media {
max-width: calc(100% - 30px); max-width: calc(100% - 30px);
margin: 2.5px auto; margin: 2.5px auto;
@ -1133,6 +1155,10 @@ summary.comment_data {
margin-top: 10px; margin-top: 10px;
} }
.prefs > p {
font-weight: 500;
}
.prefs select { .prefs select {
border-radius: 5px; border-radius: 5px;
box-shadow: var(--shadow); box-shadow: var(--shadow);
@ -1161,6 +1187,16 @@ input[type="submit"] {
margin-left: 30px; margin-left: 30px;
} }
#settings_subs a {
color: var(--accent);
}
.helper {
padding: 10px;
width: 250px;
background: var(--highlighted) !important;
}
/* Markdown */ /* Markdown */
.md { .md {
@ -1213,7 +1249,6 @@ input[type="submit"] {
.md table { .md table {
margin: 5px; margin: 5px;
display: block;
overflow-x: auto; overflow-x: auto;
} }

@ -8,7 +8,7 @@
<p class="comment_score" title="{{ score.1 }}">{{ score.0 }}</p> <p class="comment_score" title="{{ score.1 }}">{{ score.0 }}</p>
<div class="line"></div> <div class="line"></div>
</div> </div>
<details class="comment_right" open> <details class="comment_right" {% if collapsed == false %}open{% endif %}>
<summary class="comment_data"> <summary class="comment_data">
<a class="comment_author {{ author.distinguished }} {% if author.name == post_author %}op{% endif %}" href="/user/{{ author.name }}">u/{{ author.name }}</a> <a class="comment_author {{ author.distinguished }} {% if author.name == post_author %}op{% endif %}" href="/user/{{ author.name }}">u/{{ author.name }}</a>
{% if author.flair.flair_parts.len() > 0 %} {% if author.flair.flair_parts.len() > 0 %}

@ -71,7 +71,7 @@
{% else if post.post_type == "video" || post.post_type == "gif" %} {% else if post.post_type == "video" || post.post_type == "gif" %}
{% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %}
<script src="/hls.min.js"></script> <script src="/hls.min.js"></script>
<video class="post_media_video short hls_autoplay" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" preload="none" controls {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}> <video class="post_media_video short {% if prefs.autoplay_videos == "on" %}hls_autoplay{% endif %}" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" preload="none" controls>
<source src="{{ post.media.alt_url }}" type="application/vnd.apple.mpegurl" /> <source src="{{ post.media.alt_url }}" type="application/vnd.apple.mpegurl" />
<source src="{{ post.media.url }}" type="video/mp4" /> <source src="{{ post.media.url }}" type="video/mp4" />
</video> </video>

@ -17,6 +17,7 @@
<label for="restrict_sr" class="search_label">in r/{{ sub }}</label> <label for="restrict_sr" class="search_label">in r/{{ sub }}</label>
</div> </div>
{% endif %} {% endif %}
{% if params.typed == "sr_user" %}<input type="hidden" name="type" value="sr_user">{% endif %}
<select id="sort_options" name="sort" title="Sort results by"> <select id="sort_options" name="sort" title="Sort results by">
{% call utils::options(params.sort, ["relevance", "hot", "top", "new", "comments"], "") %} {% call utils::options(params.sort, ["relevance", "hot", "top", "new", "comments"], "") %}
</select>{% if params.sort != "new" %}<select id="timeframe" name="t" title="Timeframe"> </select>{% if params.sort != "new" %}<select id="timeframe" name="t" title="Timeframe">
@ -30,8 +31,11 @@
</button> </button>
</form> </form>
{% if subreddits.len() > 0 %} {% if subreddits.len() > 0 || params.typed == "sr_user" %}
<div id="search_subreddits"> <div id="search_subreddits">
{% if params.typed == "sr_user" %}
<a href="?q={{ params.q }}&sort={{ params.sort }}&t={{ params.t }}" class="search_subreddit" id="more_subreddits">← Back to post/comment results</a>
{% endif %}
{% for subreddit in subreddits %} {% for subreddit in subreddits %}
<a href="{{ subreddit.url }}" class="search_subreddit"> <a href="{{ subreddit.url }}" class="search_subreddit">
<div class="search_subreddit_left">{% if subreddit.icon != "" %}<img loading="lazy" src="{{ subreddit.icon }}" alt="r/{{ subreddit.name }} icon">{% endif %}</div> <div class="search_subreddit_left">{% if subreddit.icon != "" %}<img loading="lazy" src="{{ subreddit.icon }}" alt="r/{{ subreddit.name }} icon">{% endif %}</div>
@ -45,10 +49,13 @@
</div> </div>
</a> </a>
{% endfor %} {% endfor %}
{% if params.typed != "sr_user" %}
<a href="?q={{ params.q }}&sort={{ params.sort }}&t={{ params.t }}&type=sr_user" class="search_subreddit" id="more_subreddits">More subreddit results →</a>
{% endif %}
</div> </div>
{% endif %} {% endif %}
{% if params.typed != "sr_user" %}
{% for post in posts %} {% for post in posts %}
{% if post.flags.nsfw && prefs.show_nsfw != "on" %} {% if post.flags.nsfw && prefs.show_nsfw != "on" %}
{% else if post.title != "Comment" %} {% else if post.title != "Comment" %}
{% call utils::post_in_list(post) %} {% call utils::post_in_list(post) %}
@ -68,11 +75,13 @@
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
{% if prefs.use_hls == "on" %} {% if prefs.use_hls == "on" %}
<script src="/hls.min.js"></script> <script src="/hls.min.js"></script>
<script src="/playHLSVideo.js"></script> <script src="/playHLSVideo.js"></script>
{% endif %} {% endif %}
{% if params.typed != "sr_user" %}
<footer> <footer>
{% if params.before != "" %} {% if params.before != "" %}
<a href="?q={{ params.q }}&restrict_sr={{ params.restrict_sr }} <a href="?q={{ params.q }}&restrict_sr={{ params.restrict_sr }}
@ -86,5 +95,6 @@
&after={{ params.after }}">NEXT</a> &after={{ params.after }}">NEXT</a>
{% endif %} {% endif %}
</footer> </footer>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}

@ -60,7 +60,12 @@
<input type="checkbox" name="autoplay_videos" {% if prefs.autoplay_videos == "on" %}checked{% endif %}> <input type="checkbox" name="autoplay_videos" {% if prefs.autoplay_videos == "on" %}checked{% endif %}>
</div> </div>
<div id="use_hls"> <div id="use_hls">
<label for="use_hls">Use HLS for videos</label> <label for="use_hls">Use HLS for videos
<details id="feeds">
<summary>Why?</summary>
<div id="feed_list" class="helper">Reddit videos require JavaScript (via HLS.js) to be enabled to be played with audio. Therefore, this toggle lets you either use Libreddit JS-free or utilize this feature.</div>
</details>
</label>
<input type="hidden" value="off" name="use_hls"> <input type="hidden" value="off" name="use_hls">
<input type="checkbox" name="use_hls" {% if prefs.use_hls == "on" %}checked{% endif %}> <input type="checkbox" name="use_hls" {% if prefs.use_hls == "on" %}checked{% endif %}>
</div> </div>
@ -77,7 +82,9 @@
<p>Subscribed Feeds</p> <p>Subscribed Feeds</p>
{% for sub in prefs.subscriptions %} {% for sub in prefs.subscriptions %}
<div> <div>
<span>{% if sub.starts_with("u_") -%}{{ format!("u/{}", &sub[2..]) }}{% else -%}{{ format!("r/{}", sub) }}{% endif -%}</span> {% let feed -%}
{% if sub.starts_with("u_") -%}{% let feed = format!("u/{}", &sub[2..]) -%}{% else -%}{% let feed = format!("r/{}", sub) -%}{% endif -%}
<a href="/{{ feed }}">{{ feed }}</a>
<form action="/r/{{ sub }}/unsubscribe/?redirect=settings" method="POST"> <form action="/r/{{ sub }}/unsubscribe/?redirect=settings" method="POST">
<button class="unsubscribe">Unsubscribe</button> <button class="unsubscribe">Unsubscribe</button>
</form> </form>

@ -102,7 +102,7 @@
<video class="post_media_video short" src="{{ post.media.url }}" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" preload="none" controls loop {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}><a href={{ post.media.url }}>Video</a></video> <video class="post_media_video short" src="{{ post.media.url }}" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" preload="none" controls loop {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}><a href={{ post.media.url }}>Video</a></video>
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %} {% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %}
{% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %}
<video class="post_media_video short" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" controls preload="none" {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}> <video class="post_media_video short {% if prefs.autoplay_videos == "on" %}hls_autoplay{% endif %}" width="{{ post.media.width }}" height="{{ post.media.height }}" poster="{{ post.media.poster }}" controls preload="none">
<source src="{{ post.media.alt_url }}" type="application/vnd.apple.mpegurl" /> <source src="{{ post.media.alt_url }}" type="application/vnd.apple.mpegurl" />
<source src="{{ post.media.url }}" type="video/mp4" /> <source src="{{ post.media.url }}" type="video/mp4" />
</video> </video>
@ -130,6 +130,9 @@
{% endif %} {% endif %}
<div class="post_score" title="{{ post.score.1 }}">{{ post.score.0 }}<span class="label"> Upvotes</span></div> <div class="post_score" title="{{ post.score.1 }}">{{ post.score.0 }}<span class="label"> Upvotes</span></div>
<div class="post_body post_preview">
{{ post.body }}
</div>
<div class="post_footer"> <div class="post_footer">
<a href="{{ post.permalink }}" class="post_comments" title="{{ post.comments.1 }} comments">{{ post.comments.0 }} comments</a> <a href="{{ post.permalink }}" class="post_comments" title="{{ post.comments.1 }} comments">{{ post.comments.0 }} comments</a>
</div> </div>