mirror of
https://github.com/zyllian/webdog.git
synced 2025-01-17 19:22:21 -08:00
implement custom userdata, resolves #11
This commit is contained in:
parent
6c31ccb9d5
commit
95a0765b1e
4 changed files with 35 additions and 0 deletions
|
@ -77,6 +77,10 @@ list of extra stylesheets to include in the page.
|
|||
|
||||
see <a href="extras">extras documentation</a> for more info on this field.
|
||||
|
||||
### `userdata`
|
||||
|
||||
custom userdata to supply to the page's base template.
|
||||
|
||||
## special features
|
||||
|
||||
in addition to standard markdown, webdog comes with some minor additions for ease of use.
|
||||
|
|
|
@ -30,3 +30,28 @@ the main html content for the page to be rendered. can be rendered anywhere you
|
|||
{% block content %}{{ page | safe }}{% endblock content %}
|
||||
</main>
|
||||
```
|
||||
|
||||
### `userdata`
|
||||
|
||||
custom userdata provided by the page to be rendered.
|
||||
|
||||
if a page defines its userdata as follows:
|
||||
|
||||
```yaml
|
||||
userdata:
|
||||
value: 5
|
||||
```
|
||||
|
||||
you may use it like so:
|
||||
|
||||
```tera
|
||||
{{ userdata.value }}
|
||||
```
|
||||
|
||||
or, to only use it only if it exists:
|
||||
|
||||
```tera
|
||||
{% if userdata is object and 'value' in userdata %}
|
||||
{{ userdata.value }}
|
||||
{% endif %}
|
||||
```
|
||||
|
|
|
@ -24,6 +24,8 @@ struct TemplateData<'a, T> {
|
|||
pub title: &'a str,
|
||||
/// Custom template data.
|
||||
pub data: T,
|
||||
/// Userdata supplied from the page.
|
||||
pub userdata: serde_yml::Value,
|
||||
}
|
||||
|
||||
/// Struct used to build the site.
|
||||
|
@ -320,6 +322,7 @@ impl SiteBuilder {
|
|||
page: page_html,
|
||||
title: &title,
|
||||
data: extra_data,
|
||||
userdata: page_metadata.userdata,
|
||||
})?,
|
||||
)?;
|
||||
|
||||
|
|
|
@ -128,6 +128,9 @@ pub struct PageMetadata {
|
|||
/// The extra stuff to run for the page, if any.
|
||||
#[serde(default)]
|
||||
pub extra: Option<ExtraData>,
|
||||
/// Custom values passed to the base template.
|
||||
#[serde(default)]
|
||||
pub userdata: serde_yml::Value,
|
||||
}
|
||||
|
||||
/// Struct containing information about the site.
|
||||
|
|
Loading…
Add table
Reference in a new issue