aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-02-04 02:01:43 +0000
committerFuwn <[email protected]>2023-02-04 02:01:43 +0000
commit851bfbd3c37ceb18178380f51913feef6dc4274c (patch)
tree21c46f7a1f8aa6e198295ab4630dff9ecfcbc3b0
parentfix(gemini_to_html.rs): html entity-encode gemini (diff)
downloadseptember-851bfbd3c37ceb18178380f51913feef6dc4274c.tar.xz
september-851bfbd3c37ceb18178380f51913feef6dc4274c.zip
build(rustup): move from nightly to stable)
-rw-r--r--.license_template17
-rw-r--r--Dockerfile8
-rw-r--r--Makefile.toml1
-rw-r--r--rust-toolchain.toml2
-rw-r--r--rustfmt.toml20
-rw-r--r--src/gemini_to_html.rs48
-rw-r--r--src/main.rs18
-rw-r--r--src/response.rs41
-rw-r--r--src/url.rs19
9 files changed, 67 insertions, 107 deletions
diff --git a/.license_template b/.license_template
deleted file mode 100644
index c3c7133..0000000
--- a/.license_template
+++ /dev/null
@@ -1,17 +0,0 @@
-// This file is part of September <https://github.com/gemrest/september>.
-// Copyright (C) {20\d{2}(-20\d{2})?} Fuwn <[email protected]>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 3.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-// Copyright (C) {20\d{2}(-20\d{2})?} Fuwn <[email protected]>
-// SPDX-License-Identifier: GPL-3.0-only
diff --git a/Dockerfile b/Dockerfile
index 6c8df3f..3f21f5f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
-FROM clux/muslrust:nightly-2022-03-08 AS environment
+FROM clux/muslrust:1.66.0 AS environment
-ENV CHANNEL=nightly-2022-03-08
+ENV CHANNEL=1.66.0
RUN curl "https://static.rust-lang.org/rustup/archive/${RUSTUP_VER}/${RUST_ARCH}/rustup-init" -o rustup-init \
&& chmod +x rustup-init \
@@ -11,8 +11,10 @@ RUN curl "https://static.rust-lang.org/rustup/archive/${RUSTUP_VER}/${RUST_ARCH}
RUN cargo install sccache
+RUN apt-get update \
+ && apt-get install -y gnupg2
+
RUN curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
- && apt-get update \
&& apt-get install -y clang
# RUN cargo install --git https://github.com/dimensionhq/fleet fleet-rs
diff --git a/Makefile.toml b/Makefile.toml
index a3940af..d5356b2 100644
--- a/Makefile.toml
+++ b/Makefile.toml
@@ -5,6 +5,7 @@
command = "cargo"
args = ["fmt"]
private = true
+toolchain = "nightly"
[tasks.check]
command = "cargo"
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
deleted file mode 100644
index 099ab4b..0000000
--- a/rust-toolchain.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-[toolchain]
-channel = "nightly-2022-03-08"
diff --git a/rustfmt.toml b/rustfmt.toml
index 1dd4c90..c2072ca 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,30 +1,16 @@
-condense_wildcard_suffixes = true
edition = "2021"
-enum_discrim_align_threshold = 20
-# error_on_line_overflow = true
-# error_on_unformatted = true
+condense_wildcard_suffixes = true
fn_single_line = true
-force_multiline_blocks = true
format_code_in_doc_comments = true
-format_macro_matchers = true
+doc_comment_code_block_width = 80
format_strings = true
-imports_layout = "HorizontalVertical"
-license_template_path = ".license_template"
-max_width = 80
match_arm_blocks = false
+max_width = 80
imports_granularity = "Crate"
-newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
reorder_impl_items = true
group_imports = "StdExternalCrate"
-reorder_modules = true
-report_fixme = "Always"
-# report_todo = "Always"
-struct_field_align_threshold = 20
-struct_lit_single_line = false
tab_spaces = 2
use_field_init_shorthand = true
-use_try_shorthand = true
-where_single_line = true
wrap_comments = true
diff --git a/src/gemini_to_html.rs b/src/gemini_to_html.rs
index 845c568..8359cfe 100644
--- a/src/gemini_to_html.rs
+++ b/src/gemini_to_html.rs
@@ -47,22 +47,19 @@ pub fn gemini_to_html(
));
let ast = ast_tree.inner();
let mut html = String::new();
- let mut title = "".to_string();
+ let mut title = String::new();
for node in ast {
match node {
- Node::Text(text) => html.push_str(&format!("<p>{}</p>", text)),
- Node::Link {
- to,
- text,
- } => {
+ Node::Text(text) => html.push_str(&format!("<p>{text}</p>")),
+ Node::Link { to, text } => {
let mut href = to.clone();
let mut surface = false;
if href.contains("://") && !href.starts_with("gemini://") {
surface = true;
} else if !href.starts_with("gemini://") && !href.starts_with('/') {
- href = format!("./{}", href);
+ href = format!("./{href}");
} else if href.starts_with('/') || !href.contains("://") {
href = link_from_host_href(url, &href);
}
@@ -78,7 +75,7 @@ pub fn gemini_to_html(
.trim_end_matches('/')
.split('/')
.collect::<Vec<_>>()
- .get(0)
+ .first()
.unwrap()
!= &url.authority.host.as_str()
{
@@ -115,13 +112,10 @@ pub fn gemini_to_html(
html.push_str(&format!(
"<p><a href=\"{}\">{}</a></p>\n",
href,
- text.clone().unwrap_or_else(|| "".to_string())
+ text.clone().unwrap_or_default()
));
}
- Node::Heading {
- level,
- text,
- } => {
+ Node::Heading { level, text } => {
if title.is_empty() && *level == 1 {
title = text.clone();
}
@@ -137,21 +131,19 @@ pub fn gemini_to_html(
text
));
}
- Node::List(items) =>
- html.push_str(&format!(
- "<ul>{}</ul>",
- items
- .iter()
- .map(|i| format!("<li>{}</li>", i))
- .collect::<Vec<String>>()
- .join("\n")
- )),
- Node::Blockquote(text) =>
- html.push_str(&format!("<blockquote>{}</blockquote>", text)),
- Node::PreformattedText {
- text, ..
- } => {
- html.push_str(&format!("<pre>{}</pre>", text));
+ Node::List(items) => html.push_str(&format!(
+ "<ul>{}</ul>",
+ items
+ .iter()
+ .map(|i| format!("<li>{i}</li>"))
+ .collect::<Vec<String>>()
+ .join("\n")
+ )),
+ Node::Blockquote(text) => {
+ html.push_str(&format!("<blockquote>{text}</blockquote>"));
+ }
+ Node::PreformattedText { text, .. } => {
+ html.push_str(&format!("<pre>{text}</pre>"));
}
Node::Whitespace => {}
}
diff --git a/src/main.rs b/src/main.rs
index 3b6f740..a5c5330 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -64,19 +64,15 @@ async fn main() -> std::io::Result<()> {
"0.0.0.0",
// If the `PORT` environment variable is present, try to use it, otherwise;
// use port `80`.
- if let Ok(port) = var("PORT") {
- match port.parse::<_>() {
- Ok(port) => port,
- Err(e) => {
- warn!("could not use PORT from environment variables: {}", e);
- warn!("proceeding with default port: 80");
+ var("PORT").map_or(80, |port| match port.parse::<_>() {
+ Ok(port) => port,
+ Err(e) => {
+ warn!("could not use PORT from environment variables: {}", e);
+ warn!("proceeding with default port: 80");
- 80
- }
+ 80
}
- } else {
- 80
- },
+ }),
))?
.run()
.await
diff --git a/src/response.rs b/src/response.rs
index b114441..bd79024 100644
--- a/src/response.rs
+++ b/src/response.rs
@@ -36,7 +36,7 @@ pub async fn default(
{
format!("?{}", req.query_string())
} else {
- "".to_string()
+ String::new()
}
}),
false,
@@ -49,7 +49,7 @@ pub async fn default(
return Ok(
HttpResponse::BadRequest()
.content_type("text/plain")
- .body(format!("{}", e)),
+ .body(format!("{e}")),
);
}
};
@@ -75,7 +75,7 @@ pub async fn default(
return Ok(
HttpResponse::BadRequest()
.content_type("text/plain")
- .body(format!("{}", e)),
+ .body(format!("{e}")),
);
}
}) {
@@ -95,7 +95,7 @@ pub async fn default(
let language = meta
.parameters()
.get("lang")
- .map_or_else(|| "".to_string(), ToString::to_string);
+ .map_or_else(String::new, ToString::to_string);
// Reset timer for below
timer = Instant::now();
@@ -107,9 +107,9 @@ pub async fn default(
format!(
"<!DOCTYPE html><html{}><head>",
if language.is_empty() {
- "".to_string()
+ String::new()
} else {
- format!(" lang=\"{}\"", language)
+ format!(" lang=\"{language}\"")
}
)
};
@@ -123,7 +123,7 @@ pub async fn default(
return Ok(
HttpResponse::Ok()
- .content_type(format!("{}; charset={}", meta.mime(), charset))
+ .content_type(format!("{}; charset={charset}", meta.mime()))
.body(html_context),
);
}
@@ -157,18 +157,19 @@ pub async fn default(
}
// Add a title to HTML response
- html_context.push_str(&format!("<title>{}</title>", gemini_title));
+ html_context.push_str(&format!("<title>{gemini_title}</title>"));
html_context.push_str("</head><body>");
match response.status {
- gmi::protocol::StatusCode::Success(_) =>
- html_context.push_str(&gemini_html.1),
+ gmi::protocol::StatusCode::Success(_) => {
+ html_context.push_str(&gemini_html.1);
+ }
_ => html_context.push_str(&format!("<p>{}</p>", response.meta)),
}
// Add proxy information to footer of HTML response
html_context.push_str(&format!(
- "<details>\n<summary>Proxy information</summary>
+ "<details>\n<summary>Proxy information</summary>
<dl>
<dt>Original URL</dt><dd><a href=\"{}\">{0}</a></dd>
<dt>Status code</dt>
@@ -182,14 +183,14 @@ pub async fn default(
<p>This content has been proxied by \
<a href=\"https://github.com/gemrest/september{}\">September ({})</a>.</p>
</details></body></html>",
- url,
- response.status,
- response.meta,
- response_time_taken.as_nanos() as f64 / 1_000_000.0,
- convert_time_taken.as_nanos() as f64 / 1_000_000.0,
- format_args!("/tree/{}", env!("VERGEN_GIT_SHA")),
- env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"),
- ));
+ url,
+ response.status,
+ response.meta,
+ response_time_taken.as_nanos() as f64 / 1_000_000.0,
+ convert_time_taken.as_nanos() as f64 / 1_000_000.0,
+ format_args!("/tree/{}", env!("VERGEN_GIT_SHA")),
+ env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"),
+ ));
if let Ok(plain_texts) = var("PLAIN_TEXT_ROUTE") {
if plain_texts.split(',').any(|r| r == req.path()) {
@@ -202,7 +203,7 @@ pub async fn default(
Ok(
HttpResponse::Ok()
- .content_type(format!("text/html; charset={}", charset))
+ .content_type(format!("text/html; charset={charset}"))
.body(html_context),
)
}
diff --git a/src/url.rs b/src/url.rs
index 5100d44..1653335 100644
--- a/src/url.rs
+++ b/src/url.rs
@@ -66,16 +66,17 @@ pub fn make(
format!(
"{}{}{}",
{
- if let Ok(root) = std::env::var("ROOT") {
- root
- } else {
- warn!(
- "could not use ROOT from environment variables, proceeding with \
- default root: gemini://fuwn.me"
- );
+ std::env::var("ROOT").map_or_else(
+ |_| {
+ warn!(
+ "could not use ROOT from environment variables, proceeding \
+ with default root: gemini://fuwn.me"
+ );
- "gemini://fuwn.me".to_string()
- }
+ "gemini://fuwn.me".to_string()
+ },
+ |root| root,
+ )
},
path,
if fallback { "/" } else { "" }