🎨 [pagetop] Mejora gestión de URLs según contexto

This commit is contained in:
Manuel Cillero 2025-12-03 06:41:52 +01:00
parent 4944af073f
commit 51e18cf5ee
6 changed files with 32 additions and 28 deletions

View file

@ -91,13 +91,14 @@ pub struct Intro {
}
impl Default for Intro {
#[rustfmt::skip]
fn default() -> Self {
const BUTTON_LINK: &str = "https://pagetop.cillero.es";
Intro {
title : L10n::l("intro_default_title"),
slogan : L10n::l("intro_default_slogan").with_arg("app", &global::SETTINGS.app.name),
button : Some((L10n::l("intro_default_button"), |_| "https://pagetop.cillero.es")),
opening : IntroOpening::default(),
title: L10n::l("intro_default_title"),
slogan: L10n::l("intro_default_slogan").with_arg("app", &global::SETTINGS.app.name),
button: Some((L10n::l("intro_default_button"), |_| BUTTON_LINK.into())),
opening: IntroOpening::default(),
children: Children::default(),
}
}

View file

@ -1,5 +1,7 @@
//! API para construir nuevos componentes.
use std::borrow::Cow;
mod definition;
pub use definition::{Component, ComponentRender};
@ -66,6 +68,10 @@ pub type FnIsRenderable = fn(cx: &Context) -> bool;
/// Alias de función (*callback*) para **resolver una URL** según el contexto de renderizado.
///
/// Se usa para generar enlaces dinámicos en función del contexto (petición, idioma, etc.). Debe
/// devolver una referencia válida durante el renderizado.
pub type FnPathByContext = fn(cx: &Context) -> &str;
/// Se usa para generar enlaces dinámicos en función del contexto (petición, idioma, etc.). El
/// resultado se devuelve como [`Cow<'static, str>`](std::borrow::Cow), lo que permite:
///
/// - Usar rutas estáticas sin asignaciones adicionales (`"/path".into()`).
/// - Construir rutas dinámicas en tiempo de ejecución (`format!(...).into()`), por ejemplo, en
/// función de parámetros almacenados en [`Context`].
pub type FnPathByContext = fn(cx: &Context) -> Cow<'static, str>;