Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
eb6c5e5e1e | |||
ed11135af8 | |||
3a1af78e26 | |||
345770c64d | |||
9eb42932df | |||
f0a6bdc21b | |||
3eef60d486 | |||
59043456ba | |||
90c7088da2 | |||
9e65a65556 | |||
8cfbde2710 | |||
70ff150ab4 | |||
388779c1f2 | |||
6b605d859f | |||
0ae48c400c | |||
a6ed18d674 | |||
838cdd95d1 | |||
bc95b08ffd | |||
e6190267e4 | |||
3ceeac5fb0 | |||
60eb0137c2 | |||
b6bca68d4e | |||
91bff826f0 | |||
af6606a855 | |||
977cd0763a | |||
fcadd44cb3 | |||
9c325c2cbf | |||
e9038f4fe2 | |||
8b8f55e09a | |||
f1b3749cf0 | |||
0708fdfb37 | |||
cad29e9544 | |||
6b59976fcf | |||
f9b3981448 | |||
db3196df5a | |||
b3d4f6f91c | |||
45b875b85d | |||
992d7889c4 | |||
3188f9d8e7 | |||
90fa0b5496 | |||
7aeabfc4bc | |||
150ebe38f3 | |||
2905d114fa | |||
40e97cc75d | |||
7c73e352ce | |||
341c623be8 | |||
4c8b724a9d | |||
227d74b187 | |||
f05a818edd | |||
ceee13cfb7 | |||
a39495b3cb | |||
38cfe4ad71 | |||
0b89539c2b | |||
046b8b3edc | |||
0656756d21 | |||
43551f70fd | |||
364c29c4d5 |
7
.github/workflows/rust.yml
vendored
7
.github/workflows/rust.yml
vendored
@ -23,6 +23,10 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release
|
run: cargo build --release
|
||||||
|
|
||||||
|
- name: Publish to crates.io
|
||||||
|
continue-on-error: true
|
||||||
|
run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v2.2.1
|
- uses: actions/upload-artifact@v2.2.1
|
||||||
name: Upload a Build Artifact
|
name: Upload a Build Artifact
|
||||||
with:
|
with:
|
||||||
@ -43,12 +47,13 @@ jobs:
|
|||||||
if: github.base_ref != 'master'
|
if: github.base_ref != 'master'
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ steps.version.outputs.version }}
|
tag_name: ${{ steps.version.outputs.version }}
|
||||||
name: ${{ steps.version.outputs.version }} - NAME
|
name: ${{ steps.version.outputs.version }} - ${{ github.event.head_commit.message }}
|
||||||
draft: true
|
draft: true
|
||||||
files: |
|
files: |
|
||||||
target/release/libreddit
|
target/release/libreddit
|
||||||
libreddit.sha512
|
libreddit.sha512
|
||||||
body: |
|
body: |
|
||||||
- ${{ github.event.head_commit.message }} ${{ github.sha }}
|
- ${{ github.event.head_commit.message }} ${{ github.sha }}
|
||||||
|
generate_release_notes: true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
|
678
Cargo.lock
generated
678
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
26
Cargo.toml
26
Cargo.toml
@ -3,23 +3,23 @@ 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.20.0"
|
version = "0.22.5"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.10.5", default-features = false }
|
askama = { version = "0.11.1", default-features = false }
|
||||||
async-recursion = "0.3.2"
|
async-recursion = "1.0.0"
|
||||||
cached = "0.26.2"
|
cached = "0.34.0"
|
||||||
clap = { version = "2.33.3", default-features = false }
|
clap = { version = "3.1.6", default-features = false, features = ["std"] }
|
||||||
regex = "1.5.4"
|
regex = "1.5.5"
|
||||||
serde = { version = "1.0.130", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
cookie = "0.15.1"
|
cookie = "0.16.0"
|
||||||
futures-lite = "1.12.0"
|
futures-lite = "1.12.0"
|
||||||
hyper = { version = "0.14.15", features = ["full"] }
|
hyper = { version = "0.14.18", features = ["full"] }
|
||||||
hyper-rustls = "0.23.0"
|
hyper-rustls = "0.23.0"
|
||||||
route-recognizer = "0.3.1"
|
route-recognizer = "0.3.1"
|
||||||
serde_json = "1.0.72"
|
serde_json = "1.0.79"
|
||||||
tokio = { version = "1.14.0", features = ["full"] }
|
tokio = { version = "1.17.0", features = ["full"] }
|
||||||
time = "0.2.7"
|
time = "0.3.9"
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
|
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
|||||||
liberapay: spike
|
liberapay: spike
|
||||||
issuehunt: # Replace with a single IssueHunt username
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
otechie: # Replace with a single Otechie username
|
otechie: # Replace with a single Otechie username
|
||||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
custom: ['https://www.buymeacoffee.com/spikecodes']
|
||||||
|
41
README.md
41
README.md
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
I appreciate any donations! Your support allows me to continue developing Libreddit.
|
I appreciate any donations! Your support allows me to continue developing Libreddit.
|
||||||
|
|
||||||
**Liberapay:** <a href="https://liberapay.com/spike/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
|
<a href="https://www.buymeacoffee.com/spikecodes" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 40px" ></a>
|
||||||
|
<a href="https://liberapay.com/spike/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" style="height: 40px"></a>
|
||||||
|
|
||||||
|
|
||||||
**Bitcoin:** [bc1qwyxjnafpu3gypcpgs025cw9wa7ryudtecmwa6y](bitcoin:bc1qwyxjnafpu3gypcpgs025cw9wa7ryudtecmwa6y)
|
**Bitcoin:** [bc1qwyxjnafpu3gypcpgs025cw9wa7ryudtecmwa6y](bitcoin:bc1qwyxjnafpu3gypcpgs025cw9wa7ryudtecmwa6y)
|
||||||
|
|
||||||
@ -29,6 +31,8 @@ I appreciate any donations! Your support allows me to continue developing Libred
|
|||||||
|
|
||||||
Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new) to have your [selfhosted instance](#deployment) listed here!
|
Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new) to have your [selfhosted instance](#deployment) listed here!
|
||||||
|
|
||||||
|
🔗 **Want to automatically redirect Reddit links to Libreddit? Use [LibRedirect](https://github.com/libredirect/libredirect) or [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect)!**
|
||||||
|
|
||||||
| Website | Country | Cloudflare |
|
| Website | Country | Cloudflare |
|
||||||
|-|-|-|
|
|-|-|-|
|
||||||
| [libredd.it](https://libredd.it) (official) | 🇺🇸 US | |
|
| [libredd.it](https://libredd.it) (official) | 🇺🇸 US | |
|
||||||
@ -41,7 +45,7 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
|
|||||||
| [lr.riverside.rocks](https://lr.riverside.rocks) | 🇺🇸 US | |
|
| [lr.riverside.rocks](https://lr.riverside.rocks) | 🇺🇸 US | |
|
||||||
| [libreddit.silkky.cloud](https://libreddit.silkky.cloud) | 🇫🇮 FI | ✅ |
|
| [libreddit.silkky.cloud](https://libreddit.silkky.cloud) | 🇫🇮 FI | ✅ |
|
||||||
| [libreddit.database.red](https://libreddit.database.red) | 🇺🇸 US | ✅ |
|
| [libreddit.database.red](https://libreddit.database.red) | 🇺🇸 US | ✅ |
|
||||||
| [libreddit.exonip.de](https://libreddit.exonip.de) | 🇩🇪 DE | |
|
| [libreddit.privacy.com.de](https://libreddit.privacy.com.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.jamiethalacker.dev](https://libreddit.jamiethalacker.dev) | 🇺🇸 US | ✅ |
|
| [libreddit.jamiethalacker.dev](https://libreddit.jamiethalacker.dev) | 🇺🇸 US | ✅ |
|
||||||
@ -55,13 +59,30 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
|
|||||||
| [libreddit.igna.rocks](https://libreddit.igna.rocks) | 🇺🇸 US | |
|
| [libreddit.igna.rocks](https://libreddit.igna.rocks) | 🇺🇸 US | |
|
||||||
| [libreddit.autarkic.org](https://libreddit.autarkic.org) | 🇺🇸 US | |
|
| [libreddit.autarkic.org](https://libreddit.autarkic.org) | 🇺🇸 US | |
|
||||||
| [libreddit.flux.industries](https://libreddit.flux.industries) | 🇩🇪 DE | ✅ |
|
| [libreddit.flux.industries](https://libreddit.flux.industries) | 🇩🇪 DE | ✅ |
|
||||||
| [libreddit.drivet.xyz](https://libreddit.drivet.xyz) | 🇫🇮 FI | ✅ |
|
| [libreddit.drivet.xyz](https://libreddit.drivet.xyz) | 🇵🇱 PL | |
|
||||||
| [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 | |
|
| [libreddit.mutahar.rocks](https://libreddit.mutahar.rocks) | 🇫🇷 FR | |
|
||||||
| [libreddit.northboot.xyz](https://libreddit.northboot.xyz) | 🇩🇪 DE | |
|
| [libreddit.northboot.xyz](https://libreddit.northboot.xyz) | 🇩🇪 DE | |
|
||||||
| [leddit.xyz](https://www.leddit.xyz) | 🇩🇪 DE | |
|
| [leddit.xyz](https://leddit.xyz) | 🇺🇸 US | |
|
||||||
|
| [de.leddit.xyz](https://de.leddit.xyz) | 🇩🇪 DE | |
|
||||||
|
| [lr.cowfee.moe](https://lr.cowfee.moe) | 🇺🇸 US | |
|
||||||
|
| [libreddit.hu](https://libreddit.hu) | 🇫🇮 FI | ✅ |
|
||||||
|
| [libreddit.totaldarkness.net](https://libreddit.totaldarkness.net) | 🇨🇦 CA | |
|
||||||
|
| [libreddit.esmailelbob.xyz](https://libreddit.esmailelbob.xyz) | 🇨🇦 CA | |
|
||||||
|
| [libreddit.nl](https://libreddit.nl) | 🇳🇱 NL | |
|
||||||
|
| [lr.stilic.ml](https://lr.stilic.ml) | 🇫🇷 FR | ✅ |
|
||||||
|
| [reddi.tk](https://reddi.tk) | 🇺🇸 US | ✅ |
|
||||||
|
| [libreddit.bus-hit.me](https://libreddit.bus-hit.me) | 🇨🇦 CA | |
|
||||||
|
| [libreddit.datatunnel.xyz](https://libreddit.datatunnel.xyz) | 🇫🇮 FI | |
|
||||||
|
| [libreddit.crewz.me](https://libreddit.crewz.me) | 🇳🇱 NL | ✅ |
|
||||||
|
| [r.walkx.org](https://r.walkx.org) | 🇩🇪 DE | ✅ |
|
||||||
|
| [libreddit.kylrth.com](https://libreddit.kylrth.com) | 🇨🇦 CA | |
|
||||||
|
| [libreddit.yonalee.eu](https://libreddit.yonalee.eu) | 🇱🇺 LU | ✅ |
|
||||||
|
| [libreddit.winscloud.net](https://libreddit.winscloud.net) | 🇹🇭 TH | ✅ |
|
||||||
|
| [libreddit.tiekoetter.com](https://libreddit.tiekoetter.com) | 🇩🇪 DE | |
|
||||||
|
| [reddit.rtrace.io](https://reddit.rtrace.io) | 🇩🇪 DE | |
|
||||||
| [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 | |
|
||||||
@ -69,7 +90,12 @@ Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new)
|
|||||||
| [liredejj74h5xjqr2dylnl5howb2bpikfowqoveub55ru27x43357iid.onion](http://liredejj74h5xjqr2dylnl5howb2bpikfowqoveub55ru27x43357iid.onion) | 🇩🇪 DE | |
|
| [liredejj74h5xjqr2dylnl5howb2bpikfowqoveub55ru27x43357iid.onion](http://liredejj74h5xjqr2dylnl5howb2bpikfowqoveub55ru27x43357iid.onion) | 🇩🇪 DE | |
|
||||||
| [kzhfp3nvb4qp575vy23ccbrgfocezjtl5dx66uthgrhu7nscu6rcwjyd.onion](http://kzhfp3nvb4qp575vy23ccbrgfocezjtl5dx66uthgrhu7nscu6rcwjyd.onion) | 🇺🇸 US | |
|
| [kzhfp3nvb4qp575vy23ccbrgfocezjtl5dx66uthgrhu7nscu6rcwjyd.onion](http://kzhfp3nvb4qp575vy23ccbrgfocezjtl5dx66uthgrhu7nscu6rcwjyd.onion) | 🇺🇸 US | |
|
||||||
| [ecue64ybzvn6vjzl37kcsnwt4ycmbsyf74nbttyg7rkc3t3qwnj7mcyd.onion](http://ecue64ybzvn6vjzl37kcsnwt4ycmbsyf74nbttyg7rkc3t3qwnj7mcyd.onion) | 🇩🇪 DE | |
|
| [ecue64ybzvn6vjzl37kcsnwt4ycmbsyf74nbttyg7rkc3t3qwnj7mcyd.onion](http://ecue64ybzvn6vjzl37kcsnwt4ycmbsyf74nbttyg7rkc3t3qwnj7mcyd.onion) | 🇩🇪 DE | |
|
||||||
|
| [ledditqo2mxfvlgobxnlhrkq4dh34jss6evfkdkb2thlvy6dn4f4gpyd.onion](http://ledditqo2mxfvlgobxnlhrkq4dh34jss6evfkdkb2thlvy6dn4f4gpyd.onion) | 🇺🇸 US | |
|
||||||
|
| [libredoxhxwnmsb6dvzzd35hmgzmawsq5i764es7witwhddvpc2razid.onion](http://libredoxhxwnmsb6dvzzd35hmgzmawsq5i764es7witwhddvpc2razid.onion) | 🇺🇸 US | |
|
||||||
|
| [libreddit.2syis2nnyytz6jnusnjurva4swlaizlnleiks5mjp46phuwjbdjqwgqd.onion](http://libreddit.2syis2nnyytz6jnusnjurva4swlaizlnleiks5mjp46phuwjbdjqwgqd.onion) | 🇪🇬 EG | |
|
||||||
|
| [ol5begilptoou34emq2sshf3may3hlblvipdjtybbovpb7c7zodxmtqd.onion](http://ol5begilptoou34emq2sshf3may3hlblvipdjtybbovpb7c7zodxmtqd.onion) | 🇩🇪 DE | |
|
||||||
|
| [lbrdtjaj7567ptdd4rv74lv27qhxfkraabnyphgcvptl64ijx2tijwid.onion](http://lbrdtjaj7567ptdd4rv74lv27qhxfkraabnyphgcvptl64ijx2tijwid.onion) | 🇨🇦 CA | |
|
||||||
|
| [libreddit.lqs5fjmajyp7rvp4qvyubwofzi6d4imua7vs237rkc4m5qogitqwrgyd.onion](http://libreddit.lqs5fjmajyp7rvp4qvyubwofzi6d4imua7vs237rkc4m5qogitqwrgyd.onion/) | 🇨🇦 CA | |
|
||||||
|
|
||||||
A checkmark in the "Cloudflare" category here refers to the use of the reverse proxy, [Cloudflare](https://cloudflare). The checkmark will not be listed for a site which uses Cloudflare DNS but rather the proxying service which grants Cloudflare the ability to monitor traffic to the website.
|
A checkmark in the "Cloudflare" category here refers to the use of the reverse proxy, [Cloudflare](https://cloudflare). The checkmark will not be listed for a site which uses Cloudflare DNS but rather the proxying service which grants Cloudflare the ability to monitor traffic to the website.
|
||||||
|
|
||||||
@ -225,8 +251,8 @@ libreddit
|
|||||||
Assign a default value for each setting by passing environment variables to Libreddit in the format `LIBREDDIT_DEFAULT_{X}`. Replace `{X}` with the setting name (see list below) in capital letters.
|
Assign a default value for each setting by passing environment variables to Libreddit in the format `LIBREDDIT_DEFAULT_{X}`. Replace `{X}` with the setting name (see list below) in capital letters.
|
||||||
|
|
||||||
| Name | Possible values | Default value |
|
| Name | Possible values | Default value |
|
||||||
|-------------------------|------------------------------------------------------------------------------------------|---------------|
|
|-------------------------|-----------------------------------------------------------------------------------------------------|---------------|
|
||||||
| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold"]` | `system` |
|
| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox"]` | `system` |
|
||||||
| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` |
|
| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` |
|
||||||
| `LAYOUT` | `["card", "clean", "compact"]` | `card` |
|
| `LAYOUT` | `["card", "clean", "compact"]` | `card` |
|
||||||
| `WIDE` | `["on", "off"]` | `off` |
|
| `WIDE` | `["on", "off"]` | `off` |
|
||||||
@ -235,6 +261,7 @@ Assign a default value for each setting by passing environment variables to Libr
|
|||||||
| `SHOW_NSFW` | `["on", "off"]` | `off` |
|
| `SHOW_NSFW` | `["on", "off"]` | `off` |
|
||||||
| `USE_HLS` | `["on", "off"]` | `off` |
|
| `USE_HLS` | `["on", "off"]` | `off` |
|
||||||
| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` |
|
| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` |
|
||||||
|
| `AUTOPLAY_VIDEOS` | `["on", "off"]` | `off` |
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use cached::proc_macro::cached;
|
|||||||
use futures_lite::{future::Boxed, FutureExt};
|
use futures_lite::{future::Boxed, FutureExt};
|
||||||
use hyper::{body::Buf, client, Body, Request, Response, Uri};
|
use hyper::{body::Buf, client, Body, Request, Response, Uri};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{result::Result, str::FromStr};
|
use std::result::Result;
|
||||||
|
|
||||||
use crate::server::RequestExt;
|
use crate::server::RequestExt;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ pub async fn proxy(req: Request<Body>, format: &str) -> Result<Response<Body>, S
|
|||||||
|
|
||||||
async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String> {
|
async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String> {
|
||||||
// First parameter is target URL (mandatory).
|
// First parameter is target URL (mandatory).
|
||||||
let url = Uri::from_str(url).map_err(|_| "Couldn't parse URL".to_string())?;
|
let uri = url.parse::<Uri>().map_err(|_| "Couldn't parse URL".to_string())?;
|
||||||
|
|
||||||
// Prepare the HTTPS connector.
|
// Prepare the HTTPS connector.
|
||||||
let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
|
let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
|
||||||
@ -28,7 +28,7 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, String
|
|||||||
// 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);
|
||||||
|
|
||||||
let mut builder = Request::get(url);
|
let mut builder = Request::get(uri);
|
||||||
|
|
||||||
// Copy useful headers from original request
|
// Copy useful headers from original request
|
||||||
for &key in &["Range", "If-Modified-Since", "Cache-Control"] {
|
for &key in &["Range", "If-Modified-Since", "Cache-Control"] {
|
||||||
@ -89,7 +89,10 @@ fn request(url: String, quarantine: bool) -> Boxed<Result<Response<Body>, String
|
|||||||
response
|
response
|
||||||
.headers()
|
.headers()
|
||||||
.get("Location")
|
.get("Location")
|
||||||
.map(|val| val.to_str().unwrap_or_default())
|
.map(|val| {
|
||||||
|
let new_url = val.to_str().unwrap_or_default();
|
||||||
|
format!("{}{}raw_json=1", new_url, if new_url.contains('?') { "&" } else { "?" })
|
||||||
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
quarantine,
|
quarantine,
|
||||||
|
34
src/main.rs
34
src/main.rs
@ -1,13 +1,6 @@
|
|||||||
// Global specifiers
|
// Global specifiers
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![warn(clippy::pedantic, clippy::all)]
|
#![allow(clippy::cmp_owned)]
|
||||||
#![allow(
|
|
||||||
clippy::needless_pass_by_value,
|
|
||||||
clippy::cast_possible_truncation,
|
|
||||||
clippy::cast_possible_wrap,
|
|
||||||
clippy::manual_find_map,
|
|
||||||
clippy::unused_async
|
|
||||||
)]
|
|
||||||
|
|
||||||
// Reference local files
|
// Reference local files
|
||||||
mod post;
|
mod post;
|
||||||
@ -18,7 +11,7 @@ mod user;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
// Import Crates
|
// Import Crates
|
||||||
use clap::{App as cli, Arg};
|
use clap::{Command, Arg};
|
||||||
|
|
||||||
use futures_lite::FutureExt;
|
use futures_lite::FutureExt;
|
||||||
use hyper::{header::HeaderValue, Body, Request, Response};
|
use hyper::{header::HeaderValue, Body, Request, Response};
|
||||||
@ -70,6 +63,7 @@ async fn font() -> Result<Response<Body>, String> {
|
|||||||
Response::builder()
|
Response::builder()
|
||||||
.status(200)
|
.status(200)
|
||||||
.header("content-type", "font/woff2")
|
.header("content-type", "font/woff2")
|
||||||
|
.header("Cache-Control", "public, max-age=1209600, s-maxage=86400")
|
||||||
.body(include_bytes!("../static/Inter.var.woff2").as_ref().into())
|
.body(include_bytes!("../static/Inter.var.woff2").as_ref().into())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
@ -93,19 +87,19 @@ async fn resource(body: &str, content_type: &str, cache: bool) -> Result<Respons
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let matches = cli::new("Libreddit")
|
let matches = Command::new("Libreddit")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("Private front-end for Reddit written in Rust ")
|
.about("Private front-end for Reddit written in Rust ")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("redirect-https")
|
Arg::new("redirect-https")
|
||||||
.short("r")
|
.short('r')
|
||||||
.long("redirect-https")
|
.long("redirect-https")
|
||||||
.help("Redirect all HTTP requests to HTTPS (no longer functional)")
|
.help("Redirect all HTTP requests to HTTPS (no longer functional)")
|
||||||
.takes_value(false),
|
.takes_value(false),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("address")
|
Arg::new("address")
|
||||||
.short("a")
|
.short('a')
|
||||||
.long("address")
|
.long("address")
|
||||||
.value_name("ADDRESS")
|
.value_name("ADDRESS")
|
||||||
.help("Sets address to listen on")
|
.help("Sets address to listen on")
|
||||||
@ -113,8 +107,8 @@ async fn main() {
|
|||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("port")
|
Arg::new("port")
|
||||||
.short("p")
|
.short('p')
|
||||||
.long("port")
|
.long("port")
|
||||||
.value_name("PORT")
|
.value_name("PORT")
|
||||||
.help("Port to listen on")
|
.help("Port to listen on")
|
||||||
@ -122,8 +116,8 @@ async fn main() {
|
|||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("hsts")
|
Arg::new("hsts")
|
||||||
.short("H")
|
.short('H')
|
||||||
.long("hsts")
|
.long("hsts")
|
||||||
.value_name("EXPIRE_TIME")
|
.value_name("EXPIRE_TIME")
|
||||||
.help("HSTS header to tell browsers that this site should only be accessed over HTTPS")
|
.help("HSTS header to tell browsers that this site should only be accessed over HTTPS")
|
||||||
@ -183,6 +177,9 @@ async fn main() {
|
|||||||
app.at("/img/*path").get(|r| proxy(r, "https://i.redd.it/{path}").boxed());
|
app.at("/img/*path").get(|r| proxy(r, "https://i.redd.it/{path}").boxed());
|
||||||
app.at("/thumb/:point/:id").get(|r| proxy(r, "https://{point}.thumbs.redditmedia.com/{id}").boxed());
|
app.at("/thumb/:point/:id").get(|r| proxy(r, "https://{point}.thumbs.redditmedia.com/{id}").boxed());
|
||||||
app.at("/emoji/:id/:name").get(|r| proxy(r, "https://emoji.redditmedia.com/{id}/{name}").boxed());
|
app.at("/emoji/:id/:name").get(|r| proxy(r, "https://emoji.redditmedia.com/{id}/{name}").boxed());
|
||||||
|
app
|
||||||
|
.at("/preview/:loc/award_images/:fullname/:id")
|
||||||
|
.get(|r| proxy(r, "https://{loc}view.redd.it/award_images/{fullname}/{id}").boxed());
|
||||||
app.at("/preview/:loc/:id").get(|r| proxy(r, "https://{loc}view.redd.it/{id}").boxed());
|
app.at("/preview/:loc/:id").get(|r| proxy(r, "https://{loc}view.redd.it/{id}").boxed());
|
||||||
app.at("/style/*path").get(|r| proxy(r, "https://styles.redditmedia.com/{path}").boxed());
|
app.at("/style/*path").get(|r| proxy(r, "https://styles.redditmedia.com/{path}").boxed());
|
||||||
app.at("/static/*path").get(|r| proxy(r, "https://www.redditstatic.com/{path}").boxed());
|
app.at("/static/*path").get(|r| proxy(r, "https://www.redditstatic.com/{path}").boxed());
|
||||||
@ -196,6 +193,7 @@ async fn main() {
|
|||||||
|
|
||||||
app.at("/user/[deleted]").get(|req| error(req, "User has deleted their account".to_string()).boxed());
|
app.at("/user/[deleted]").get(|req| error(req, "User has deleted their account".to_string()).boxed());
|
||||||
app.at("/user/:name").get(|r| user::profile(r).boxed());
|
app.at("/user/:name").get(|r| user::profile(r).boxed());
|
||||||
|
app.at("/user/:name/:listing").get(|r| user::profile(r).boxed());
|
||||||
app.at("/user/:name/comments/:id").get(|r| post::item(r).boxed());
|
app.at("/user/:name/comments/:id").get(|r| post::item(r).boxed());
|
||||||
app.at("/user/:name/comments/:id/:title").get(|r| post::item(r).boxed());
|
app.at("/user/:name/comments/:id/:title").get(|r| post::item(r).boxed());
|
||||||
app.at("/user/:name/comments/:id/:title/:comment_id").get(|r| post::item(r).boxed());
|
app.at("/user/:name/comments/:id/:title/:comment_id").get(|r| post::item(r).boxed());
|
||||||
|
19
src/post.rs
19
src/post.rs
@ -97,12 +97,20 @@ async fn parse_post(json: &serde_json::Value) -> Post {
|
|||||||
|
|
||||||
let awards: Awards = Awards::parse(&post["data"]["all_awardings"]);
|
let awards: Awards = Awards::parse(&post["data"]["all_awardings"]);
|
||||||
|
|
||||||
|
let permalink = val(post, "permalink");
|
||||||
|
|
||||||
|
let body = if val(post, "removed_by_category") == "moderator" {
|
||||||
|
format!("<div class=\"md\"><p>[removed] — <a href=\"https://www.reveddit.com{}\">view removed post</a></p></div>", permalink)
|
||||||
|
} else {
|
||||||
|
rewrite_urls(&val(post, "selftext_html"))
|
||||||
|
};
|
||||||
|
|
||||||
// Build a post using data parsed from Reddit post API
|
// Build a post using data parsed from Reddit post API
|
||||||
Post {
|
Post {
|
||||||
id: val(post, "id"),
|
id: val(post, "id"),
|
||||||
title: esc!(post, "title"),
|
title: esc!(post, "title"),
|
||||||
community: val(post, "subreddit"),
|
community: val(post, "subreddit"),
|
||||||
body: rewrite_urls(&val(post, "selftext_html")).replace("\\", ""),
|
body,
|
||||||
author: Author {
|
author: Author {
|
||||||
name: val(post, "author"),
|
name: val(post, "author"),
|
||||||
flair: Flair {
|
flair: Flair {
|
||||||
@ -117,7 +125,7 @@ async fn parse_post(json: &serde_json::Value) -> Post {
|
|||||||
},
|
},
|
||||||
distinguished: val(post, "distinguished"),
|
distinguished: val(post, "distinguished"),
|
||||||
},
|
},
|
||||||
permalink: val(post, "permalink"),
|
permalink,
|
||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
upvote_ratio: ratio as i64,
|
upvote_ratio: ratio as i64,
|
||||||
post_type,
|
post_type,
|
||||||
@ -174,7 +182,6 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
|
|||||||
let edited = data["edited"].as_f64().map_or((String::new(), String::new()), time);
|
let edited = data["edited"].as_f64().map_or((String::new(), String::new()), time);
|
||||||
|
|
||||||
let score = data["score"].as_i64().unwrap_or(0);
|
let score = data["score"].as_i64().unwrap_or(0);
|
||||||
let body = rewrite_urls(&val(&comment, "body_html"));
|
|
||||||
|
|
||||||
// If this comment contains replies, handle those too
|
// If this comment contains replies, handle those too
|
||||||
let replies: Vec<Comment> = if data["replies"].is_object() {
|
let replies: Vec<Comment> = if data["replies"].is_object() {
|
||||||
@ -191,6 +198,12 @@ 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;
|
||||||
|
|
||||||
|
let body = if val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]" {
|
||||||
|
format!("<div class=\"md\"><p>[removed] — <a href=\"https://www.reveddit.com{}{}\">view removed comment</a></p></div>", post_link, id)
|
||||||
|
} else {
|
||||||
|
rewrite_urls(&val(&comment, "body_html"))
|
||||||
|
};
|
||||||
|
|
||||||
let author = Author {
|
let author = Author {
|
||||||
name: val(&comment, "author"),
|
name: val(&comment, "author"),
|
||||||
flair: Flair {
|
flair: Flair {
|
||||||
|
@ -47,13 +47,17 @@ struct SearchTemplate {
|
|||||||
// SERVICES
|
// SERVICES
|
||||||
pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
let nsfw_results = if setting(&req, "show_nsfw") == "on" { "&include_over_18=on" } else { "" };
|
let nsfw_results = if setting(&req, "show_nsfw") == "on" { "&include_over_18=on" } else { "" };
|
||||||
let path = format!("{}.json?{}{}", req.uri().path(), req.uri().query().unwrap_or_default(), nsfw_results);
|
let path = format!("{}.json?{}{}&raw_json=1", req.uri().path(), req.uri().query().unwrap_or_default(), nsfw_results);
|
||||||
let query = param(&path, "q").unwrap_or_default();
|
let query = param(&path, "q").unwrap_or_default();
|
||||||
|
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
return Ok(redirect("/".to_string()));
|
return Ok(redirect("/".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if query.starts_with("r/") {
|
||||||
|
return Ok(redirect(format!("/{}", query)));
|
||||||
|
}
|
||||||
|
|
||||||
let sub = req.param("sub").unwrap_or_default();
|
let sub = req.param("sub").unwrap_or_default();
|
||||||
let quarantined = can_access_quarantine(&req, &sub);
|
let quarantined = can_access_quarantine(&req, &sub);
|
||||||
// Handle random subreddits
|
// Handle random subreddits
|
||||||
@ -78,7 +82,7 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
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()));
|
||||||
|
|
||||||
// If all requested subs are filtered, we don't need to fetch posts.
|
// If all requested subs are filtered, we don't need to fetch posts.
|
||||||
if sub.split("+").all(|s| filters.contains(s)) {
|
if sub.split('+').all(|s| filters.contains(s)) {
|
||||||
template(SearchTemplate {
|
template(SearchTemplate {
|
||||||
posts: Vec::new(),
|
posts: Vec::new(),
|
||||||
subreddits,
|
subreddits,
|
||||||
|
@ -105,7 +105,7 @@ impl ResponseExt for Response<Body> {
|
|||||||
fn remove_cookie(&mut self, name: String) {
|
fn remove_cookie(&mut self, name: String) {
|
||||||
let mut cookie = Cookie::named(name);
|
let mut cookie = Cookie::named(name);
|
||||||
cookie.set_path("/");
|
cookie.set_path("/");
|
||||||
cookie.set_max_age(Duration::second());
|
cookie.set_max_age(Duration::seconds(1));
|
||||||
if let Ok(val) = HeaderValue::from_str(&cookie.to_string()) {
|
if let Ok(val) = HeaderValue::from_str(&cookie.to_string()) {
|
||||||
self.headers_mut().append("Set-Cookie", val);
|
self.headers_mut().append("Set-Cookie", val);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ struct SubredditTemplate {
|
|||||||
ends: (String, String),
|
ends: (String, String),
|
||||||
prefs: Preferences,
|
prefs: Preferences,
|
||||||
url: String,
|
url: String,
|
||||||
|
redirect_url: String,
|
||||||
/// Whether the subreddit itself is filtered.
|
/// Whether the subreddit itself is filtered.
|
||||||
is_filtered: bool,
|
is_filtered: bool,
|
||||||
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
|
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
|
||||||
@ -86,22 +87,21 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
} else {
|
} else {
|
||||||
Subreddit::default()
|
Subreddit::default()
|
||||||
}
|
}
|
||||||
} else if sub_name.contains('+') {
|
} else {
|
||||||
// Multireddit
|
// Multireddit, all, popular
|
||||||
Subreddit {
|
Subreddit {
|
||||||
name: sub_name.clone(),
|
name: sub_name.clone(),
|
||||||
..Subreddit::default()
|
..Subreddit::default()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Subreddit::default()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub_name.clone(), sort, req.uri().query().unwrap_or_default());
|
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub_name.clone(), sort, req.uri().query().unwrap_or_default());
|
||||||
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()));
|
||||||
|
let redirect_url = url[1..].replace('?', "%3F").replace('&', "%26");
|
||||||
let filters = get_filters(&req);
|
let filters = get_filters(&req);
|
||||||
|
|
||||||
// If all requested subs are filtered, we don't need to fetch posts.
|
// If all requested subs are filtered, we don't need to fetch posts.
|
||||||
if sub_name.split("+").all(|s| filters.contains(s)) {
|
if sub_name.split('+').all(|s| filters.contains(s)) {
|
||||||
template(SubredditTemplate {
|
template(SubredditTemplate {
|
||||||
sub,
|
sub,
|
||||||
posts: Vec::new(),
|
posts: Vec::new(),
|
||||||
@ -109,6 +109,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
ends: (param(&path, "after").unwrap_or_default(), "".to_string()),
|
ends: (param(&path, "after").unwrap_or_default(), "".to_string()),
|
||||||
prefs: Preferences::new(req),
|
prefs: Preferences::new(req),
|
||||||
url,
|
url,
|
||||||
|
redirect_url,
|
||||||
is_filtered: true,
|
is_filtered: true,
|
||||||
all_posts_filtered: false,
|
all_posts_filtered: false,
|
||||||
})
|
})
|
||||||
@ -124,6 +125,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
ends: (param(&path, "after").unwrap_or_default(), after),
|
ends: (param(&path, "after").unwrap_or_default(), after),
|
||||||
prefs: Preferences::new(req),
|
prefs: Preferences::new(req),
|
||||||
url,
|
url,
|
||||||
|
redirect_url,
|
||||||
is_filtered: false,
|
is_filtered: false,
|
||||||
all_posts_filtered,
|
all_posts_filtered,
|
||||||
})
|
})
|
||||||
@ -211,7 +213,7 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
// Find each subreddit name (separated by '+') in sub parameter
|
// Find each subreddit name (separated by '+') in sub parameter
|
||||||
for part in sub.split('+') {
|
for part in sub.split('+').filter(|x| x != &"") {
|
||||||
// Retrieve display name for the subreddit
|
// Retrieve display name for the subreddit
|
||||||
let display;
|
let display;
|
||||||
let part = if part.starts_with("u_") {
|
let part = if part.starts_with("u_") {
|
||||||
@ -253,7 +255,7 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
|
|||||||
// Redirect back to subreddit
|
// Redirect back to subreddit
|
||||||
// check for redirect parameter if unsubscribing/unfiltering from outside sidebar
|
// check for redirect parameter if unsubscribing/unfiltering from outside sidebar
|
||||||
let path = if let Some(redirect_path) = param(&format!("?{}", query), "redirect") {
|
let path = if let Some(redirect_path) = param(&format!("?{}", query), "redirect") {
|
||||||
format!("/{}/", redirect_path)
|
format!("/{}", redirect_path)
|
||||||
} else {
|
} else {
|
||||||
format!("/r/{}", sub)
|
format!("/r/{}", sub)
|
||||||
};
|
};
|
||||||
@ -334,10 +336,10 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
match json(path, quarantined).await {
|
match json(path, quarantined).await {
|
||||||
// If success, receive JSON in response
|
// If success, receive JSON in response
|
||||||
Ok(response) => template(WikiTemplate {
|
Ok(response) => template(WikiTemplate {
|
||||||
wiki: rewrite_urls(&val(&response, "description_html").replace("\\", "")),
|
wiki: rewrite_urls(&val(&response, "description_html")),
|
||||||
// wiki: format!(
|
// wiki: format!(
|
||||||
// "{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
|
// "{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
|
||||||
// rewrite_urls(&val(&response, "description_html").replace("\\", "")),
|
// rewrite_urls(&val(&response, "description_html"),
|
||||||
// moderators(&sub, quarantined).await.unwrap_or(vec!["Could not fetch moderators".to_string()]).join(""),
|
// moderators(&sub, quarantined).await.unwrap_or(vec!["Could not fetch moderators".to_string()]).join(""),
|
||||||
// ),
|
// ),
|
||||||
sub,
|
sub,
|
||||||
@ -409,7 +411,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
|
|||||||
name: esc!(&res, "display_name"),
|
name: esc!(&res, "display_name"),
|
||||||
title: esc!(&res, "title"),
|
title: esc!(&res, "title"),
|
||||||
description: esc!(&res, "public_description"),
|
description: esc!(&res, "public_description"),
|
||||||
info: rewrite_urls(&val(&res, "description_html").replace("\\", "")),
|
info: rewrite_urls(&val(&res, "description_html")),
|
||||||
// moderators: moderators_list(sub, quarantined).await.unwrap_or_default(),
|
// moderators: moderators_list(sub, quarantined).await.unwrap_or_default(),
|
||||||
icon: format_url(&icon),
|
icon: format_url(&icon),
|
||||||
members: format_num(members),
|
members: format_num(members),
|
||||||
|
22
src/user.rs
22
src/user.rs
@ -5,7 +5,7 @@ use crate::server::RequestExt;
|
|||||||
use crate::utils::{error, filter_posts, format_url, get_filters, param, template, Post, Preferences, User};
|
use crate::utils::{error, filter_posts, format_url, get_filters, param, template, Post, Preferences, User};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use hyper::{Body, Request, Response};
|
use hyper::{Body, Request, Response};
|
||||||
use time::OffsetDateTime;
|
use time::{OffsetDateTime, macros::format_description};
|
||||||
|
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
@ -15,8 +15,11 @@ struct UserTemplate {
|
|||||||
posts: Vec<Post>,
|
posts: Vec<Post>,
|
||||||
sort: (String, String),
|
sort: (String, String),
|
||||||
ends: (String, String),
|
ends: (String, String),
|
||||||
|
/// "overview", "comments", or "submitted"
|
||||||
|
listing: String,
|
||||||
prefs: Preferences,
|
prefs: Preferences,
|
||||||
url: String,
|
url: String,
|
||||||
|
redirect_url: String,
|
||||||
/// Whether the user themself is filtered.
|
/// Whether the user themself is filtered.
|
||||||
is_filtered: bool,
|
is_filtered: bool,
|
||||||
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
|
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
|
||||||
@ -26,13 +29,17 @@ struct UserTemplate {
|
|||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
|
let listing = req.param("listing").unwrap_or_else(|| "overview".to_string());
|
||||||
|
|
||||||
// Build the Reddit JSON API path
|
// Build the Reddit JSON API path
|
||||||
let path = format!(
|
let path = format!(
|
||||||
"/user/{}.json?{}&raw_json=1",
|
"/user/{}/{}.json?{}&raw_json=1",
|
||||||
req.param("name").unwrap_or_else(|| "reddit".to_string()),
|
req.param("name").unwrap_or_else(|| "reddit".to_string()),
|
||||||
req.uri().query().unwrap_or_default()
|
listing,
|
||||||
|
req.uri().query().unwrap_or_default(),
|
||||||
);
|
);
|
||||||
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()));
|
||||||
|
let redirect_url = url[1..].replace('?', "%3F").replace('&', "%26");
|
||||||
|
|
||||||
// Retrieve other variables from Libreddit request
|
// Retrieve other variables from Libreddit request
|
||||||
let sort = param(&path, "sort").unwrap_or_default();
|
let sort = param(&path, "sort").unwrap_or_default();
|
||||||
@ -46,8 +53,10 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
posts: Vec::new(),
|
posts: Vec::new(),
|
||||||
sort: (sort, param(&path, "t").unwrap_or_default()),
|
sort: (sort, param(&path, "t").unwrap_or_default()),
|
||||||
ends: (param(&path, "after").unwrap_or_default(), "".to_string()),
|
ends: (param(&path, "after").unwrap_or_default(), "".to_string()),
|
||||||
|
listing,
|
||||||
prefs: Preferences::new(req),
|
prefs: Preferences::new(req),
|
||||||
url,
|
url,
|
||||||
|
redirect_url,
|
||||||
is_filtered: true,
|
is_filtered: true,
|
||||||
all_posts_filtered: false,
|
all_posts_filtered: false,
|
||||||
})
|
})
|
||||||
@ -62,8 +71,10 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
posts,
|
posts,
|
||||||
sort: (sort, param(&path, "t").unwrap_or_default()),
|
sort: (sort, param(&path, "t").unwrap_or_default()),
|
||||||
ends: (param(&path, "after").unwrap_or_default(), after),
|
ends: (param(&path, "after").unwrap_or_default(), after),
|
||||||
|
listing,
|
||||||
prefs: Preferences::new(req),
|
prefs: Preferences::new(req),
|
||||||
url,
|
url,
|
||||||
|
redirect_url,
|
||||||
is_filtered: false,
|
is_filtered: false,
|
||||||
all_posts_filtered,
|
all_posts_filtered,
|
||||||
})
|
})
|
||||||
@ -82,7 +93,8 @@ async fn user(name: &str) -> Result<User, String> {
|
|||||||
// Send a request to the url
|
// Send a request to the url
|
||||||
json(path, false).await.map(|res| {
|
json(path, false).await.map(|res| {
|
||||||
// Grab creation date as unix timestamp
|
// Grab creation date as unix timestamp
|
||||||
let created: i64 = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
|
let created_unix = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
|
||||||
|
let created = OffsetDateTime::from_unix_timestamp(created_unix).unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
||||||
|
|
||||||
// Closure used to parse JSON from Reddit APIs
|
// Closure used to parse JSON from Reddit APIs
|
||||||
let about = |item| res["data"]["subreddit"][item].as_str().unwrap_or_default().to_string();
|
let about = |item| res["data"]["subreddit"][item].as_str().unwrap_or_default().to_string();
|
||||||
@ -93,7 +105,7 @@ async fn user(name: &str) -> Result<User, String> {
|
|||||||
title: esc!(about("title")),
|
title: esc!(about("title")),
|
||||||
icon: format_url(&about("icon_img")),
|
icon: format_url(&about("icon_img")),
|
||||||
karma: res["data"]["total_karma"].as_i64().unwrap_or(0),
|
karma: res["data"]["total_karma"].as_i64().unwrap_or(0),
|
||||||
created: OffsetDateTime::from_unix_timestamp(created).format("%b %d '%y"),
|
created: created.format(format_description!("[month repr:short] [day] '[year repr:last_two]")).unwrap_or_default(),
|
||||||
banner: esc!(about("banner_img")),
|
banner: esc!(about("banner_img")),
|
||||||
description: about("public_description"),
|
description: about("public_description"),
|
||||||
}
|
}
|
||||||
|
91
src/utils.rs
91
src/utils.rs
@ -9,7 +9,7 @@ use regex::Regex;
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use time::{Duration, OffsetDateTime};
|
use time::{Duration, OffsetDateTime, macros::format_description};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
// Post flair with content, background color and foreground color
|
// Post flair with content, background color and foreground color
|
||||||
@ -21,6 +21,7 @@ pub struct Flair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Part of flair, either emoji or text
|
// Part of flair, either emoji or text
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct FlairPart {
|
pub struct FlairPart {
|
||||||
pub flair_part_type: String,
|
pub flair_part_type: String,
|
||||||
pub value: String,
|
pub value: String,
|
||||||
@ -74,6 +75,7 @@ pub struct Flags {
|
|||||||
pub stickied: bool,
|
pub stickied: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Media {
|
pub struct Media {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub alt_url: String,
|
pub alt_url: String,
|
||||||
@ -86,28 +88,29 @@ impl Media {
|
|||||||
pub async fn parse(data: &Value) -> (String, Self, Vec<GalleryMedia>) {
|
pub async fn parse(data: &Value) -> (String, Self, Vec<GalleryMedia>) {
|
||||||
let mut gallery = Vec::new();
|
let mut gallery = Vec::new();
|
||||||
|
|
||||||
|
// Define the various known places that Reddit might put video URLs.
|
||||||
|
let data_preview = &data["preview"]["reddit_video_preview"];
|
||||||
|
let secure_media = &data["secure_media"]["reddit_video"];
|
||||||
|
let crosspost_parent_media = &data["crosspost_parent_list"][0]["secure_media"]["reddit_video"];
|
||||||
|
|
||||||
// If post is a video, return the video
|
// If post is a video, return the video
|
||||||
let (post_type, url_val, alt_url_val) = if data["preview"]["reddit_video_preview"]["fallback_url"].is_string() {
|
let (post_type, url_val, alt_url_val) = if data_preview["fallback_url"].is_string() {
|
||||||
// Return reddit video
|
|
||||||
(
|
(
|
||||||
if data["preview"]["reddit_video_preview"]["is_gif"].as_bool().unwrap_or(false) {
|
if data_preview["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
|
||||||
"gif"
|
&data_preview["fallback_url"],
|
||||||
} else {
|
Some(&data_preview["hls_url"]),
|
||||||
"video"
|
|
||||||
},
|
|
||||||
&data["preview"]["reddit_video_preview"]["fallback_url"],
|
|
||||||
Some(&data["preview"]["reddit_video_preview"]["hls_url"]),
|
|
||||||
)
|
)
|
||||||
} else if data["secure_media"]["reddit_video"]["fallback_url"].is_string() {
|
} else if secure_media["fallback_url"].is_string() {
|
||||||
// Return reddit video
|
|
||||||
(
|
(
|
||||||
if data["preview"]["reddit_video_preview"]["is_gif"].as_bool().unwrap_or(false) {
|
if secure_media["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
|
||||||
"gif"
|
&secure_media["fallback_url"],
|
||||||
} else {
|
Some(&secure_media["hls_url"]),
|
||||||
"video"
|
)
|
||||||
},
|
} else if crosspost_parent_media["fallback_url"].is_string() {
|
||||||
&data["secure_media"]["reddit_video"]["fallback_url"],
|
(
|
||||||
Some(&data["secure_media"]["reddit_video"]["hls_url"]),
|
if crosspost_parent_media["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
|
||||||
|
&crosspost_parent_media["fallback_url"],
|
||||||
|
Some(&crosspost_parent_media["hls_url"]),
|
||||||
)
|
)
|
||||||
} else if data["post_hint"].as_str().unwrap_or("") == "image" {
|
} else if data["post_hint"].as_str().unwrap_or("") == "image" {
|
||||||
// Handle images, whether GIFs or pics
|
// Handle images, whether GIFs or pics
|
||||||
@ -140,18 +143,12 @@ impl Media {
|
|||||||
|
|
||||||
let source = &data["preview"]["images"][0]["source"];
|
let source = &data["preview"]["images"][0]["source"];
|
||||||
|
|
||||||
let url = if post_type == "self" || post_type == "link" {
|
|
||||||
url_val.as_str().unwrap_or_default().to_string()
|
|
||||||
} else {
|
|
||||||
format_url(url_val.as_str().unwrap_or_default())
|
|
||||||
};
|
|
||||||
|
|
||||||
let alt_url = alt_url_val.map_or(String::new(), |val| format_url(val.as_str().unwrap_or_default()));
|
let alt_url = alt_url_val.map_or(String::new(), |val| format_url(val.as_str().unwrap_or_default()));
|
||||||
|
|
||||||
(
|
(
|
||||||
post_type.to_string(),
|
post_type.to_string(),
|
||||||
Self {
|
Self {
|
||||||
url,
|
url: format_url(url_val.as_str().unwrap_or_default()),
|
||||||
alt_url,
|
alt_url,
|
||||||
width: source["width"].as_i64().unwrap_or_default(),
|
width: source["width"].as_i64().unwrap_or_default(),
|
||||||
height: source["height"].as_i64().unwrap_or_default(),
|
height: source["height"].as_i64().unwrap_or_default(),
|
||||||
@ -251,13 +248,13 @@ impl Post {
|
|||||||
let title = esc!(post, "title");
|
let title = esc!(post, "title");
|
||||||
|
|
||||||
// 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;
|
||||||
let awards = Awards::parse(&data["all_awardings"]);
|
let awards = Awards::parse(&data["all_awardings"]);
|
||||||
|
|
||||||
// selftext_html is set for text posts when browsing.
|
// selftext_html is set for text posts when browsing.
|
||||||
let mut body = rewrite_urls(&val(post, "selftext_html"));
|
let mut body = rewrite_urls(&val(post, "selftext_html"));
|
||||||
if body == "" {
|
if body.is_empty() {
|
||||||
body = rewrite_urls(&val(post, "body_html"))
|
body = rewrite_urls(&val(post, "body_html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
posts.push(Self {
|
posts.push(Self {
|
||||||
@ -384,7 +381,7 @@ impl Awards {
|
|||||||
pub fn parse(items: &Value) -> Self {
|
pub fn parse(items: &Value) -> Self {
|
||||||
let parsed = items.as_array().unwrap_or(&Vec::new()).iter().fold(Vec::new(), |mut awards, item| {
|
let parsed = items.as_array().unwrap_or(&Vec::new()).iter().fold(Vec::new(), |mut awards, item| {
|
||||||
let name = item["name"].as_str().unwrap_or_default().to_string();
|
let name = item["name"].as_str().unwrap_or_default().to_string();
|
||||||
let icon_url = format_url(&item["icon_url"].as_str().unwrap_or_default().to_string());
|
let icon_url = format_url(item["resized_icons"][0]["url"].as_str().unwrap_or_default());
|
||||||
let description = item["description"].as_str().unwrap_or_default().to_string();
|
let description = item["description"].as_str().unwrap_or_default().to_string();
|
||||||
let count: i64 = i64::from_str(&item["count"].to_string()).unwrap_or(1);
|
let count: i64 = i64::from_str(&item["count"].to_string()).unwrap_or(1);
|
||||||
|
|
||||||
@ -484,7 +481,7 @@ impl Preferences {
|
|||||||
|
|
||||||
/// Gets a `HashSet` of filters from the cookie in the given `Request`.
|
/// Gets a `HashSet` of filters from the cookie in the given `Request`.
|
||||||
pub fn get_filters(req: &Request<Body>) -> HashSet<String> {
|
pub fn get_filters(req: &Request<Body>) -> HashSet<String> {
|
||||||
setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect::<HashSet<String>>()
|
setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect::<HashSet<String>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filters a `Vec<Post>` by the given `HashSet` of filters (each filter being a subreddit name or a user name). If a
|
/// Filters a `Vec<Post>` by the given `HashSet` of filters (each filter being a subreddit name or a user name). If a
|
||||||
@ -551,7 +548,7 @@ pub fn format_url(url: &str) -> String {
|
|||||||
if url.is_empty() || url == "self" || url == "default" || url == "nsfw" || url == "spoiler" {
|
if url.is_empty() || url == "self" || url == "default" || url == "nsfw" || url == "spoiler" {
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
Url::parse(url).map_or(String::new(), |parsed| {
|
Url::parse(url).map_or(url.to_string(), |parsed| {
|
||||||
let domain = parsed.domain().unwrap_or_default();
|
let domain = parsed.domain().unwrap_or_default();
|
||||||
|
|
||||||
let capture = |regex: &str, format: &str, segments: i16| {
|
let capture = |regex: &str, format: &str, segments: i16| {
|
||||||
@ -586,8 +583,12 @@ pub fn format_url(url: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match domain {
|
match domain {
|
||||||
|
"www.reddit.com" => capture(r"https://www\.reddit\.com/(.*)", "/", 1),
|
||||||
|
"old.reddit.com" => capture(r"https://old\.reddit\.com/(.*)", "/", 1),
|
||||||
|
"np.reddit.com" => capture(r"https://np\.reddit\.com/(.*)", "/", 1),
|
||||||
|
"reddit.com" => capture(r"https://reddit\.com/(.*)", "/", 1),
|
||||||
"v.redd.it" => chain!(
|
"v.redd.it" => chain!(
|
||||||
capture(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$))", "/vid/", 2),
|
capture(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$|\?source=fallback))", "/vid/", 2),
|
||||||
capture(r"https://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$", "/hls/", 2)
|
capture(r"https://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$", "/hls/", 2)
|
||||||
),
|
),
|
||||||
"i.redd.it" => capture(r"https://i\.redd\.it/(.*)", "/img/", 1),
|
"i.redd.it" => capture(r"https://i\.redd\.it/(.*)", "/img/", 1),
|
||||||
@ -598,7 +599,7 @@ pub fn format_url(url: &str) -> String {
|
|||||||
"external-preview.redd.it" => capture(r"https://external\-preview\.redd\.it/(.*)", "/preview/external-pre/", 1),
|
"external-preview.redd.it" => capture(r"https://external\-preview\.redd\.it/(.*)", "/preview/external-pre/", 1),
|
||||||
"styles.redditmedia.com" => capture(r"https://styles\.redditmedia\.com/(.*)", "/style/", 1),
|
"styles.redditmedia.com" => capture(r"https://styles\.redditmedia\.com/(.*)", "/style/", 1),
|
||||||
"www.redditstatic.com" => capture(r"https://www\.redditstatic\.com/(.*)", "/static/", 1),
|
"www.redditstatic.com" => capture(r"https://www\.redditstatic\.com/(.*)", "/static/", 1),
|
||||||
_ => String::new(),
|
_ => url.to_string(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -606,8 +607,12 @@ pub fn format_url(url: &str) -> String {
|
|||||||
|
|
||||||
// Rewrite Reddit links to Libreddit in body of text
|
// Rewrite Reddit links to Libreddit in body of text
|
||||||
pub fn rewrite_urls(input_text: &str) -> String {
|
pub fn rewrite_urls(input_text: &str) -> String {
|
||||||
|
|
||||||
let text1 =
|
let text1 =
|
||||||
Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|)(reddit\.com|redd\.it)/"#).map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string());
|
Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|)(reddit\.com|redd\.it)/"#)
|
||||||
|
.map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string())
|
||||||
|
// Remove (html-encoded) "\" from URLs.
|
||||||
|
.replace("%5C", "").replace(r"\", "");
|
||||||
|
|
||||||
// Rewrite external media previews to Libreddit
|
// Rewrite external media previews to Libreddit
|
||||||
Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {
|
Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {
|
||||||
@ -636,12 +641,12 @@ pub fn format_num(num: i64) -> (String, String) {
|
|||||||
|
|
||||||
// Parse a relative and absolute time from a UNIX timestamp
|
// Parse a relative and absolute time from a UNIX timestamp
|
||||||
pub fn time(created: f64) -> (String, String) {
|
pub fn time(created: f64) -> (String, String) {
|
||||||
let time = OffsetDateTime::from_unix_timestamp(created.round() as i64);
|
let time = OffsetDateTime::from_unix_timestamp(created.round() as i64).unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
||||||
let time_delta = OffsetDateTime::now_utc() - time;
|
let time_delta = OffsetDateTime::now_utc() - time;
|
||||||
|
|
||||||
// If the time difference is more than a month, show full date
|
// If the time difference is more than a month, show full date
|
||||||
let rel_time = if time_delta > Duration::days(30) {
|
let rel_time = if time_delta > Duration::days(30) {
|
||||||
time.format("%b %d '%y")
|
time.format(format_description!("[month repr:short] [day] '[year repr:last_two]")).unwrap_or_default()
|
||||||
// Otherwise, show relative date/time
|
// Otherwise, show relative date/time
|
||||||
} else if time_delta.whole_days() > 0 {
|
} else if time_delta.whole_days() > 0 {
|
||||||
format!("{}d ago", time_delta.whole_days())
|
format!("{}d ago", time_delta.whole_days())
|
||||||
@ -651,7 +656,7 @@ pub fn time(created: f64) -> (String, String) {
|
|||||||
format!("{}m ago", time_delta.whole_minutes())
|
format!("{}m ago", time_delta.whole_minutes())
|
||||||
};
|
};
|
||||||
|
|
||||||
(rel_time, time.format("%b %d %Y, %H:%M:%S UTC"))
|
(rel_time, time.format(format_description!("[month repr:short] [day] [year], [hour]:[minute]:[second] UTC")).unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
// val() function used to parse JSON from Reddit APIs
|
// val() function used to parse JSON from Reddit APIs
|
||||||
@ -709,6 +714,7 @@ pub async fn error(req: Request<Body>, msg: String) -> Result<Response<Body>, St
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::format_num;
|
use super::format_num;
|
||||||
|
use super::rewrite_urls;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn format_num_works() {
|
fn format_num_works() {
|
||||||
@ -718,4 +724,13 @@ mod tests {
|
|||||||
assert_eq!(format_num(1001), ("1.0k".to_string(), "1001".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()));
|
assert_eq!(format_num(1_999_999), ("2.0m".to_string(), "1999999".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rewrite_urls_removes_backslashes() {
|
||||||
|
let comment_body_html = r#"<a href=\"https://www.reddit.com/r/linux%5C_gaming/comments/x/just%5C_a%5C_test%5C/\">https://www.reddit.com/r/linux\\_gaming/comments/x/just\\_a\\_test/</a>"#;
|
||||||
|
assert_eq!(
|
||||||
|
rewrite_urls(comment_body_html),
|
||||||
|
r#"<a href="https://www.reddit.com/r/linux_gaming/comments/x/just_a_test/">https://www.reddit.com/r/linux_gaming/comments/x/just_a_test/</a>"#
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,6 +465,7 @@ aside {
|
|||||||
#wiki {
|
#wiki {
|
||||||
background: var(--foreground);
|
background: var(--foreground);
|
||||||
padding: 35px;
|
padding: 35px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
#top {
|
#top {
|
||||||
@ -486,8 +487,8 @@ aside {
|
|||||||
|
|
||||||
/* Sorting and Search */
|
/* Sorting and Search */
|
||||||
|
|
||||||
select, #search, #sort_options, #inside, #searchbox > *, #sort_submit {
|
select, #search, #sort_options, #listing_options, #inside, #searchbox > *, #sort_submit {
|
||||||
height: 40px;
|
height: 38px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search_label {
|
.search_label {
|
||||||
@ -504,7 +505,7 @@ select {
|
|||||||
|
|
||||||
select, #search {
|
select, #search {
|
||||||
border: none;
|
border: none;
|
||||||
padding: 0 15px;
|
padding: 0 10px;
|
||||||
|
|
||||||
appearance: none;
|
appearance: none;
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
@ -562,6 +563,11 @@ button.submit:hover > svg { stroke: var(--accent); }
|
|||||||
border-radius: 5px 0px 0px 5px;
|
border-radius: 5px 0px 0px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#listing_options + #sort_select {
|
||||||
|
margin-left: 10px;
|
||||||
|
border-radius: 5px 0px 0px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
#search_sort {
|
#search_sort {
|
||||||
background: var(--highlighted);
|
background: var(--highlighted);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -590,15 +596,16 @@ button.submit:hover > svg { stroke: var(--accent); }
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sort_options, footer > a {
|
#sort_options, #listing_options, footer > a {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
align-items: center;
|
||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
background: var(--outside);
|
background: var(--outside);
|
||||||
display: flex;
|
display: flex;
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sort_options > a, footer > a {
|
#sort_options > a, #listing_options > a, footer > a {
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@ -606,12 +613,12 @@ button.submit:hover > svg { stroke: var(--accent); }
|
|||||||
transition: 0.2s background;
|
transition: 0.2s background;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sort_options > a.selected {
|
#sort_options > a.selected, #listing_options > a.selected {
|
||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
#sort_options > a:not(.selected):hover {
|
#sort_options > a:not(.selected):hover, #listing_options > a:not(.selected):hover {
|
||||||
background: var(--foreground);
|
background: var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,7 +725,7 @@ a.search_subreddit:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post_score {
|
.post_score {
|
||||||
padding-top: 16px;
|
padding-top: 19px;
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -747,6 +754,7 @@ a.search_subreddit:hover {
|
|||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
margin: 5px 15px 5px 12px;
|
margin: 5px 15px 5px 12px;
|
||||||
grid-area: post_title;
|
grid-area: post_title;
|
||||||
}
|
}
|
||||||
@ -874,8 +882,9 @@ a.search_subreddit:hover {
|
|||||||
|
|
||||||
#post_url {
|
#post_url {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
margin: 5px 15px;
|
margin: 5px 12px;
|
||||||
grid-area: post_media;
|
grid-area: post_media;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_body {
|
.post_body {
|
||||||
@ -901,7 +910,7 @@ a.search_subreddit:hover {
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
grid-area: post_footer;
|
grid-area: post_footer;
|
||||||
margin: 5px 20px 15px 15px;
|
margin: 5px 20px 15px 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_comments {
|
.post_comments {
|
||||||
@ -1179,12 +1188,10 @@ summary.comment_data {
|
|||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.prefs {
|
.prefs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background: var(--post);
|
background: var(--post);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -1197,11 +1204,19 @@ summary.comment_data {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 35px;
|
height: 35px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-top: 10px;
|
margin-top: 7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.prefs > p {
|
.prefs legend {
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
border-bottom: 1px solid var(--highlighted);
|
||||||
|
font-size: 18px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prefs legend:not(:first-child) {
|
||||||
|
padding-top: 10px;
|
||||||
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.prefs select {
|
.prefs select {
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% block search %}{% endblock %}
|
{% block search %}{% endblock %}
|
||||||
<div id="links">
|
<div id="links">
|
||||||
<a id="reddit_link" href="https://www.reddit.com{{ url }}">
|
<a id="reddit_link" href="https://www.reddit.com{{ url }}" rel="nofollow">
|
||||||
<span>reddit</span>
|
<span>reddit</span>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path d="M23 12.0737C23 10.7308 21.9222 9.64226 20.5926 9.64226C19.9435 9.64226 19.3557 9.90274 18.923 10.3244C17.2772 9.12492 15.0099 8.35046 12.4849 8.26135L13.5814 3.05002L17.1643 3.8195C17.2081 4.73947 17.9539 5.47368 18.8757 5.47368C19.8254 5.47368 20.5951 4.69626 20.5951 3.73684C20.5951 2.77769 19.8254 2 18.8758 2C18.2001 2 17.6214 2.39712 17.3404 2.96952L13.3393 2.11066C13.2279 2.08679 13.1116 2.10858 13.016 2.17125C12.9204 2.23393 12.8533 2.33235 12.8295 2.44491L11.6051 8.25987C9.04278 8.33175 6.73904 9.10729 5.07224 10.3201C4.63988 9.90099 4.05398 9.64226 3.40757 9.64226C2.0781 9.64226 1 10.7308 1 12.0737C1 13.0618 1.58457 13.9105 2.4225 14.2909C2.38466 14.5342 2.36545 14.78 2.36505 15.0263C2.36505 18.7673 6.67626 21.8 11.9945 21.8C17.3131 21.8 21.6243 18.7673 21.6243 15.0263C21.6243 14.7794 21.6043 14.5359 21.5678 14.2957C22.4109 13.9175 23 13.0657 23 12.0737Z"/>
|
<path d="M23 12.0737C23 10.7308 21.9222 9.64226 20.5926 9.64226C19.9435 9.64226 19.3557 9.90274 18.923 10.3244C17.2772 9.12492 15.0099 8.35046 12.4849 8.26135L13.5814 3.05002L17.1643 3.8195C17.2081 4.73947 17.9539 5.47368 18.8757 5.47368C19.8254 5.47368 20.5951 4.69626 20.5951 3.73684C20.5951 2.77769 19.8254 2 18.8758 2C18.2001 2 17.6214 2.39712 17.3404 2.96952L13.3393 2.11066C13.2279 2.08679 13.1116 2.10858 13.016 2.17125C12.9204 2.23393 12.8533 2.33235 12.8295 2.44491L11.6051 8.25987C9.04278 8.33175 6.73904 9.10729 5.07224 10.3201C4.63988 9.90099 4.05398 9.64226 3.40757 9.64226C2.0781 9.64226 1 10.7308 1 12.0737C1 13.0618 1.58457 13.9105 2.4225 14.2909C2.38466 14.5342 2.36545 14.78 2.36505 15.0263C2.36505 18.7673 6.67626 21.8 11.9945 21.8C17.3131 21.8 21.6243 18.7673 21.6243 15.0263C21.6243 14.7794 21.6043 14.5359 21.5678 14.2957C22.4109 13.9175 23 13.0657 23 12.0737Z"/>
|
||||||
|
@ -10,7 +10,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<details class="comment_right" {% if !collapsed || highlighted %}open{% endif %}>
|
<details class="comment_right" {% if !collapsed || highlighted %}open{% endif %}>
|
||||||
<summary class="comment_data">
|
<summary class="comment_data">
|
||||||
|
{% if author.name != "[deleted]" %}
|
||||||
<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>
|
||||||
|
{% else %}
|
||||||
|
<span class="comment_author {{ author.distinguished }}">u/[deleted]</span>
|
||||||
|
{% endif %}
|
||||||
{% if author.flair.flair_parts.len() > 0 %}
|
{% if author.flair.flair_parts.len() > 0 %}
|
||||||
<small class="author_flair">{% call utils::render_flair(author.flair.flair_parts) %}</small>
|
<small class="author_flair">{% call utils::render_flair(author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<a class="post_author" href="/user/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
<a class="post_author {{ post.author.distinguished }}" href="/user/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
||||||
{% if post.author.flair.flair_parts.len() > 0 %}
|
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||||
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -56,7 +56,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
<p class="post_title">
|
<p class="post_title">
|
||||||
<a href="{{ post.permalink }}">{{ post.title }}</a>
|
{{ post.title }}
|
||||||
{% if post.flair.flair_parts.len() > 0 %}
|
{% if post.flair.flair_parts.len() > 0 %}
|
||||||
<a href="/r/{{ post.community }}/search?q=flair_name%3A%22{{ post.flair.text }}%22&restrict_sr=on"
|
<a href="/r/{{ post.community }}/search?q=flair_name%3A%22{{ post.flair.text }}%22&restrict_sr=on"
|
||||||
class="post_flair"
|
class="post_flair"
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
<div id="settings">
|
<div id="settings">
|
||||||
<form action="/settings" method="POST">
|
<form action="/settings" method="POST">
|
||||||
<div class="prefs">
|
<div class="prefs">
|
||||||
<p>Appearance</p>
|
<legend>Appearance</legend>
|
||||||
<div id="theme">
|
<div id="theme">
|
||||||
<label for="theme">Theme:</label>
|
<label for="theme">Theme:</label>
|
||||||
<select name="theme">
|
<select name="theme">
|
||||||
{% call utils::options(prefs.theme, ["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox"], "system") %}
|
{% call utils::options(prefs.theme, ["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox"], "system") %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<p>Interface</p>
|
<legend>Interface</legend>
|
||||||
<div id="front_page">
|
<div id="front_page">
|
||||||
<label for="front_page">Front page:</label>
|
<label for="front_page">Front page:</label>
|
||||||
<select name="front_page">
|
<select name="front_page">
|
||||||
@ -36,7 +36,7 @@
|
|||||||
<input type="hidden" value="off" name="wide">
|
<input type="hidden" value="off" name="wide">
|
||||||
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
|
<input type="checkbox" name="wide" {% if prefs.wide == "on" %}checked{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
<p>Content</p>
|
<legend>Content</legend>
|
||||||
<div id="post_sort">
|
<div id="post_sort">
|
||||||
<label for="post_sort" title="Applies only to subreddit feeds">Default subreddit post sort:</label>
|
<label for="post_sort" title="Applies only to subreddit feeds">Default subreddit post sort:</label>
|
||||||
<select name="post_sort">
|
<select name="post_sort">
|
||||||
@ -79,7 +79,7 @@
|
|||||||
</form>
|
</form>
|
||||||
{% if prefs.subscriptions.len() > 0 %}
|
{% if prefs.subscriptions.len() > 0 %}
|
||||||
<div class="prefs" id="settings_subs">
|
<div class="prefs" id="settings_subs">
|
||||||
<p>Subscribed Feeds</p>
|
<legend>Subscribed Feeds</legend>
|
||||||
{% for sub in prefs.subscriptions %}
|
{% for sub in prefs.subscriptions %}
|
||||||
<div>
|
<div>
|
||||||
{% let feed -%}
|
{% let feed -%}
|
||||||
@ -94,7 +94,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if !prefs.filters.is_empty() %}
|
{% if !prefs.filters.is_empty() %}
|
||||||
<div class="prefs" id="settings_filters">
|
<div class="prefs" id="settings_filters">
|
||||||
<p>Filtered Feeds</p>
|
<legend>Filtered Feeds</legend>
|
||||||
{% for sub in prefs.filters %}
|
{% for sub in prefs.filters %}
|
||||||
<div>
|
<div>
|
||||||
{% let feed -%}
|
{% let feed -%}
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if sub.name.contains("+") %}
|
{% if sub.name.contains("+") %}
|
||||||
<form action="/r/{{ sub.name }}/subscribe" method="POST">
|
<form action="/r/{{ sub.name }}/subscribe?redirect={{ redirect_url }}" method="POST">
|
||||||
<button id="multisub" class="subscribe" title="Subscribe to each sub in this multireddit">Subscribe to Multireddit</button>
|
<button id="multisub" class="subscribe" title="Subscribe to each sub in this multireddit">Subscribe to Multireddit</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -64,22 +64,22 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
{% if ends.0 != "" %}
|
{% if !ends.0.is_empty() %}
|
||||||
<a href="?sort={{ sort.0 }}&t={{ sort.1 }}&before={{ ends.0 }}">PREV</a>
|
<a href="?sort={{ sort.0 }}&t={{ sort.1 }}&before={{ ends.0 }}">PREV</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if ends.1 != "" %}
|
{% if !ends.1.is_empty() %}
|
||||||
<a href="?sort={{ sort.0 }}&t={{ sort.1 }}&after={{ ends.1 }}">NEXT</a>
|
<a href="?sort={{ sort.0 }}&t={{ sort.1 }}&after={{ ends.1 }}">NEXT</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if is_filtered || (sub.name != "" && !sub.name.contains("+")) %}
|
{% if is_filtered || (!sub.name.is_empty() && sub.name != "all" && sub.name != "popular" && !sub.name.contains("+")) %}
|
||||||
<aside>
|
<aside>
|
||||||
{% if is_filtered %}
|
{% if is_filtered %}
|
||||||
<center>(Content from r/{{ sub.name }} has been filtered)</center>
|
<center>(Content from r/{{ sub.name }} has been filtered)</center>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if sub.name != "" && !sub.name.contains("+") %}
|
{% if !sub.name.is_empty() && sub.name != "all" && sub.name != "popular" && !sub.name.contains("+") %}
|
||||||
<div class="panel" id="subreddit">
|
<div class="panel" id="subreddit">
|
||||||
{% if sub.wiki %}
|
{% if sub.wiki %}
|
||||||
<div id="top">
|
<div id="top">
|
||||||
@ -101,22 +101,22 @@
|
|||||||
<div id="sub_actions">
|
<div id="sub_actions">
|
||||||
<div id="sub_subscription">
|
<div id="sub_subscription">
|
||||||
{% if prefs.subscriptions.contains(sub.name) %}
|
{% if prefs.subscriptions.contains(sub.name) %}
|
||||||
<form action="/r/{{ sub.name }}/unsubscribe" method="POST">
|
<form action="/r/{{ sub.name }}/unsubscribe?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="unsubscribe">Unsubscribe</button>
|
<button class="unsubscribe">Unsubscribe</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="/r/{{ sub.name }}/subscribe" method="POST">
|
<form action="/r/{{ sub.name }}/subscribe?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="subscribe">Subscribe</button>
|
<button class="subscribe">Subscribe</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div id="sub_filter">
|
<div id="sub_filter">
|
||||||
{% if prefs.filters.contains(sub.name) %}
|
{% if prefs.filters.contains(sub.name) %}
|
||||||
<form action="/r/{{ sub.name }}/unfilter" method="POST">
|
<form action="/r/{{ sub.name }}/unfilter?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="unfilter">Unfilter</button>
|
<button class="unfilter">Unfilter</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="/r/{{ sub.name }}/filter" method="POST">
|
<form action="/r/{{ sub.name }}/filter?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="filter">Filter</button>
|
<button class="filter">Filter</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -16,9 +16,12 @@
|
|||||||
{% if !is_filtered %}
|
{% if !is_filtered %}
|
||||||
<div id="column_one">
|
<div id="column_one">
|
||||||
<form id="sort">
|
<form id="sort">
|
||||||
<select name="sort">
|
<div id="listing_options">
|
||||||
{% call utils::options(sort.0, ["hot", "new", "top"], "") %}
|
{% call utils::sort(["/user/", user.name.as_str()].concat(), ["overview", "comments", "submitted"], listing) %}
|
||||||
</select>{% if sort.0 == "top" %}<select id="timeframe" name="t">
|
</div>
|
||||||
|
<select id="sort_select" name="sort">
|
||||||
|
{% call utils::options(sort.0, ["hot", "new", "top", "controversial"], "") %}
|
||||||
|
</select>{% if sort.0 == "top" || sort.0 == "controversial" %}<select id="timeframe" name="t">
|
||||||
{% call utils::options(sort.1, ["hour", "day", "week", "month", "year", "all"], "all") %}
|
{% call utils::options(sort.1, ["hour", "day", "week", "month", "year", "all"], "all") %}
|
||||||
</select>{% endif %}<button id="sort_submit" class="submit">
|
</select>{% endif %}<button id="sort_submit" class="submit">
|
||||||
<svg width="15" viewBox="0 0 110 100" fill="none" stroke-width="10" stroke-linecap="round">
|
<svg width="15" viewBox="0 0 110 100" fill="none" stroke-width="10" stroke-linecap="round">
|
||||||
@ -91,22 +94,22 @@
|
|||||||
{% let name = ["u_", user.name.as_str()].join("") %}
|
{% let name = ["u_", user.name.as_str()].join("") %}
|
||||||
<div id="user_subscription">
|
<div id="user_subscription">
|
||||||
{% if prefs.subscriptions.contains(name) %}
|
{% if prefs.subscriptions.contains(name) %}
|
||||||
<form action="/r/{{ name }}/unsubscribe" method="POST">
|
<form action="/r/{{ name }}/unsubscribe?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="unsubscribe">Unfollow</button>
|
<button class="unsubscribe">Unfollow</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="/r/{{ name }}/subscribe" method="POST">
|
<form action="/r/{{ name }}/subscribe?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="subscribe">Follow</button>
|
<button class="subscribe">Follow</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div id="user_filter">
|
<div id="user_filter">
|
||||||
{% if prefs.filters.contains(name) %}
|
{% if prefs.filters.contains(name) %}
|
||||||
<form action="/r/{{ name }}/unfilter" method="POST">
|
<form action="/r/{{ name }}/unfilter?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="unfilter">Unfilter</button>
|
<button class="unfilter">Unfilter</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="/r/{{ name }}/filter" method="POST">
|
<form action="/r/{{ name }}/filter?redirect={{ redirect_url }}" method="POST">
|
||||||
<button class="filter">Filter</button>
|
<button class="filter">Filter</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% macro options(current, values, default) -%}
|
{% macro options(current, values, default) -%}
|
||||||
{% for value in values %}
|
{% for value in values %}
|
||||||
<option value="{{ value }}" {% if current == value || (current == "" && value == default) %}selected{% endif %}>
|
<option value="{{ value }}" {% if current == value.to_string() || (current == "" && value.to_string() == default.to_string()) %}selected{% endif %}>
|
||||||
{{ format!("{}{}", value.get(0..1).unwrap_or_default().to_uppercase(), value.get(1..).unwrap_or_default()) }}
|
{{ format!("{}{}", value.get(0..1).unwrap_or_default().to_uppercase(), value.get(1..).unwrap_or_default()) }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
{% macro sort(root, methods, selected) -%}
|
{% macro sort(root, methods, selected) -%}
|
||||||
{% for method in methods %}
|
{% for method in methods %}
|
||||||
<a {% if method == selected %}class="selected"{% endif %} href="{{ root }}/{{ method }}">
|
<a {% if method.to_string() == selected.to_string() %}class="selected"{% endif %} href="{{ root }}/{{ method }}">
|
||||||
{{ format!("{}{}", method.get(0..1).unwrap_or_default().to_uppercase(), method.get(1..).unwrap_or_default()) }}
|
{{ format!("{}{}", method.get(0..1).unwrap_or_default().to_uppercase(), method.get(1..).unwrap_or_default()) }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<input id="search" type="text" name="q" placeholder="Search" title="Search libreddit" value="{{ search }}">
|
<input id="search" type="text" name="q" placeholder="Search" title="Search libreddit" value="{{ search }}">
|
||||||
{% if root != "/r/" && !root.is_empty() %}
|
{% if root != "/r/" && !root.is_empty() %}
|
||||||
<div id="inside">
|
<div id="inside">
|
||||||
<input type="checkbox" name="restrict_sr" id="restrict_sr">
|
<input type="checkbox" name="restrict_sr" id="restrict_sr" checked>
|
||||||
<label for="restrict_sr" class="search_label" title="Restrict search to this subreddit">in {{ root }}</label>
|
<label for="restrict_sr" class="search_label" title="Restrict search to this subreddit">in {{ root }}</label>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -34,7 +34,7 @@
|
|||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{% macro render_flair(flair_parts) -%}
|
{% macro render_flair(flair_parts) -%}
|
||||||
{% for flair_part in flair_parts %}{% if flair_part.flair_part_type == "emoji" %}<span class="emoji" style="background-image:url('{{ flair_part.value }}');"></span>{% else if flair_part.flair_part_type == "text" && !flair_part.value.is_empty() %}<span>{{ flair_part.value }}</span>{% endif %}{% endfor %}
|
{% for flair_part in flair_parts.clone() %}{% if flair_part.flair_part_type == "emoji" %}<span class="emoji" style="background-image:url('{{ flair_part.value }}');"></span>{% else if flair_part.flair_part_type == "text" && !flair_part.value.is_empty() %}<span>{{ flair_part.value }}</span>{% endif %}{% endfor %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{% macro sub_list(current) -%}
|
{% macro sub_list(current) -%}
|
||||||
@ -72,7 +72,7 @@
|
|||||||
{% endif -%}
|
{% endif -%}
|
||||||
<a class="post_subreddit" href="/{{ community }}">{{ community }}</a>
|
<a class="post_subreddit" href="/{{ community }}">{{ community }}</a>
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
<a class="post_author {{ post.author.distinguished }}" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||||
{% if !post.awards.is_empty() %}
|
{% if !post.awards.is_empty() %}
|
||||||
|
Reference in New Issue
Block a user