Add "open in reddit" button to all pages (#304)

* Pass the url parameter to all templates. Add a reddit_link to the navbar, which opens the current url on reddit.

* Add icon for reddit link

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
mikupls 2021-11-15 03:39:33 +01:00 committed by GitHub
parent 2486347b14
commit 0f7ba3c61d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 2 deletions

View file

@ -26,6 +26,7 @@ struct WikiTemplate {
wiki: String,
page: String,
prefs: Preferences,
url: String,
}
#[derive(Template)]
@ -239,6 +240,7 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
let page = req.param("page").unwrap_or_else(|| "index".to_string());
let path: String = format!("/r/{}/wiki/{}.json?raw_json=1", sub, page);
let url = req.uri().to_string();
match json(path, quarantined).await {
Ok(response) => template(WikiTemplate {
@ -246,6 +248,7 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
wiki: rewrite_urls(response["data"]["content_html"].as_str().unwrap_or("<h3>Wiki not found</h3>")),
page,
prefs: Preferences::new(req),
url: url,
}),
Err(msg) => {
if msg == "quarantined" {
@ -268,6 +271,7 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
// Build the Reddit JSON API url
let path: String = format!("/r/{}/about.json?raw_json=1", sub);
let url = req.uri().to_string();
// Send a request to the url
match json(path, quarantined).await {
@ -282,6 +286,7 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
sub,
page: "Sidebar".to_string(),
prefs: Preferences::new(req),
url: url,
}),
Err(msg) => {
if msg == "quarantined" {