Crate teensy_cms

Source
Expand description

TeensyCMS is the smallest CMS possible that allows admins running your application to add custom pages that are accessible from a nav bar.

An implementation of TeensyCMS with actix-web can be found in the source code’s example directory.

use teensy_cms::{TeensyCms, DefaultPage};

let my_config = MyConfig::from_env();
let cms = TeensyCms::<DefaultPage>::from_config_path(
    "/page",
    &my_config.pages_config_path
).unwrap();

/* -- server initialization here -- */

fn handle_page_request(req: Request) -> String {
    // something like "contact" or "about"
    let page = &req.path_args()["page"];
    req.data::<TeensyCms<DefaultPage>>().unwrap()
        .render(&format!("{page}.html")).unwrap()
}

Pages use YAML frontmatter followed by HTML. The frontmatter MUST be delimited by --- both before and after. Only a single YAML document is permitted in the frontmatter.

---
title: My Page
cats: [Scruffles, Mx. Clawz]
---
<h1>{{ page.title }}</h1>
<ul>
  {% for cat in page.cats %}
    <li>{{ cat }}</li>
  {% endfor %}
</ul>

Structs§

  • Configuration for the application.
  • A struct that collects all values and makes them available to the page or templates.
  • Contains the nested menu items after loading all pages.
  • The main CMS struct.

Enums§

Traits§

  • Trait for a page’s frontmatter that loaded from a template.

Type Aliases§