feat: Default index page improvements

- Add project logo to footer and favicon
- Display different messages depending on if first-run mode is active
This commit is contained in:
Ginger 2026-02-13 09:58:35 -05:00 committed by Ellis Git
parent ea3c00da43
commit 01b5dffeee
5 changed files with 43 additions and 18 deletions

View file

@ -83,3 +83,12 @@ footer {
color: transparent; color: transparent;
filter: brightness(1.2); filter: brightness(1.2);
} }
b {
color: oklch(from var(--c2) var(--name-lightness) c h);
}
.logo {
width: 100%;
height: 64px;
}

View file

@ -10,8 +10,9 @@ use conduwuit_build_metadata::{GIT_REMOTE_COMMIT_URL, GIT_REMOTE_WEB_URL, versio
use conduwuit_service::state; use conduwuit_service::state;
pub fn build() -> Router<state::State> { pub fn build() -> Router<state::State> {
let router = Router::<state::State>::new(); Router::<state::State>::new()
router.route("/", get(index_handler)) .route("/", get(index_handler))
.route("/_continuwuity/logo.svg", get(logo_handler))
} }
async fn index_handler( async fn index_handler(
@ -19,22 +20,34 @@ async fn index_handler(
) -> Result<impl IntoResponse, WebError> { ) -> Result<impl IntoResponse, WebError> {
#[derive(Debug, Template)] #[derive(Debug, Template)]
#[template(path = "index.html.j2")] #[template(path = "index.html.j2")]
struct Tmpl<'a> { struct Index<'a> {
nonce: &'a str, nonce: &'a str,
server_name: &'a str, server_name: &'a str,
first_run: bool,
} }
let nonce = rand::random::<u64>().to_string(); let nonce = rand::random::<u64>().to_string();
let template = Tmpl { let template = Index {
nonce: &nonce, nonce: &nonce,
server_name: services.config.server_name.as_str(), server_name: services.config.server_name.as_str(),
first_run: services.firstrun.is_first_run(),
}; };
Ok(( Ok((
[(header::CONTENT_SECURITY_POLICY, format!("default-src 'none' 'nonce-{nonce}';"))], [(
header::CONTENT_SECURITY_POLICY,
format!("default-src 'nonce-{nonce}'; img-src 'self';"),
)],
Html(template.render()?), Html(template.render()?),
)) ))
} }
async fn logo_handler() -> impl IntoResponse {
(
[(header::CONTENT_TYPE, "image/svg+xml")],
include_str!("templates/logo.svg").to_owned(),
)
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
enum WebError { enum WebError {
#[error("Failed to render template: {0}")] #[error("Failed to render template: {0}")]
@ -45,7 +58,7 @@ impl IntoResponse for WebError {
fn into_response(self) -> Response { fn into_response(self) -> Response {
#[derive(Debug, Template)] #[derive(Debug, Template)]
#[template(path = "error.html.j2")] #[template(path = "error.html.j2")]
struct Tmpl<'a> { struct Error<'a> {
nonce: &'a str, nonce: &'a str,
err: WebError, err: WebError,
} }
@ -55,7 +68,7 @@ impl IntoResponse for WebError {
let status = match &self { let status = match &self {
| Self::Render(_) => StatusCode::INTERNAL_SERVER_ERROR, | Self::Render(_) => StatusCode::INTERNAL_SERVER_ERROR,
}; };
let tmpl = Tmpl { nonce: &nonce, err: self }; let tmpl = Error { nonce: &nonce, err: self };
if let Ok(body) = tmpl.render() { if let Ok(body) = tmpl.render() {
( (
status, status,

View file

@ -6,6 +6,7 @@
<title>{% block title %}Continuwuity{% endblock %}</title> <title>{% block title %}Continuwuity{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/_continuwuity/logo.svg">
<style type="text/css" nonce="{{ nonce }}"> <style type="text/css" nonce="{{ nonce }}">
/*<![CDATA[*/ /*<![CDATA[*/
{{ include_str !("css/index.css") | safe }} {{ include_str !("css/index.css") | safe }}
@ -17,7 +18,8 @@
<main>{%~ block content %}{% endblock ~%}</main> <main>{%~ block content %}{% endblock ~%}</main>
{%~ block footer ~%} {%~ block footer ~%}
<footer> <footer>
<p>Powered by <a href="https://continuwuity.org">Continuwuity</a> <img class="logo" src="/_continuwuity/logo.svg">
<p>Powered by <a href="https://continuwuity.org">Continuwuity</a> {{ env!("CARGO_PKG_VERSION") }}
{%~ if let Some(version_info) = self::version_tag() ~%} {%~ if let Some(version_info) = self::version_tag() ~%}
{%~ if let Some(url) = GIT_REMOTE_COMMIT_URL.or(GIT_REMOTE_WEB_URL) ~%} {%~ if let Some(url) = GIT_REMOTE_COMMIT_URL.or(GIT_REMOTE_WEB_URL) ~%}
(<a href="{{ url }}">{{ version_info }}</a>) (<a href="{{ url }}">{{ version_info }}</a>)

View file

@ -1,16 +1,16 @@
{% extends "_layout.html.j2" %} {% extends "_layout.html.j2" %}
{%- block content -%} {%- block content -%}
<div class="orb"></div>
<div class="panel"> <div class="panel">
<h1>Welcome to <a class="project-name" href="https://continuwuity.org">Continuwuity</a>!</h1> <h1>
<p>Continuwuity is successfully installed and working. </p> Welcome to <a class="project-name" href="https://continuwuity.org">Continuwuity</a>!
<p>To get started, you can:</p> </h1>
<ul> <p>Continuwuity is successfully installed and working.</p>
<li>Read the <a href="https://continuwuity.org/introduction">documentation</a></li> {%- if first_run %}
<li>Join the <a href="https://matrix.to/#/#continuwuity:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org">Continuwuity Matrix room</a> or <a href="https://matrix.to/#/#space:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org">space</a></li> <p>To get started, <b>check the server logs</b> for instructions on how to create the first account.</p>
<li>Log in with a <a href="https://matrix.org/ecosystem/clients/">client</a></li> <p>For support, take a look at the <a href="https://continuwuity.org/introduction">documentation</a> or join the <a href="https://matrix.to/#/#continuwuity:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org">Continuwuity Matrix room</a>.</p>
<li>Ensure <a href="https://federationtester.mtrnord.blog/?serverName={{ server_name }}">federation</a> works</li> {%- else %}
</ul> <p>To get started, <a href="https://matrix.org/ecosystem/clients">choose a client</a> and connect to <code>{{ server_name }}</code>.</p>
{%- endif %}
</div> </div>
{%- endblock content -%} {%- endblock content -%}

1
src/web/templates/logo.svg Symbolic link
View file

@ -0,0 +1 @@
../../../docs/public/assets/logo.svg