Content-shipped stylesheet override (site.yaml stylesheet)
A content repo can now ship a CSS file named in site.yaml's stylesheet field; portal serves it same-origin at /site/<path> and leptos_meta appends it after the default stylesheet so content rules win. Plain repo-relative .css path only, validated on load. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y42TyF8Zu7NGRR2893vNcZ
This commit is contained in:
co-authored by
Claude Fable 5
parent
7fd40aaca9
commit
405bb98185
Generated
+1
-1
@@ -2948,7 +2948,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "portal"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arc-swap",
|
||||
|
||||
+13
-1
@@ -1,5 +1,5 @@
|
||||
use leptos::prelude::*;
|
||||
use leptos_meta::{provide_meta_context, HashedStylesheet, Html, MetaTags, Title};
|
||||
use leptos_meta::{provide_meta_context, HashedStylesheet, Html, MetaTags, Stylesheet, Title};
|
||||
use leptos_router::{
|
||||
components::{Route, Router, Routes},
|
||||
hooks::{use_location, use_navigate, use_query_map},
|
||||
@@ -79,8 +79,20 @@ pub fn App() -> impl IntoView {
|
||||
});
|
||||
provide_context(Lang(lang));
|
||||
|
||||
// A content-shipped stylesheet (site.yaml `stylesheet:`) layered
|
||||
// after the default one - leptos_meta appends it at the MetaTags
|
||||
// slot, which the shell places after HashedStylesheet, so content
|
||||
// rules win at equal specificity.
|
||||
let custom_css = Memo::new(move |_| {
|
||||
site.get()
|
||||
.and_then(|r| r.ok())
|
||||
.and_then(|s| s.stylesheet)
|
||||
.map(|p| format!("/site/{p}"))
|
||||
});
|
||||
|
||||
view! {
|
||||
<Html attr:lang=move || lang.get()/>
|
||||
{move || custom_css.get().map(|href| view! { <Stylesheet id="site-custom" href=href/> })}
|
||||
<Suspense fallback=|| ()>
|
||||
{move || {
|
||||
site.get()
|
||||
|
||||
@@ -527,6 +527,11 @@ pub struct SiteConfig {
|
||||
/// `None` means "en"; unknown codes fall back to English per key.
|
||||
#[serde(default)]
|
||||
pub lang: Option<String>,
|
||||
/// A content-repo-relative CSS file (e.g. "custom.css") layered
|
||||
/// *after* the default stylesheet, so it overrides. Served
|
||||
/// same-origin at `/site/<path>`; plain path only.
|
||||
#[serde(default)]
|
||||
pub stylesheet: Option<String>,
|
||||
#[serde(default)]
|
||||
pub hero: HeroConfig,
|
||||
}
|
||||
@@ -582,6 +587,13 @@ impl SiteConfig {
|
||||
}
|
||||
other => anyhow::bail!("site.yaml: hero.kind {other:?} is not one of plain | module"),
|
||||
}
|
||||
if let Some(sheet) = &self.stylesheet {
|
||||
if !is_safe_site_path(sheet) || !sheet.ends_with(".css") {
|
||||
anyhow::bail!(
|
||||
"site.yaml: stylesheet {sheet:?} must be a plain repo-relative .css path"
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user