allow for injecting css scripts into pages

This commit is contained in:
zyl 2024-06-17 21:25:29 -07:00
parent f9b15aa932
commit 8d9866d048
No known key found for this signature in database
3 changed files with 9 additions and 0 deletions

View file

@ -10,6 +10,9 @@
{{#each scripts}} {{#each scripts}}
<script type="text/javascript" src="{{this}}" defer></script> <script type="text/javascript" src="{{this}}" defer></script>
{{/each}} {{/each}}
{{#each styles}}
<link rel="stylesheet" href="/styles/{{this}}">
{{/each}}
</head> </head>
<body> <body>

View file

@ -23,6 +23,8 @@ struct TemplateData<'a, T> {
pub title: &'a str, pub title: &'a str,
/// The page's custom scripts. /// The page's custom scripts.
pub scripts: &'a [String], pub scripts: &'a [String],
/// the page's custom styles.
pub styles: &'a [String],
/// Custom template data. /// Custom template data.
#[serde(flatten)] #[serde(flatten)]
pub extra_data: T, pub extra_data: T,
@ -216,6 +218,7 @@ impl<'a> SiteBuilder<'a> {
page: page_html, page: page_html,
title: &title, title: &title,
scripts: &page_metadata.scripts, scripts: &page_metadata.scripts,
styles: &page_metadata.styles,
extra_data, extra_data,
}, },
)?; )?;

View file

@ -70,6 +70,9 @@ pub struct PageMetadata {
/// The page's custom scripts, if any. /// The page's custom scripts, if any.
#[serde(default)] #[serde(default)]
pub scripts: Vec<String>, pub scripts: Vec<String>,
/// the page's custom styles, if any.
#[serde(default)]
pub styles: Vec<String>,
/// The extra stuff to run for the page, if any. /// The extra stuff to run for the page, if any.
pub extra: Option<String>, pub extra: Option<String>,
} }