caio.co/de/caca

Optionally link to listing from repo pages

A little more vanity for the public instance won't hurt
Id
3568e28ea3f5f263c23430be5f65688347e25909
Author
Caio
Commit time
2024-03-09T10:22:37+01:00

Modified caca/src/config.rs

@@ -37,6 +37,7
base_url: String::from("http://localhost:42080"),
clone_base_url: None,
reverse_proxy_base: None,
+ repo_to_listing_name: None,
},
max_file_size_bytes: 2 * 1024 * 1024,
rename_similarity_threshold: Some(0.7),
@@ -63,6 +64,9
pub base_url: String,
// for mounting it as a subfolder when reverse proxying
pub reverse_proxy_base: Option<String>,
+ // fscking terrible name, but when set, a link to the index
+ // will appear before the repo name in every repo page header
+ pub repo_to_listing_name: Option<String>,

// override the url displayed for clone
// gets the repo name appended
@@ -78,6 +82,7
base_url: "https://caio.co".to_string(),
reverse_proxy_base: Some("/de".to_string()),
clone_base_url: None,
+ repo_to_listing_name: Some("caio.co/de".to_string()),
},
global_mailmap: Some("/etc/caca/mailmap".into()),
listen_mode: ListenMode::External,
@@ -132,6 +137,13
)
}

+ pub fn listing_url(&self) -> String {
+ format!(
+ "{}/",
+ self.site.reverse_proxy_base.as_deref().unwrap_or_default()
+ )
+ }
+
pub fn repo_clone_url(&self, name: &str) -> String {
if let Some(ref url) = self.site.clone_base_url {
format!("{url}/{name}",)
@@ -172,6 +184,10
}
"reverse-proxy-base" => {
config.site.reverse_proxy_base =
+ Some(String::from_utf8_lossy(value).into_owned());
+ }
+ "repo-to-listing-name" => {
+ config.site.repo_to_listing_name =
Some(String::from_utf8_lossy(value).into_owned());
}
_ => {
@@ -451,6 +467,7
listing-html-header = <h1>caio.<strong>co/de</strong></h1>
base-url = https://caio.co
reverse-proxy-base = /de
+repo-to-listing-name = caio.co/de

[core]
listen = external

Modified caca/theme/repo.html

@@ -1,9 +1,11
{% extends "base.html" %}

{% block title %}{{ repo.name }}{% if repo.description %} - {{ repo.description }}{% endif %} {% endblock title %}

{% block header %}
-<h3><a class="nodec" href="{{ repo.url }}">{{ repo.name }}</a></h3>
+<h3>{% if repo.listing_name %}<a class="nodec" href="{{ repo.listing_url }}">{{ repo.listing_name }}</a>/{% endif %}<a
+ class="nodec" href="{{ repo.url }}">{{
+ repo.name }}</a></h3>
{% if nav %}
<nav>
<ol>

Modified caca/src/repo/mod.rs

@@ -33,6 +33,8
pub name: String,
pub clone_url: String,
pub repo_url: String,
+ pub listing_url: String,
+ pub listing_name: Option<String>,
pub feed_base_url: String,
pub reverse_proxy_base: String,
pub snapshot: Snapshot,
@@ -232,6 +234,8

let clone_url = config.repo_clone_url(&name);
let repo_url = config.repo_url(&name);
+ let listing_url = config.listing_url();
+ let listing_name = config.site.repo_to_listing_name.clone();

let reverse_proxy_base = config
.site
@@ -244,6 +248,8
name,
repo_url,
clone_url,
+ listing_url,
+ listing_name,
feed_base_url: config.feed_base_url(),
snapshot,
mailmap,
@@ -764,6 +770,8
name: &self.name,
url: &self.repo_url,
clone_url: &self.clone_url,
+ listing_url: &self.listing_url,
+ listing_name: self.listing_name.as_deref(),
description: self.snapshot.metadata.description.as_deref(),
}
}
@@ -1231,6 +1239,8
description: Option<&'a str>,
url: &'a str,
clone_url: &'a str,
+ listing_url: &'a str,
+ listing_name: Option<&'a str>,
}

#[derive(Debug, serde::Serialize)]