Compare commits
44 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef3820a2e1 | |||
1678245750 | |||
3594b6d41f | |||
a754d42b9e | |||
c7e0234d33 | |||
11a9ff53e4 | |||
7b8f694c8c | |||
19dc7de3c5 | |||
cd29cfbf29 | |||
d0ec1fcc43 | |||
75bc170eba | |||
148d87fb45 | |||
5219c919af | |||
5bda103356 | |||
81274e35d7 | |||
e1962c7b66 | |||
528fe15819 | |||
8509f6e22d | |||
77886579f4 | |||
4f5ba35ddb | |||
c738300bc4 | |||
293a4d5c50 | |||
312d162c09 | |||
9f19d729d1 | |||
6794f7d6ba | |||
04310c58e0 | |||
6def67ddfe | |||
c33f7947b0 | |||
98d10d6596 | |||
863b512718 | |||
d6971bb9a3 | |||
fc98ca9af9 | |||
f33af75267 | |||
759c9fc66b | |||
9d78266494 | |||
9a6430656d | |||
8f157c0b40 | |||
3902a36ea3 | |||
9b049be627 | |||
3942388b25 | |||
74917c672f | |||
0b92868bfe | |||
b218ec6065 | |||
8a488af594 |
29
.github/workflows/rust.yml
vendored
Normal file
29
.github/workflows/rust.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Cache Packages
|
||||||
|
uses: Swatinem/rust-cache@v1.0.1
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2.2.1
|
||||||
|
name: Upload a Build Artifact
|
||||||
|
with:
|
||||||
|
name: libreddit
|
||||||
|
path: target/release/libreddit
|
985
Cargo.lock
generated
985
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@ -3,15 +3,21 @@ 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.1.6"
|
version = "0.2.1"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["proxy"]
|
||||||
|
proxy = ["actix-web/rustls", "base64"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "3.2.0", features = ["rustls"] }
|
base64 = { version = "0.13.0", optional = true }
|
||||||
surf = "2.1.0"
|
actix-web = "3.2.0"
|
||||||
|
reqwest = { version = "0.10", default_features = false, features = ["rustls-tls"] }
|
||||||
askama = "0.8.0"
|
askama = "0.8.0"
|
||||||
serde = "1.0.117"
|
serde = "1.0.117"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
pulldown-cmark = "0.8.0"
|
pulldown-cmark = "0.8.0"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
|
async-recursion = "0.3.1"
|
105
README.md
105
README.md
@ -7,68 +7,50 @@ Libre + Reddit = Libreddit
|
|||||||
- 🚀 Fast: written in Rust for blazing fast speeds and safety
|
- 🚀 Fast: written in Rust for blazing fast speeds and safety
|
||||||
- ☁️ Light: no javascript, no ads, no tracking
|
- ☁️ Light: no javascript, no ads, no tracking
|
||||||
- 🕵 Private: all requests are proxied through the server, including media
|
- 🕵 Private: all requests are proxied through the server, including media
|
||||||
- 🔒 Safe: does not rely on Reddit's OAuth-requiring APIs
|
- 🔒 Safe: does not rely on Reddit OAuth or require a Reddit API Key
|
||||||
- 📱 Responsive: works great on mobile!
|
- 📱 Responsive: works great on mobile!
|
||||||
|
|
||||||
Think Invidious but for Reddit. Watch your cat videos without being watched.
|
Think Invidious but for Reddit. Watch your cat videos without being watched.
|
||||||
|
|
||||||
## Screenshot
|
## Screenshot
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Status
|
## About
|
||||||
|
|
||||||
- [x] Hosting
|
### Elsewhere
|
||||||
- [x] Instances
|
Find Libreddit on...
|
||||||
- [x] Clearnet instance
|
- 💬 Matrix: [#libreddit:matrix.org](https://matrix.to/#/#libreddit:matrix.org)
|
||||||
- [ ] .onion instance
|
- 🐋 Docker: [spikecodes/libreddit](https://hub.docker.com/r/spikecodes/libreddit)
|
||||||
- [x] Cargo deployment
|
- :octocat: GitHub: [spikecodes/libreddit](https://github.com/spikecodes/libreddit)
|
||||||
- [x] Docker deployment
|
- 🦊 GitLab: [spikecodes/libreddit](https://gitlab.com/spikecodes/libreddit)
|
||||||
- [x] Subreddits
|
|
||||||
- [x] Title
|
|
||||||
- [x] Description
|
|
||||||
- [x] Posts
|
|
||||||
- [x] Post sorting
|
|
||||||
- [x] Posts
|
|
||||||
- [x] Flairs
|
|
||||||
- [x] Comments
|
|
||||||
- [x] Comment sorting
|
|
||||||
- [ ] Nested comments
|
|
||||||
- [x] UTC post date
|
|
||||||
- [x] Image thumbnails
|
|
||||||
- [x] Embedded images
|
|
||||||
- [x] Proxied images
|
|
||||||
- [x] Reddit-hosted video
|
|
||||||
- [x] Proxied video
|
|
||||||
- [x] Users
|
|
||||||
- [x] Username
|
|
||||||
- [x] Karma
|
|
||||||
- [x] Description
|
|
||||||
- [x] Post history
|
|
||||||
- [x] Comment history
|
|
||||||
|
|
||||||
- [ ] Search
|
### Info
|
||||||
- [ ] Post aggregating
|
Libreddit hopes to provide an easier way to browse Reddit, without the ads, trackers and bloat. Libreddit was inspired by other alternative front-ends to popular services such as [Invidious](https://github.com/iv-org/invidious) for YouTube, [Nitter](https://github.com/zedeus/nitter) for Twitter, and [Bibliogram](https://sr.ht/~cadence/bibliogram/) for Instagram.
|
||||||
- [ ] Comment aggregating
|
|
||||||
- [ ] Result sorting
|
Libreddit currently implements most of Reddit's functionalities but still lacks a few features that are being worked on below.
|
||||||
|
|
||||||
|
### In Progress
|
||||||
|
- Searching
|
||||||
|
- Multireddits
|
||||||
|
|
||||||
|
### How does it compare to Teddit?
|
||||||
|
|
||||||
|
Teddit is another awesome open source project designed to provide an alternative frontend to Reddit. There is no connection between the two and you're welcome to use whichever one you favor. Competition fosters innovation and Teddit's release has motivated me to build Libreddit into an even more polished product.
|
||||||
|
|
||||||
|
If you are looking to compare, the biggest differences I have noticed are:
|
||||||
|
- Libreddit is themed around Reddit's redesign whereas Teddit appears to stick much closer to Reddit's old design. This may suit some users better as design is always subjective.
|
||||||
|
- Libreddit is written in Rust for speed and memory safety. It uses Actix Web, which was [benchmarked as the fastest web server for single queries](https://www.techempower.com/benchmarks/#hw=ph&test=db).
|
||||||
|
- Unlike Teddit (at the time of writing this), Libreddit does not require a Reddit API key to host.
|
||||||
|
|
||||||
## Instances
|
## Instances
|
||||||
|
|
||||||
|
Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new) to have your selfhosted instance listed here!
|
||||||
|
|
||||||
- [libredd.it](https://libredd.it) 🇺🇸 (Thank you to [YeapGuy](https://github.com/YeapGuy)!)
|
- [libredd.it](https://libredd.it) 🇺🇸 (Thank you to [YeapGuy](https://github.com/YeapGuy)!)
|
||||||
- [libreddit.spike.codes](https://libreddit.spike.codes) 🇺🇸
|
- [libreddit.spike.codes](https://libreddit.spike.codes) 🇺🇸
|
||||||
|
|
||||||
## Deploy an Instance
|
## Installation
|
||||||
|
|
||||||
Once installed, deploy Libreddit (unless you're using Docker) by running:
|
|
||||||
|
|
||||||
```
|
|
||||||
libreddit
|
|
||||||
```
|
|
||||||
|
|
||||||
Specify a custom address for the server by passing the `-a` or `--address` argument:
|
|
||||||
```
|
|
||||||
libreddit --address=0.0.0.0:8111
|
|
||||||
```
|
|
||||||
|
|
||||||
### A) Cargo
|
### A) Cargo
|
||||||
|
|
||||||
@ -92,17 +74,40 @@ docker run -d --name libreddit -p 80:8080 spikecodes/libreddit
|
|||||||
|
|
||||||
### C) AUR
|
### C) AUR
|
||||||
|
|
||||||
Libreddit is available from the Arch User Repository as [`libreddit-git`](https://aur.archlinux.org/packages/libreddit-git).
|
For ArchLinux users, Libreddit is available from the AUR as [`libreddit-git`](https://aur.archlinux.org/packages/libreddit-git).
|
||||||
|
|
||||||
Install:
|
Install:
|
||||||
```
|
```
|
||||||
yay -S libreddit-git
|
yay -S libreddit-git
|
||||||
```
|
```
|
||||||
|
|
||||||
## Building
|
### D) GitHub Releases
|
||||||
|
|
||||||
|
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).
|
||||||
|
Currently Libreddit does not have Windows or MacOS binaries but those will be available soon.
|
||||||
|
|
||||||
|
## Deploy an Instance
|
||||||
|
|
||||||
|
Once installed, deploy Libreddit (unless you're using Docker) by running:
|
||||||
|
|
||||||
|
```
|
||||||
|
libreddit
|
||||||
|
```
|
||||||
|
|
||||||
|
Specify a custom address for the server by passing the `-a` or `--address` argument:
|
||||||
|
```
|
||||||
|
libreddit --address=0.0.0.0:8111
|
||||||
|
```
|
||||||
|
|
||||||
|
To disable the media proxy built into Libreddit, run:
|
||||||
|
```
|
||||||
|
libreddit --no-default-features
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building from Source
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/spikecodes/libreddit
|
git clone https://github.com/spikecodes/libreddit
|
||||||
cd libreddit
|
cd libreddit
|
||||||
cargo run
|
cargo run
|
||||||
```
|
```
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
tab_spaces = 2
|
tab_spaces = 2
|
||||||
hard_tabs = true
|
hard_tabs = true
|
||||||
max_width = 200
|
max_width = 175
|
50
src/main.rs
50
src/main.rs
@ -1,24 +1,21 @@
|
|||||||
// Import Crates
|
// Import Crates
|
||||||
use actix_web::{get, App, HttpResponse, HttpServer};
|
use actix_web::{get, middleware::NormalizePath, web, App, HttpResponse, HttpServer};
|
||||||
|
|
||||||
// Reference local files
|
// Reference local files
|
||||||
mod popular;
|
mod popular;
|
||||||
mod post;
|
mod post;
|
||||||
|
mod proxy;
|
||||||
mod subreddit;
|
mod subreddit;
|
||||||
mod user;
|
mod user;
|
||||||
mod proxy;
|
mod utils;
|
||||||
|
|
||||||
// Create Services
|
// Create Services
|
||||||
#[get("/style.css")]
|
|
||||||
async fn style() -> HttpResponse {
|
async fn style() -> HttpResponse {
|
||||||
let file = std::fs::read_to_string("static/style.css").expect("ERROR: Could not read style.css");
|
HttpResponse::Ok().content_type("text/css").body(include_str!("../static/style.css"))
|
||||||
HttpResponse::Ok().content_type("text/css").body(file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/robots.txt")]
|
|
||||||
async fn robots() -> HttpResponse {
|
async fn robots() -> HttpResponse {
|
||||||
let file = std::fs::read_to_string("static/robots.txt").expect("ERROR: Could not read robots.txt");
|
HttpResponse::Ok().body(include_str!("../static/robots.txt"))
|
||||||
HttpResponse::Ok().body(file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/favicon.ico")]
|
#[get("/favicon.ico")]
|
||||||
@ -32,32 +29,37 @@ async fn main() -> std::io::Result<()> {
|
|||||||
let mut address = "0.0.0.0:8080".to_string();
|
let mut address = "0.0.0.0:8080".to_string();
|
||||||
|
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
if args[1].starts_with("--address=") || args[1].starts_with("-a=") {
|
for arg in args {
|
||||||
let split: Vec<&str> = args[1].split("=").collect();
|
if arg.starts_with("--address=") || arg.starts_with("-a=") {
|
||||||
address = split[1].to_string();
|
let split: Vec<&str> = arg.split("=").collect();
|
||||||
|
address = split[1].to_string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// start http server
|
// start http server
|
||||||
println!("Running Libreddit on {}!", address.clone());
|
println!("Running Libreddit v{} on {}!", env!("CARGO_PKG_VERSION"), address.clone());
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
|
// TRAILING SLASH MIDDLEWARE
|
||||||
|
.wrap(NormalizePath::default())
|
||||||
// GENERAL SERVICES
|
// GENERAL SERVICES
|
||||||
.service(style)
|
.route("/style.css/", web::get().to(style))
|
||||||
.service(favicon)
|
.route("/favicon.ico/", web::get().to(|| HttpResponse::Ok()))
|
||||||
.service(robots)
|
.route("/robots.txt/", web::get().to(robots))
|
||||||
// PROXY SERVICE
|
// PROXY SERVICE
|
||||||
.service(proxy::handler)
|
.route("/proxy/{url:.*}/", web::get().to(proxy::handler))
|
||||||
// POST SERVICES
|
|
||||||
.service(post::short)
|
|
||||||
.service(post::page)
|
|
||||||
// SUBREDDIT SERVICES
|
|
||||||
.service(subreddit::page)
|
|
||||||
// POPULAR SERVICES
|
|
||||||
.service(popular::page)
|
|
||||||
// USER SERVICES
|
// USER SERVICES
|
||||||
.service(user::page)
|
.route("/u/{username}/", web::get().to(user::page))
|
||||||
|
.route("/user/{username}/", web::get().to(user::page))
|
||||||
|
// SUBREDDIT SERVICES
|
||||||
|
.route("/r/{sub}/", web::get().to(subreddit::page))
|
||||||
|
// POPULAR SERVICES
|
||||||
|
.route("/", web::get().to(popular::page))
|
||||||
|
// POST SERVICES
|
||||||
|
.route("/{id:.{5,6}}/", web::get().to(post::short))
|
||||||
|
.route("/r/{sub}/comments/{id}/{title}/", web::get().to(post::page))
|
||||||
})
|
})
|
||||||
.bind(address.clone())
|
.bind(address.clone())
|
||||||
.expect(format!("Cannot bind to the address: {}", address).as_str())
|
.expect(format!("Cannot bind to the address: {}", address).as_str())
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use actix_web::{get, web, HttpResponse, Result};
|
use crate::utils::{fetch_posts, ErrorTemplate, Params, Post};
|
||||||
|
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[path = "utils.rs"]
|
|
||||||
mod utils;
|
|
||||||
use utils::{fetch_posts, ErrorTemplate, Params, Post};
|
|
||||||
|
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "popular.html", escape = "none")]
|
#[template(path = "popular.html", escape = "none")]
|
||||||
@ -37,7 +34,7 @@ async fn render(sub_name: String, sort: Option<String>, ends: (Option<String>, O
|
|||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(HttpResponse::Ok().status(actix_web::http::StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
Ok(HttpResponse::Ok().status(StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
||||||
} else {
|
} else {
|
||||||
let items = items_result.unwrap();
|
let items = items_result.unwrap();
|
||||||
|
|
||||||
@ -53,7 +50,6 @@ async fn render(sub_name: String, sort: Option<String>, ends: (Option<String>, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
#[get("/")]
|
|
||||||
pub async fn page(params: web::Query<Params>) -> Result<HttpResponse> {
|
pub async fn page(params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
render("popular".to_string(), params.sort.clone(), (params.before.clone(), params.after.clone())).await
|
render("popular".to_string(), params.sort.clone(), (params.before.clone(), params.after.clone())).await
|
||||||
}
|
}
|
||||||
|
109
src/post.rs
109
src/post.rs
@ -1,13 +1,13 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use actix_web::{get, web, HttpResponse, Result};
|
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post};
|
||||||
|
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||||
|
|
||||||
|
use async_recursion::async_recursion;
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
use pulldown_cmark::{html, Options, Parser};
|
use pulldown_cmark::{html, Options, Parser};
|
||||||
|
|
||||||
#[path = "utils.rs"]
|
|
||||||
mod utils;
|
|
||||||
use utils::{request, val, Comment, ErrorTemplate, Flair, Params, Post};
|
|
||||||
|
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "post.html", escape = "none")]
|
#[template(path = "post.html", escape = "none")]
|
||||||
@ -17,12 +17,15 @@ struct PostTemplate {
|
|||||||
sort: String,
|
sort: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
async fn render(id: String, sort: Option<String>) -> Result<HttpResponse> {
|
||||||
// Log the post ID being fetched
|
// Log the post ID being fetched
|
||||||
println!("id: {}", id);
|
dbg!(&id);
|
||||||
|
|
||||||
|
// Handling sort paramater
|
||||||
|
let sorting: String = sort.unwrap_or("confidence".to_string());
|
||||||
|
|
||||||
// Build the Reddit JSON API url
|
// Build the Reddit JSON API url
|
||||||
let url: String = format!("https://reddit.com/{}.json?sort={}", id, sort);
|
let url: String = format!("https://reddit.com/{}.json?sort={}", id, sorting);
|
||||||
|
|
||||||
// Send a request to the url, receive JSON in response
|
// Send a request to the url, receive JSON in response
|
||||||
let req = request(url).await;
|
let req = request(url).await;
|
||||||
@ -34,21 +37,21 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
|||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return Ok(HttpResponse::Ok().status(actix_web::http::StatusCode::NOT_FOUND).content_type("text/html").body(s));
|
return Ok(HttpResponse::Ok().status(StatusCode::NOT_FOUND).content_type("text/html").body(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, grab the JSON output from the request
|
// Otherwise, grab the JSON output from the request
|
||||||
let res = req.unwrap();
|
let res = req.unwrap();
|
||||||
|
|
||||||
// Parse the JSON into Post and Comment structs
|
// Parse the JSON into Post and Comment structs
|
||||||
let post = parse_post(res.clone()).await;
|
let post = parse_post(res[0].clone()).await;
|
||||||
let comments = parse_comments(res).await;
|
let comments = parse_comments(res[1].clone()).await;
|
||||||
|
|
||||||
// Use the Post and Comment structs to generate a website to show users
|
// Use the Post and Comment structs to generate a website to show users
|
||||||
let s = PostTemplate {
|
let s = PostTemplate {
|
||||||
comments: comments.unwrap(),
|
comments: comments.unwrap(),
|
||||||
post: post.unwrap(),
|
post: post.unwrap(),
|
||||||
sort: sort,
|
sort: sorting,
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -56,39 +59,32 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
#[get("/{id}")]
|
pub async fn short(web::Path(id): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
async fn short(web::Path(id): web::Path<String>) -> Result<HttpResponse> {
|
render(id, params.sort.clone()).await
|
||||||
render(id.to_string(), "confidence".to_string()).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/r/{sub}/comments/{id}/{title}/")]
|
pub async fn page(web::Path((_sub, id)): web::Path<(String, String)>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
async fn page(web::Path((_sub, id)): web::Path<(String, String)>, params: web::Query<Params>) -> Result<HttpResponse> {
|
render(id, params.sort.clone()).await
|
||||||
match ¶ms.sort {
|
|
||||||
Some(sort) => render(id, sort.to_string()).await,
|
|
||||||
None => render(id, "confidence".to_string()).await,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTILITIES
|
// UTILITIES
|
||||||
async fn media(data: &serde_json::Value) -> String {
|
async fn media(data: &serde_json::Value) -> (String, String) {
|
||||||
let post_hint: &str = data["data"]["post_hint"].as_str().unwrap_or("");
|
let post_type: &str;
|
||||||
let has_media: bool = data["data"]["media"].is_object();
|
let url = if !data["preview"]["reddit_video_preview"]["fallback_url"].is_null() {
|
||||||
|
post_type = "video";
|
||||||
let media: String = if !has_media {
|
format_url(data["preview"]["reddit_video_preview"]["fallback_url"].as_str().unwrap()).await
|
||||||
format!(r#"<h4 class="post_body"><a href="{u}">{u}</a></h4>"#, u = data["data"]["url"].as_str().unwrap())
|
} else if !data["secure_media"]["reddit_video"]["fallback_url"].is_null() {
|
||||||
|
post_type = "video";
|
||||||
|
format_url(data["secure_media"]["reddit_video"]["fallback_url"].as_str().unwrap()).await
|
||||||
|
} else if data["post_hint"].as_str().unwrap_or("") == "image" {
|
||||||
|
post_type = "image";
|
||||||
|
format_url(data["preview"]["images"][0]["source"]["url"].as_str().unwrap()).await
|
||||||
} else {
|
} else {
|
||||||
format!(r#"<img class="post_image" src="/imageproxy/{}.png"/>"#, data["data"]["url"].as_str().unwrap())
|
post_type = "link";
|
||||||
|
data["url"].as_str().unwrap().to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
match post_hint {
|
(post_type.to_string(), url)
|
||||||
"hosted:video" => format!(
|
|
||||||
r#"<video class="post_image" src="/imageproxy/{}" controls/>"#,
|
|
||||||
data["data"]["media"]["reddit_video"]["fallback_url"].as_str().unwrap()
|
|
||||||
),
|
|
||||||
"image" => format!(r#"<img class="post_image" src="/imageproxy/{}"/>"#, data["data"]["url"].as_str().unwrap()),
|
|
||||||
"self" => String::from(""),
|
|
||||||
_ => media,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn markdown_to_html(md: &str) -> String {
|
async fn markdown_to_html(md: &str) -> String {
|
||||||
@ -107,19 +103,27 @@ async fn markdown_to_html(md: &str) -> String {
|
|||||||
|
|
||||||
// POSTS
|
// POSTS
|
||||||
async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
||||||
let post_data: &serde_json::Value = &json[0]["data"]["children"][0];
|
let post_data: &serde_json::Value = &json["data"]["children"][0];
|
||||||
|
|
||||||
let unix_time: i64 = post_data["data"]["created_utc"].as_f64().unwrap().round() as i64;
|
let unix_time: i64 = post_data["data"]["created_utc"].as_f64().unwrap().round() as i64;
|
||||||
let score = post_data["data"]["score"].as_i64().unwrap();
|
let score = post_data["data"]["score"].as_i64().unwrap();
|
||||||
|
|
||||||
|
let media = media(&post_data["data"]).await;
|
||||||
|
|
||||||
let post = Post {
|
let post = Post {
|
||||||
title: val(post_data, "title").await,
|
title: val(post_data, "title").await,
|
||||||
community: val(post_data, "subreddit").await,
|
community: val(post_data, "subreddit").await,
|
||||||
body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap()).await,
|
body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap()).await,
|
||||||
author: val(post_data, "author").await,
|
author: val(post_data, "author").await,
|
||||||
|
author_flair: Flair(
|
||||||
|
val(post_data, "author_flair_text").await,
|
||||||
|
val(post_data, "author_flair_background_color").await,
|
||||||
|
val(post_data, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
url: val(post_data, "permalink").await,
|
url: val(post_data, "permalink").await,
|
||||||
score: if score > 1000 { format!("{}k", score / 1000) } else { score.to_string() },
|
score: format_num(score),
|
||||||
media: media(post_data).await,
|
post_type: media.0,
|
||||||
|
media: media.1,
|
||||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||||
flair: Flair(
|
flair: Flair(
|
||||||
val(post_data, "link_flair_text").await,
|
val(post_data, "link_flair_text").await,
|
||||||
@ -129,30 +133,47 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
|||||||
} else {
|
} else {
|
||||||
"white".to_string()
|
"white".to_string()
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(post)
|
Ok(post)
|
||||||
}
|
}
|
||||||
|
|
||||||
// COMMENTS
|
// COMMENTS
|
||||||
|
#[async_recursion]
|
||||||
async fn parse_comments(json: serde_json::Value) -> Result<Vec<Comment>, &'static str> {
|
async fn parse_comments(json: serde_json::Value) -> Result<Vec<Comment>, &'static str> {
|
||||||
let comment_data = json[1]["data"]["children"].as_array().unwrap();
|
// Separate the comment JSON into a Vector of comments
|
||||||
|
let comment_data = json["data"]["children"].as_array().unwrap();
|
||||||
|
|
||||||
let mut comments: Vec<Comment> = Vec::new();
|
let mut comments: Vec<Comment> = Vec::new();
|
||||||
|
|
||||||
|
// For each comment, retrieve the values to build a Comment object
|
||||||
for comment in comment_data.iter() {
|
for comment in comment_data.iter() {
|
||||||
let unix_time: i64 = comment["data"]["created_utc"].as_f64().unwrap_or(0.0).round() as i64;
|
let unix_time: i64 = comment["data"]["created_utc"].as_f64().unwrap_or(0.0).round() as i64;
|
||||||
|
if unix_time == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let score = comment["data"]["score"].as_i64().unwrap_or(0);
|
let score = comment["data"]["score"].as_i64().unwrap_or(0);
|
||||||
let body = markdown_to_html(comment["data"]["body"].as_str().unwrap_or("")).await;
|
let body = markdown_to_html(comment["data"]["body"].as_str().unwrap_or("")).await;
|
||||||
|
|
||||||
// println!("{}", body);
|
let replies: Vec<Comment> = if comment["data"]["replies"].is_object() {
|
||||||
|
parse_comments(comment["data"]["replies"].clone()).await.unwrap_or(Vec::new())
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
|
||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
body: body,
|
body: body,
|
||||||
author: val(comment, "author").await,
|
author: val(comment, "author").await,
|
||||||
score: if score > 1000 { format!("{}k", score / 1000) } else { score.to_string() },
|
score: format_num(score),
|
||||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||||
|
replies: replies,
|
||||||
|
flair: Flair(
|
||||||
|
val(comment, "author_flair_text").await,
|
||||||
|
val(comment, "author_flair_background_color").await,
|
||||||
|
val(comment, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
src/proxy.rs
41
src/proxy.rs
@ -1,14 +1,29 @@
|
|||||||
use actix_web::{get, web, HttpResponse, Result, client::Client, Error};
|
use actix_web::{client::Client, web, Error, HttpResponse, Result};
|
||||||
|
|
||||||
#[get("/imageproxy/{url:.*}")]
|
#[cfg(feature = "proxy")]
|
||||||
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
use base64::decode;
|
||||||
dbg!(&url);
|
|
||||||
let client = Client::default();
|
pub async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
||||||
client.get(url)
|
if cfg!(feature = "proxy") {
|
||||||
.send()
|
let media: String;
|
||||||
.await
|
|
||||||
.map_err(Error::from)
|
#[cfg(not(feature = "proxy"))]
|
||||||
.and_then(|res| {
|
let media = url;
|
||||||
Ok(HttpResponse::build(res.status()).streaming(res))
|
|
||||||
})
|
#[cfg(feature = "proxy")]
|
||||||
}
|
match decode(url) {
|
||||||
|
Ok(bytes) => media = String::from_utf8(bytes).unwrap(),
|
||||||
|
Err(_e) => return Ok(HttpResponse::Ok().body("")),
|
||||||
|
};
|
||||||
|
|
||||||
|
let client = Client::default();
|
||||||
|
client
|
||||||
|
.get(media.replace("&", "&"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(Error::from)
|
||||||
|
.and_then(|res| Ok(HttpResponse::build(res.status()).streaming(res)))
|
||||||
|
} else {
|
||||||
|
Ok(HttpResponse::Ok().body(""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use actix_web::{get, web, HttpResponse, Result};
|
use crate::utils::{fetch_posts, format_num, format_url, request, val, ErrorTemplate, Params, Post, Subreddit};
|
||||||
|
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
use std::convert::TryInto;
|
||||||
#[path = "utils.rs"]
|
|
||||||
mod utils;
|
|
||||||
pub use utils::{request, val, fetch_posts, ErrorTemplate, Flair, Params, Post, Subreddit};
|
|
||||||
|
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
@ -13,13 +11,12 @@ struct SubredditTemplate {
|
|||||||
sub: Subreddit,
|
sub: Subreddit,
|
||||||
posts: Vec<Post>,
|
posts: Vec<Post>,
|
||||||
sort: String,
|
sort: String,
|
||||||
ends: (String, String)
|
ends: (String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[get("/r/{sub}")]
|
pub async fn page(web::Path(sub): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
async fn page(web::Path(sub): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
|
||||||
render(sub, params.sort.clone(), (params.before.clone(), params.after.clone())).await
|
render(sub, params.sort.clone(), (params.before.clone(), params.after.clone())).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +42,7 @@ pub async fn render(sub_name: String, sort: Option<String>, ends: (Option<String
|
|||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(HttpResponse::Ok().status(actix_web::http::StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
Ok(HttpResponse::Ok().status(StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
||||||
} else {
|
} else {
|
||||||
let mut sub = sub_result.unwrap();
|
let mut sub = sub_result.unwrap();
|
||||||
let items = items_result.unwrap();
|
let items = items_result.unwrap();
|
||||||
@ -60,7 +57,7 @@ pub async fn render(sub_name: String, sort: Option<String>, ends: (Option<String
|
|||||||
sub: sub,
|
sub: sub,
|
||||||
posts: items.0,
|
posts: items.0,
|
||||||
sort: sorting,
|
sort: sorting,
|
||||||
ends: (before, items.1)
|
ends: (before, items.1),
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -85,16 +82,16 @@ async fn subreddit(sub: &String) -> Result<Subreddit, &'static str> {
|
|||||||
let res = req.unwrap();
|
let res = req.unwrap();
|
||||||
|
|
||||||
let members = res["data"]["subscribers"].as_u64().unwrap_or(0);
|
let members = res["data"]["subscribers"].as_u64().unwrap_or(0);
|
||||||
let active = res["data"]["accounts_active"].as_u64().unwrap_or(0);
|
let active = res["data"]["accounts_active"].as_u64().unwrap_or(0);
|
||||||
|
|
||||||
let sub = Subreddit {
|
let sub = Subreddit {
|
||||||
name: val(&res, "display_name").await,
|
name: val(&res, "display_name").await,
|
||||||
title: val(&res, "title").await,
|
title: val(&res, "title").await,
|
||||||
description: val(&res, "public_description").await,
|
description: val(&res, "public_description").await,
|
||||||
icon: val(&res, "icon_img").await,
|
icon: format_url(val(&res, "icon_img").await.as_str()).await,
|
||||||
members: if members > 1000 { format!("{}k", members / 1000) } else { members.to_string() },
|
members: format_num(members.try_into().unwrap()),
|
||||||
active: if active > 1000 { format!("{}k", active / 1000) } else { active.to_string() },
|
active: format_num(active.try_into().unwrap()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(sub)
|
Ok(sub)
|
||||||
}
|
}
|
||||||
|
14
src/user.rs
14
src/user.rs
@ -1,11 +1,8 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use actix_web::{get, web, HttpResponse, Result};
|
use crate::utils::{fetch_posts, nested_val, request, ErrorTemplate, Params, Post, User};
|
||||||
|
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[path = "utils.rs"]
|
|
||||||
mod utils;
|
|
||||||
use utils::{nested_val, request, fetch_posts, ErrorTemplate, Params, Post, User};
|
|
||||||
|
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "user.html", escape = "none")]
|
#[template(path = "user.html", escape = "none")]
|
||||||
@ -28,7 +25,7 @@ async fn render(username: String, sort: String) -> Result<HttpResponse> {
|
|||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(HttpResponse::Ok().status(actix_web::http::StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
Ok(HttpResponse::Ok().status(StatusCode::NOT_FOUND).content_type("text/html").body(s))
|
||||||
} else {
|
} else {
|
||||||
let s = UserTemplate {
|
let s = UserTemplate {
|
||||||
user: user.unwrap(),
|
user: user.unwrap(),
|
||||||
@ -42,8 +39,7 @@ async fn render(username: String, sort: String) -> Result<HttpResponse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
#[get("/u/{username}")]
|
pub async fn page(web::Path(username): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
async fn page(web::Path(username): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
|
||||||
match ¶ms.sort {
|
match ¶ms.sort {
|
||||||
Some(sort) => render(username, sort.to_string()).await,
|
Some(sort) => render(username, sort.to_string()).await,
|
||||||
None => render(username, "hot".to_string()).await,
|
None => render(username, "hot".to_string()).await,
|
||||||
@ -74,4 +70,4 @@ async fn user(name: &String) -> Result<User, &'static str> {
|
|||||||
banner: nested_val(&res, "subreddit", "banner_img").await,
|
banner: nested_val(&res, "subreddit", "banner_img").await,
|
||||||
description: nested_val(&res, "subreddit", "public_description").await,
|
description: nested_val(&res, "subreddit", "public_description").await,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
79
src/utils.rs
79
src/utils.rs
@ -2,6 +2,11 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
//
|
//
|
||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
|
use serde_json::{from_str, Value};
|
||||||
|
// use surf::{client, get, middleware::Redirect};
|
||||||
|
|
||||||
|
#[cfg(feature = "proxy")]
|
||||||
|
use base64::encode;
|
||||||
|
|
||||||
//
|
//
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
@ -17,11 +22,13 @@ pub struct Post {
|
|||||||
pub community: String,
|
pub community: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
pub author_flair: Flair,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
|
pub post_type: String,
|
||||||
pub media: String,
|
pub media: String,
|
||||||
pub time: String,
|
pub time: String,
|
||||||
pub flair: Flair
|
pub flair: Flair,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -29,8 +36,10 @@ pub struct Post {
|
|||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
pub flair: Flair,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub time: String
|
pub time: String,
|
||||||
|
pub replies: Vec<Comment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -40,7 +49,7 @@ pub struct User {
|
|||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub karma: i64,
|
pub karma: i64,
|
||||||
pub banner: String,
|
pub banner: String,
|
||||||
pub description: String
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -51,7 +60,7 @@ pub struct Subreddit {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub members: String,
|
pub members: String,
|
||||||
pub active: String
|
pub active: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser for query params, used in sorting (eg. /r/rust/?sort=hot)
|
// Parser for query params, used in sorting (eg. /r/rust/?sort=hot)
|
||||||
@ -59,14 +68,36 @@ pub struct Subreddit {
|
|||||||
pub struct Params {
|
pub struct Params {
|
||||||
pub sort: Option<String>,
|
pub sort: Option<String>,
|
||||||
pub after: Option<String>,
|
pub after: Option<String>,
|
||||||
pub before: Option<String>
|
pub before: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error template
|
// Error template
|
||||||
#[derive(askama::Template)]
|
#[derive(askama::Template)]
|
||||||
#[template(path = "error.html", escape = "none")]
|
#[template(path = "error.html", escape = "none")]
|
||||||
pub struct ErrorTemplate {
|
pub struct ErrorTemplate {
|
||||||
pub message: String
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// FORMATTING
|
||||||
|
//
|
||||||
|
|
||||||
|
pub async fn format_url(url: &str) -> String {
|
||||||
|
#[cfg(feature = "proxy")]
|
||||||
|
return "/proxy/".to_string() + encode(url).as_str();
|
||||||
|
|
||||||
|
#[cfg(not(feature = "proxy"))]
|
||||||
|
return url.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_num(num: i64) -> String {
|
||||||
|
if num > 1000000 {
|
||||||
|
format!("{}m", num / 1000000)
|
||||||
|
} else if num > 1000 {
|
||||||
|
format!("{}k", num / 1000)
|
||||||
|
} else {
|
||||||
|
num.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -105,7 +136,7 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
|||||||
|
|
||||||
for post in post_list.iter() {
|
for post in post_list.iter() {
|
||||||
let img = if val(post, "thumbnail").await.starts_with("https:/") {
|
let img = if val(post, "thumbnail").await.starts_with("https:/") {
|
||||||
val(post, "thumbnail").await
|
format_url(val(post, "thumbnail").await.as_str()).await
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
@ -118,7 +149,13 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
|||||||
community: val(post, "subreddit").await,
|
community: val(post, "subreddit").await,
|
||||||
body: val(post, "body").await,
|
body: val(post, "body").await,
|
||||||
author: val(post, "author").await,
|
author: val(post, "author").await,
|
||||||
score: if score > 1000 { format!("{}k", score / 1000) } else { score.to_string() },
|
author_flair: Flair(
|
||||||
|
val(post, "author_flair_text").await,
|
||||||
|
val(post, "author_flair_background_color").await,
|
||||||
|
val(post, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
|
score: format_num(score),
|
||||||
|
post_type: "link".to_string(),
|
||||||
media: img,
|
media: img,
|
||||||
url: val(post, "permalink").await,
|
url: val(post, "permalink").await,
|
||||||
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
||||||
@ -157,28 +194,26 @@ pub async fn request(url: String) -> Result<serde_json::Value, &'static str> {
|
|||||||
// let body = std::str::from_utf8(res.as_ref())?; // .as_ref converts Bytes to [u8]
|
// let body = std::str::from_utf8(res.as_ref())?; // .as_ref converts Bytes to [u8]
|
||||||
|
|
||||||
// --- surf ---
|
// --- surf ---
|
||||||
let req = surf::get(&url).header("User-Agent", "libreddit");
|
// let req = get(&url).header("User-Agent", "libreddit");
|
||||||
let client = surf::client().with(surf::middleware::Redirect::new(5));
|
// let client = client().with(Redirect::new(5));
|
||||||
let mut res = client.send(req).await.unwrap();
|
// let mut res = client.send(req).await.unwrap();
|
||||||
let success = res.status().is_success();
|
// let success = res.status().is_success();
|
||||||
let body = res.body_string().await.unwrap();
|
// let body = res.body_string().await.unwrap();
|
||||||
|
|
||||||
dbg!(url.clone());
|
|
||||||
|
|
||||||
// --- reqwest ---
|
// --- reqwest ---
|
||||||
// let res = reqwest::get(&url).await.unwrap();
|
let res = reqwest::get(&url).await.unwrap();
|
||||||
// // Read the status from the response
|
// Read the status from the response
|
||||||
// let success = res.status().is_success();
|
let success = res.status().is_success();
|
||||||
// // Read the body of the response
|
// Read the body of the response
|
||||||
// let body = res.text().await.unwrap();
|
let body = res.text().await.unwrap();
|
||||||
|
|
||||||
// Parse the response from Reddit as JSON
|
// Parse the response from Reddit as JSON
|
||||||
let json: serde_json::Value = serde_json::from_str(body.as_str()).unwrap_or(serde_json::Value::Null);
|
let json: Value = from_str(body.as_str()).unwrap_or(Value::Null);
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
println!("! {} - {}", url, "Page not found");
|
println!("! {} - {}", url, "Page not found");
|
||||||
Err("Page not found")
|
Err("Page not found")
|
||||||
} else if json == serde_json::Value::Null {
|
} else if json == Value::Null {
|
||||||
println!("! {} - {}", url, "Failed to parse page JSON data");
|
println!("! {} - {}", url, "Failed to parse page JSON data");
|
||||||
Err("Failed to parse page JSON data")
|
Err("Failed to parse page JSON data")
|
||||||
} else {
|
} else {
|
||||||
|
202
static/style.css
202
static/style.css
@ -1,5 +1,14 @@
|
|||||||
/* General */
|
/* General */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--background: #0F0F0F;
|
||||||
|
--foreground: #222;
|
||||||
|
--outside: #1F1F1F;
|
||||||
|
--post: #161616;
|
||||||
|
--highlighted: #333;
|
||||||
|
--black-contrast: 0 1px 3px rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
transition: 0.2s all;
|
transition: 0.2s all;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
@ -8,15 +17,15 @@
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
body {
|
||||||
background: black;
|
background: var(--background);
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
color: aqua;
|
color: aqua;
|
||||||
background: #151515;
|
background: var(--outside);
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
@ -53,12 +62,14 @@ a:not(.post_right):hover {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
#about {
|
||||||
color: aqua;
|
padding-top: 20px;
|
||||||
|
background: #151515;
|
||||||
}
|
}
|
||||||
|
|
||||||
#about {
|
#version {
|
||||||
background: #151515;
|
color: white;
|
||||||
|
opacity: 25%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Subreddit */
|
/* Subreddit */
|
||||||
@ -123,7 +134,8 @@ span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#sort > div, footer > a {
|
#sort > div, footer > a {
|
||||||
background: #151515;
|
box-shadow: var(--black-contrast);
|
||||||
|
background: var(--outside);
|
||||||
color: lightgrey;
|
color: lightgrey;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
@ -138,32 +150,24 @@ span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#sort > div:hover {
|
#sort > div:hover {
|
||||||
background: #222;
|
background: var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Post */
|
/* Post */
|
||||||
|
|
||||||
.post {
|
.post {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
background: #151515;
|
background: var(--post);
|
||||||
|
box-shadow: var(--black-contrast);
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post.highlighted {
|
|
||||||
border: 2px solid #555;
|
|
||||||
background: #222;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post.highlighted > .post_left {
|
|
||||||
background: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post:hover {
|
.post:hover {
|
||||||
background: #222;
|
background: var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post:hover > .post_left {
|
.post:hover > .post_left {
|
||||||
background: #333;
|
background: var(--highlighted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_left, .post_right {
|
.post_left, .post_right {
|
||||||
@ -174,26 +178,18 @@ span {
|
|||||||
|
|
||||||
.post_left {
|
.post_left {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background: #222;
|
background: var(--foreground);
|
||||||
border-radius: 5px 0px 0px 5px;
|
border-radius: 5px 0px 0px 5px;
|
||||||
min-width: 50px;
|
min-width: 50px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_right > p > span, .comment_right > p > span {
|
.post_subreddit {
|
||||||
float: right;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_title {
|
.post_title {
|
||||||
font-size: 20px;
|
font-size: 18px;
|
||||||
}
|
|
||||||
|
|
||||||
.post_upvote {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post_subreddit {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_score {
|
.post_score {
|
||||||
@ -213,14 +209,15 @@ span {
|
|||||||
|
|
||||||
.post_right > p {
|
.post_right > p {
|
||||||
opacity: 0.75;
|
opacity: 0.75;
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_image {
|
.post_media {
|
||||||
max-width: 500px;
|
max-width: 90%;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_image[src=""] {
|
.post_media[src=""] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,37 +236,40 @@ span {
|
|||||||
color: aqua;
|
color: aqua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#post_url {
|
||||||
|
color: aqua;
|
||||||
|
}
|
||||||
|
|
||||||
.post_thumbnail {
|
.post_thumbnail {
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
width: auto;
|
width: auto;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
|
max-width: 20%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_thumbnail[src=""] {
|
.post_thumbnail[src=""] {
|
||||||
border: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
small {
|
.post_flair {
|
||||||
background: aqua;
|
background: aqua;
|
||||||
color: black;
|
color: black;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 5px;
|
margin-right: 5px;
|
||||||
font-size: 12px;
|
border-radius: 5px;
|
||||||
font-weight: bold;
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Comment */
|
/* Comment */
|
||||||
|
|
||||||
.comment {
|
.comment {
|
||||||
|
margin-top: 1em;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
display: flex;
|
display: flex;
|
||||||
border: 2px solid #222;
|
font-size: 15px;
|
||||||
}
|
|
||||||
|
|
||||||
.comment:hover {
|
|
||||||
background: #111;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_left, .comment_right {
|
.comment_left, .comment_right {
|
||||||
@ -280,18 +280,32 @@ small {
|
|||||||
.comment_left {
|
.comment_left {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
min-width: 50px;
|
min-width: 50px;
|
||||||
padding: 5px;
|
padding: 5px 0px;
|
||||||
align-items: flex-end;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_title {
|
.comment_title {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comment_author {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.author_flair {
|
||||||
|
background: var(--highlighted);
|
||||||
|
color: white;
|
||||||
|
padding: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
.comment_upvote {
|
.comment_upvote {
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
border-radius: 5px 5px 0px 0px;
|
border-radius: 5px 5px 0px 0px;
|
||||||
background: #222;
|
background: var(--foreground);
|
||||||
width: 40px;
|
width: 40px;
|
||||||
padding: 10px 0px 0px 0px;
|
padding: 10px 0px 0px 0px;
|
||||||
}
|
}
|
||||||
@ -302,27 +316,23 @@ small {
|
|||||||
|
|
||||||
.comment_score {
|
.comment_score {
|
||||||
color: aqua;
|
color: aqua;
|
||||||
background: #222;
|
background: var(--foreground);
|
||||||
width: 40px;
|
min-width: 40px;
|
||||||
padding: 5px 0px 10px 0px;
|
border-radius: 5px;
|
||||||
border-radius: 0px 0px 5px 5px;
|
padding: 10px 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_right {
|
.comment_right {
|
||||||
word-wrap: anywhere;
|
word-wrap: anywhere;
|
||||||
padding: 10px 25px 10px 10px;
|
padding: 10px 25px 10px 5px;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_right > * {
|
.comment_data > * {
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_right > p {
|
|
||||||
opacity: 0.75;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment_image {
|
.comment_image {
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
@ -347,23 +357,85 @@ small {
|
|||||||
color: aqua;
|
color: aqua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::marker {
|
||||||
|
color: aqua;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-left: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.datetime {
|
||||||
|
opacity: 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
width: 2px;
|
||||||
|
height: 100%;
|
||||||
|
background: var(--foreground);
|
||||||
|
}
|
||||||
|
|
||||||
.post.comment {
|
.post.comment {
|
||||||
background: #000;
|
background: #000;
|
||||||
border: 2px solid #222;
|
border: 2px solid var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post.comment > .post_left {
|
.post.comment > .post_left {
|
||||||
background: black;
|
background: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Code */
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background: var(--outside);
|
||||||
|
padding: 20px;
|
||||||
|
margin-top: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-shadow: var(--black-contrast);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Tables */
|
/* Tables */
|
||||||
|
|
||||||
table {
|
table {
|
||||||
border: 3px #333 solid;
|
border: 3px var(--highlighted) solid;
|
||||||
border-spacing: 0rem;
|
border-spacing: 0rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
td, th {
|
td, th {
|
||||||
border: 1px #333 solid;
|
border: 1px var(--highlighted) solid;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile */
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
.post {
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post_left {
|
||||||
|
border-radius: 0px 0px 5px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post_right {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post_score {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post_thumbnail {
|
||||||
|
max-width: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.datetime {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,7 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline';">
|
||||||
<meta name="description" content="View on Libreddit, an alternative private front-end to Reddit.">
|
<meta name="description" content="View on Libreddit, an alternative private front-end to Reddit.">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
{% block sortstyle %}
|
{% block sortstyle %}
|
||||||
@ -17,14 +19,14 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block body %}
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<header>
|
<header>
|
||||||
<a href="/"><span id="lib">lib</span>reddit.</a>
|
<a href="/"><span id="lib">lib</span>reddit. <span id="version">v{{ env!("CARGO_PKG_VERSION") }}</span></a>
|
||||||
<a id="github" href="https://github.com/spikecodes/libreddit">GITHUB</a>
|
<a id="github" href="https://github.com/spikecodes/libreddit">GITHUB</a>
|
||||||
</header>
|
</header>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
<main>
|
<main>
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -5,25 +5,25 @@
|
|||||||
<div id="sort_hot"><a href="?sort=hot">Hot</a></div>
|
<div id="sort_hot"><a href="?sort=hot">Hot</a></div>
|
||||||
<div id="sort_top"><a href="?sort=top">Top</a></div>
|
<div id="sort_top"><a href="?sort=top">Top</a></div>
|
||||||
<div id="sort_new"><a href="?sort=new">New</a></div>
|
<div id="sort_new"><a href="?sort=new">New</a></div>
|
||||||
|
<div id="sort_rising"><a href="?sort=rising">Rising</a></div>
|
||||||
</div>
|
</div>
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<button class="post_upvote">↑</button>
|
|
||||||
<h3 class="post_score">{{ post.score }}</h3>
|
<h3 class="post_score">{{ post.score }}</h3>
|
||||||
<button class="post_upvote">↓</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
<span style="float: right;">{{ post.time }}</span>
|
{% endif %}
|
||||||
</p>
|
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
||||||
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
@ -41,4 +41,4 @@
|
|||||||
<a href="?after={{ ends.1 }}">NEXT</a>
|
<a href="?after={{ ends.1 }}">NEXT</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</footer>
|
</footer>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -4,28 +4,54 @@
|
|||||||
{% call super() %}
|
{% call super() %}
|
||||||
<meta name="author" content="u/{{ post.author }}">
|
<meta name="author" content="u/{{ post.author }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% macro comment(item) -%}
|
||||||
|
|
||||||
|
<div class="comment">
|
||||||
|
<div class="comment_left">
|
||||||
|
<h3 class="comment_score">{{ item.score }}</h3>
|
||||||
|
<div class="line"></div>
|
||||||
|
</div>
|
||||||
|
<details class="comment_right" open>
|
||||||
|
<summary class="comment_data">
|
||||||
|
<a class="comment_author" href="/u/{{ item.author }}">u/{{ item.author }}</a>
|
||||||
|
{% if item.flair.0 != "" %}
|
||||||
|
<small class="author_flair">{{ item.flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
|
• <span class="datetime">{{ item.time }}</span>
|
||||||
|
</summary>
|
||||||
|
<h4 class="comment_body">{{ item.body }}</h4>
|
||||||
|
|
||||||
|
{%- endmacro %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="post highlighted">
|
<div class="post highlighted">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<button class="post_upvote">↑</button>
|
|
||||||
<h3 class="post_score">{{ post.score }}</h3>
|
<h3 class="post_score">{{ post.score }}</h3>
|
||||||
<button class="post_upvote">↓</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
•
|
||||||
Posted by
|
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
<span>{{ post.time }}</span>
|
{% if post.author_flair.0 != "" %}
|
||||||
</p>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
<h3 class="post_title">
|
{% endif %}
|
||||||
|
<span class="datetime">{{ post.time }}</span>
|
||||||
|
</h4>
|
||||||
|
<a href="{{ post.url }}" class="post_title">
|
||||||
{{ post.title }}
|
{{ post.title }}
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h3>
|
</a>
|
||||||
{{ post.media }}
|
{% if post.post_type == "image" %}
|
||||||
|
<img class="post_media" src="{{ post.media }}"/>
|
||||||
|
{% else if post.post_type == "video" %}
|
||||||
|
<video class="post_media" src="{{ post.media }}" controls autoplay loop>
|
||||||
|
{% else if post.post_type == "link" %}
|
||||||
|
<a id="post_url" href="{{ post.media }}">{{ post.media }}</a>
|
||||||
|
{% endif %}
|
||||||
<h4 class="post_body">{{ post.body }}</h4>
|
<h4 class="post_body">{{ post.body }}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -36,19 +62,21 @@
|
|||||||
<div id="sort_controversial"><a href="?sort=controversial">Controversial</a></div>
|
<div id="sort_controversial"><a href="?sort=controversial">Controversial</a></div>
|
||||||
<div id="sort_old"><a href="?sort=old">Old</a></div>
|
<div id="sort_old"><a href="?sort=old">Old</a></div>
|
||||||
</div>
|
</div>
|
||||||
{% for comment in comments %}
|
|
||||||
<div class="comment">
|
{% for c in comments -%}
|
||||||
<div class="comment_left">
|
<div class="thread">
|
||||||
<button class="comment_upvote">↑</button>
|
{% call comment(c) %}
|
||||||
<h3 class="comment_score">{{ comment.score }}</h3>
|
<div class="replies">
|
||||||
|
{% for reply in c.replies %}
|
||||||
|
{% call comment(reply) %}
|
||||||
|
<div class="replies">
|
||||||
|
{% for response in reply.replies %}
|
||||||
|
{% call comment(response) %}</details></div>
|
||||||
|
{% endfor %}
|
||||||
|
</div></details></div>
|
||||||
|
{% endfor %}
|
||||||
|
</div></details></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment_right">
|
{%- endfor %}
|
||||||
<p>
|
|
||||||
Posted by <a class="comment_author" href="/u/{{ comment.author }}">u/{{ comment.author }}</a>
|
|
||||||
<span>{{ comment.time }}</span>
|
|
||||||
</p>
|
|
||||||
<h4 class="comment_body">{{ comment.body }}</h4>
|
|
||||||
</div>
|
|
||||||
</div><br>
|
|
||||||
{% endfor %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -1,12 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block title %}r/{{ sub.name }}: {{ sub.description }}{% endblock %}
|
{% block title %}r/{{ sub.name }}: {{ sub.description }}{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% block header %}
|
|
||||||
<header>
|
|
||||||
<a href="/"><span id="lib">lib</span>reddit.</a>
|
|
||||||
<a id="github" href="https://github.com/spikecodes/libreddit">GITHUB</a>
|
|
||||||
</header>
|
|
||||||
{% endblock %}
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<div class="subreddit">
|
<div class="subreddit">
|
||||||
<div class="subreddit_left">
|
<div class="subreddit_left">
|
||||||
@ -28,21 +22,20 @@
|
|||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<button class="post_upvote">↑</button>
|
|
||||||
<h3 class="post_score">{{ post.score }}</h3>
|
<h3 class="post_score">{{ post.score }}</h3>
|
||||||
<button class="post_upvote">↓</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ sub.name }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ sub.name }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
<span>{{ post.time }}</span>
|
{% endif %}
|
||||||
</p>
|
<span class="datetime">{{ post.time }}</span>
|
||||||
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block title %}Libreddit: u/{{ user.name }}{% endblock %}
|
{% block title %}Libreddit: u/{{ user.name }}{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% block header %}
|
|
||||||
<header>
|
|
||||||
<a href="/"><span id="lib">lib</span>reddit.</a>
|
|
||||||
<a id="github" href="https://github.com/spikecodes/libreddit">GITHUB</a>
|
|
||||||
</header>
|
|
||||||
{% endblock %}
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<div class="user">
|
<div class="user">
|
||||||
<div class="user_left">
|
<div class="user_left">
|
||||||
@ -28,23 +22,22 @@
|
|||||||
{% if post.title != "Comment" %}
|
{% if post.title != "Comment" %}
|
||||||
<div class='post'>
|
<div class='post'>
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<button class="post_upvote">↑</button>
|
|
||||||
<h3 class="post_score">{{ post.score }}</h3>
|
<h3 class="post_score">{{ post.score }}</h3>
|
||||||
<button class="post_upvote">↓</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
<span style="float: right;">{{ post.time }}</span>
|
{% endif %}
|
||||||
</p>
|
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
||||||
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 == "Comment" %}
|
{% if post.flair.0 == "Comment" %}
|
||||||
{% else if post.flair.0 == "" %}
|
{% else if post.flair.0 == "" %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
@ -54,14 +47,13 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="comment">
|
<div class="comment">
|
||||||
<div class="comment_left">
|
<div class="comment_left">
|
||||||
<button class="comment_upvote">↑</button>
|
|
||||||
<h3 class="comment_score">{{ post.score }}</h3>
|
<h3 class="comment_score">{{ post.score }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment_right">
|
<div class="comment_right">
|
||||||
<p>
|
<h4>
|
||||||
COMMENT
|
COMMENT
|
||||||
<span>{{ post.time }}</span>
|
<span class="datetime">{{ post.time }}</span>
|
||||||
</p>
|
</h4>
|
||||||
<h4 class="comment_body">{{ post.body }}</h4>
|
<h4 class="comment_body">{{ post.body }}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div><br>
|
</div><br>
|
||||||
|
Reference in New Issue
Block a user