Compare commits
16 Commits
a0135f0f9a
...
54c2ffad95
Author | SHA1 | Date | |
---|---|---|---|
54c2ffad95 | |||
6991fc6ae3 | |||
30b27aea44 | |||
63e2fadf4a | |||
4ba26285d7 | |||
|
7c87d63d34 | ||
|
75b139dff2 | ||
|
10499df423 | ||
|
c86ca16c1a | ||
|
858299c861 | ||
|
75f5c6668c | ||
|
e6b9a2e426 | ||
|
d4a2b3edc6 | ||
|
4f0b29f930 | ||
|
4e2648280d | ||
|
35ae71302f |
@ -9,7 +9,7 @@ REDLIB_BANNER=
|
||||
# Disable search engine indexing
|
||||
REDLIB_ROBOTS_DISABLE_INDEXING=off
|
||||
# Set the Pushshift frontend for "removed" links
|
||||
REDLIB_PUSHSHIFT_FRONTEND=www.unddit.com
|
||||
REDLIB_PUSHSHIFT_FRONTEND=undelete.pullpush.io
|
||||
|
||||
# Default user settings
|
||||
# Set the default theme (options: system, light, dark, black, dracula, nord, laserwave, violet, gold, rosebox, gruvboxdark, gruvboxlight)
|
||||
|
22
Dockerfile
22
Dockerfile
@ -1,16 +1,28 @@
|
||||
FROM alpine:3.19
|
||||
FROM rust:1.77.1-buster AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./ ./
|
||||
|
||||
RUN cargo build --release
|
||||
|
||||
FROM debian:stable
|
||||
|
||||
ARG TARGET
|
||||
|
||||
RUN apk add --no-cache curl
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y ca-certificates wget
|
||||
|
||||
RUN curl -L https://github.com/redlib-org/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \
|
||||
tar xz -C /usr/local/bin/
|
||||
RUN apt-get clean -y; \
|
||||
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
|
||||
|
||||
COPY --from=builder /app/target/release/ /usr/local/bin
|
||||
|
||||
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
|
||||
|
||||
USER redlib
|
||||
|
||||
# Tell Docker to expose port 8080
|
||||
# Tell Docker to expose port 808
|
||||
EXPOSE 8080
|
||||
|
||||
# Run a healthcheck every minute to make sure redlib is functional
|
||||
|
20
Dockerfile.old
Normal file
20
Dockerfile.old
Normal file
@ -0,0 +1,20 @@
|
||||
FROM alpine:3.19
|
||||
|
||||
ARG TARGET
|
||||
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
RUN curl -L https://github.com/redlib-org/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \
|
||||
tar xz -C /usr/local/bin/
|
||||
|
||||
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
|
||||
USER redlib
|
||||
|
||||
# Tell Docker to expose port 8080
|
||||
EXPOSE 8080
|
||||
|
||||
# Run a healthcheck every minute to make sure redlib is functional
|
||||
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1
|
||||
|
||||
CMD ["redlib"]
|
||||
|
@ -385,7 +385,7 @@ Assign a default value for each instance-specific setting by passing environment
|
||||
| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. |
|
||||
| `BANNER` | String | (empty) | Allows the server to set a banner to be displayed. Currently this is displayed on the instance info page. |
|
||||
| `ROBOTS_DISABLE_INDEXING` | `["on", "off"]` | `off` | Disables indexing of the instance by search engines. |
|
||||
| `PUSHSHIFT_FRONTEND` | String | `www.unddit.com` | Allows the server to set the Pushshift frontend to be used with "removed" links. |
|
||||
| `PUSHSHIFT_FRONTEND` | String | `undelete.pullpush.io` | Allows the server to set the Pushshift frontend to be used with "removed" links. |
|
||||
|
||||
## Default user settings
|
||||
|
||||
|
33
src/utils.rs
33
src/utils.rs
@ -877,14 +877,16 @@ pub fn format_url(url: &str) -> String {
|
||||
static REDDIT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|new\.|)(reddit\.com|redd\.it)/"#).unwrap());
|
||||
static REDDIT_PREVIEW_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https?://(external-preview|preview)\.redd\.it(.*)[^?]").unwrap());
|
||||
static REDDIT_EMOJI_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https?://(www|).redditstatic\.com/(.*)").unwrap());
|
||||
static REDLIB_PREVIEW_LINK_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r#"/preview/(pre|external-pre)/(.*)">"#).unwrap());
|
||||
static REDLIB_PREVIEW_TEXT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r">(.*)</a>").unwrap());
|
||||
|
||||
// Rewrite Reddit links to Redlib in body of text
|
||||
pub fn rewrite_urls(input_text: &str) -> String {
|
||||
let text1 =
|
||||
let mut text1 =
|
||||
// Rewrite Reddit links to Redlib
|
||||
REDDIT_REGEX.replace_all(input_text, r#"href="/"#)
|
||||
.to_string();
|
||||
let text1 = REDDIT_EMOJI_REGEX
|
||||
text1 = REDDIT_EMOJI_REGEX
|
||||
.replace_all(&text1, format_url(REDDIT_EMOJI_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default()))
|
||||
.to_string()
|
||||
// Remove (html-encoded) "\" from URLs.
|
||||
@ -893,9 +895,21 @@ pub fn rewrite_urls(input_text: &str) -> String {
|
||||
|
||||
// Rewrite external media previews to Redlib
|
||||
if REDDIT_PREVIEW_REGEX.is_match(&text1) {
|
||||
REDDIT_PREVIEW_REGEX
|
||||
.replace_all(&text1, format_url(REDDIT_PREVIEW_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default()))
|
||||
loop {
|
||||
if REDDIT_PREVIEW_REGEX.find(&text1).is_none() {
|
||||
return text1;
|
||||
} else {
|
||||
let formatted_url = format_url(REDDIT_PREVIEW_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default());
|
||||
|
||||
let image_url = REDLIB_PREVIEW_LINK_REGEX.find(&formatted_url).map_or("", |m| m.as_str()).to_string();
|
||||
let image_text = REDLIB_PREVIEW_TEXT_REGEX.find(&formatted_url).map_or("", |m| m.as_str()).to_string();
|
||||
|
||||
text1 = REDDIT_PREVIEW_REGEX
|
||||
.replace(&text1, format_url(REDDIT_PREVIEW_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default()))
|
||||
.replace(&image_text, &format!("><img src=\"{image_url}</a>"))
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text1
|
||||
}
|
||||
@ -1148,3 +1162,14 @@ async fn test_fetching_ws() {
|
||||
assert!(post.ws_url.starts_with("wss://k8s-lb.wss.redditmedia.com/link/"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rewriting_image_links() {
|
||||
let input = r#"<p><a href="https://preview.redd.it/zq21ggkj2xo31.png?width=2560&format=png&auto=webp&s=539d8050628ec1190cac26468fe99cc66b6071ab">https://preview.redd.it/zq21ggkj2xo31.png?width=2560&format=png&auto=webp&s=539d8050628ec1190cac26468fe99cc66b6071ab</a></p>
|
||||
<p><a href="https://preview.redd.it/vty9ocij2xo31.png?width=2560&format=png&auto=webp&s=fc7c7ef993a5e9ef656d5f5d9cf8290a0a1df877">https://preview.redd.it/vty9ocij2xo31.png?width=2560&format=png&auto=webp&s=fc7c7ef993a5e9ef656d5f5d9cf8290a0a1df877</a></p>
|
||||
<p><a href="https://preview.redd.it/bdfdxkjj2xo31.png?width=2560&format=png&auto=webp&s=d0fa420ece27605e882e89cb4711d75d774322ac">https://preview.redd.it/bdfdxkjj2xo31.png?width=2560&format=png&auto=webp&s=d0fa420ece27605e882e89cb4711d75d774322ac</a></p>
|
||||
<p><a href="https://preview.redd.it/6awags382xo31.png?width=2560&format=png&auto=webp&s=9c563aed4f07a91bdd249b5a3cea43a79710dcfc">caption 1</a></p>
|
||||
<p><a href="https://preview.redd.it/rbu2ca2b2xo31.png?width=2560&format=png&auto=webp&s=afb538cf784d2e339de9a91aba5dc9c92e47988f">caption 2</a></p>"#;
|
||||
let output = r#"<p><a href="/preview/pre/zq21ggkj2xo31.png?width=2560&format=png&auto=webp&s=539d8050628ec1190cac26468fe99cc66b6071ab"><img src="/preview/pre/zq21ggkj2xo31.png?width=2560&format=png&auto=webp&s=539d8050628ec1190cac26468fe99cc66b6071ab"></a></p> <p><a href="/preview/pre/vty9ocij2xo31.png?width=2560&format=png&auto=webp&s=fc7c7ef993a5e9ef656d5f5d9cf8290a0a1df877"><img src="/preview/pre/vty9ocij2xo31.png?width=2560&format=png&auto=webp&s=fc7c7ef993a5e9ef656d5f5d9cf8290a0a1df877"></a></p> <p><a href="/preview/pre/bdfdxkjj2xo31.png?width=2560&format=png&auto=webp&s=d0fa420ece27605e882e89cb4711d75d774322ac"><img src="/preview/pre/bdfdxkjj2xo31.png?width=2560&format=png&auto=webp&s=d0fa420ece27605e882e89cb4711d75d774322ac"></a></p> <p><a href="/preview/pre/6awags382xo31.png?width=2560&format=png&auto=webp&s=9c563aed4f07a91bdd249b5a3cea43a79710dcfc"><img src="/preview/pre/6awags382xo31.png?width=2560&format=png&auto=webp&s=9c563aed4f07a91bdd249b5a3cea43a79710dcfc"></a></p> <p><a href="/preview/pre/rbu2ca2b2xo31.png?width=2560&format=png&auto=webp&s=afb538cf784d2e339de9a91aba5dc9c92e47988f"><img src="/preview/pre/rbu2ca2b2xo31.png?width=2560&format=png&auto=webp&s=afb538cf784d2e339de9a91aba5dc9c92e47988f"></a></p>"#;
|
||||
assert_eq!(rewrite_urls(input), output);
|
||||
}
|
||||
|
BIN
static/logo.png
BIN
static/logo.png
Binary file not shown.
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 11 KiB |
1
static/logo.svg
Normal file
1
static/logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(.75272 0 0 .75272 -.75945 -.16518)"><circle cx="341.11" cy="340.32" r="340.1" fill="#1a1a1a"/><path d="m320.64 126.73v300.8h92.264v-207.92h75.803v-92.83h-75.803v-0.0508z" fill="#0ff"/><path d="m193.1 126.74v383.96h6e-3v43.543h295.82v-92.338h-202.74v-335.16z" fill="#f9f9f9"/></g></svg>
|
After Width: | Height: | Size: 383 B |
@ -112,6 +112,16 @@ pre, form, fieldset, table, th, td, select, input {
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
|
||||
html.fixed_navbar {
|
||||
scroll-padding-top: 50px;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
html.fixed_navbar {
|
||||
scroll-padding-top: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
padding-bottom: var(--footer-height);
|
||||
@ -998,6 +1008,10 @@ a.search_subreddit:hover {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.post_body img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.post_poll {
|
||||
grid-area: post_poll;
|
||||
padding: 5px 15px 5px 12px;
|
||||
@ -1161,6 +1175,16 @@ a.search_subreddit:hover {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.comment img {
|
||||
max-width: 50%;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
.comment img {
|
||||
max-width: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
.comment_left, .comment_right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
16
static/themes/catppuccin.css
Normal file
16
static/themes/catppuccin.css
Normal file
@ -0,0 +1,16 @@
|
||||
.dark {
|
||||
--accent: #b4befe; /* lavender */
|
||||
--green: #a6e3a1; /* green */
|
||||
--text: #cdd6f4; /* text */
|
||||
--foreground: #11111b; /* crust */
|
||||
--background: #1e1e2e; /* base */
|
||||
--outside: #11111b; /* crust */
|
||||
--post: #11111b; /* crust */
|
||||
--panel-border: none;
|
||||
--highlighted: #313244; /* surface0 */
|
||||
--visited: #6c7086; /* overlay0 */
|
||||
--shadow: 0 0 0 transparent;
|
||||
|
||||
--nsfw: #fab387; /* peach */
|
||||
--admin: #eba0ac; /* maroon */
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{% import "utils.html" as utils %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="en" class="{% if prefs.fixed_navbar == "on" %}fixed_navbar{% endif %}">
|
||||
<head>
|
||||
{% block head %}
|
||||
<title>{% block title %}Redlib{% endblock %}</title>
|
||||
|
Loading…
Reference in New Issue
Block a user