🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pgml-dashboard/src/components/layouts/head/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pgml_components::component;
use pgml_components::{component, Component};
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default, Clone)]
Expand All @@ -10,6 +10,7 @@ pub struct Head {
pub preloads: Vec<String>,
pub context: Option<String>,
pub canonical: Option<String>,
pub additional_components: Vec<Component>,
}

impl Head {
Expand Down Expand Up @@ -58,6 +59,25 @@ impl Head {
self.context = context.to_owned();
self
}

/// Add a component to `<head>`.
///
/// This can be anything, e.g. a `<script>` tag or a `<meta>` or just some HTML or text.
///
/// # Example
///
/// ```
/// use pgml_components::Component;
/// use pgml_components::layouts::Head;
///
/// let head = Head::new()
/// .add_component(Component::from("<script>console.log('hello');</script>"));
/// ```
///
pub fn add_component(mut self, component: Component) -> Self {
self.additional_components.push(component);
self
}
}

component!(Head);
Expand Down
4 changes: 4 additions & 0 deletions pgml-dashboard/src/components/layouts/head/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@
};
</script>
<% } %>

<% for component in additional_components { %>
<%+ component %>
<% } %>
</head>
11 changes: 10 additions & 1 deletion pgml-dashboard/src/components/layouts/marketing/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::components::notifications::marketing::AlertBanner;
use crate::guards::Cluster;
use crate::models::User;
use crate::Notification;
use pgml_components::component;
use pgml_components::{component, Component};
use sailfish::TemplateOnce;
use std::fmt;

Expand Down Expand Up @@ -72,6 +72,15 @@ impl Base {
rsp
}

/// Add a component to the `<head>`.
///
/// See [`Head::add_component`](crate::components::layouts::Head::add_component) for more information.
///
pub fn add_head_component(mut self, component: Component) -> Self {
self.head = self.head.add_component(component);
self
}

pub fn footer(mut self, footer: String) -> Self {
self.footer = Some(footer);
self
Expand Down
11 changes: 11 additions & 0 deletions pgml-dashboard/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ impl<'a> WebAppBase<'a> {
self
}

/// Add a component to head (`<head>`).
///
/// # Arguments
///
/// * `component` - The component to add to the head.
///
pub fn add_head_component(&mut self, component: Component) -> &mut Self {
self.head = self.head.clone().add_component(component);
self
}

pub fn render<T>(&mut self, template: T) -> String
where
T: sailfish::TemplateOnce,
Expand Down