dailp/page.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//! Provides types for structuring text-based pages.
use async_graphql::{InputObject, SimpleObject, Union};
use serde::{Deserialize, Serialize};
/// A website page which lives at a specific URL and has a list of blocks that
/// define its content.
#[derive(Clone, Serialize, Deserialize, SimpleObject, Debug)]
pub struct Page {
/// The path that this page lives at, which also uniquely identifies it.
/// For example, "/our-team"
pub id: uuid::Uuid,
pub title: String,
pub body: Vec<ContentBlock>,
pub path: String,
}
impl Page {
pub fn build(id: uuid::Uuid, path: String, title: String, body: Vec<ContentBlock>) -> Self {
Self {
id,
path,
title,
body,
}
}
}
/// Input struct for a page.
#[derive(Clone, Serialize, Deserialize, SimpleObject, InputObject)]
pub struct NewPageInput {
/// title of new page
pub title: String,
/// content for page, needs to be sanitized
pub body: Vec<String>,
/// path of new page
pub path: String,
}
/// A block of content, which may be one of several types.
/// Each page contains several blocks.
///
/// This type is intended to enable a custom page builder on the front-end for
/// content editors.
#[derive(Clone, Serialize, Deserialize, Union, Debug)]
#[serde(tag = "__typename")]
pub enum ContentBlock {
/// Block of markdown prose content
Markdown(Markdown),
/// Gallery of images
Gallery(Gallery),
}
/// A block of prose content, formatted with [Markdown](https://commonmark.org/).
#[derive(Clone, Serialize, Deserialize, SimpleObject, Debug)]
pub struct Markdown {
pub content: String,
}
/// A gallery of images, which may be rendered as a slideshow or lightbox.
#[derive(Clone, Serialize, Deserialize, SimpleObject, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Gallery {
media_urls: Vec<String>,
}