post_archiver/
content.rs

1use serde::{Deserialize, Serialize};
2#[cfg(feature = "typescript")]
3use ts_rs::TS;
4
5use crate::id::FileMetaId;
6
7/// A content segment within a post that can be either text or a file reference
8///
9/// - Used within [`Post`](crate::post::Post) content arrays
10/// - References [`FileMeta`](crate::file_meta::FileMeta) through FileMetaId
11///
12/// # Variants:
13/// - Text: Contains markdown-formatted text content
14/// - File: References external file content via FileMetaId
15///
16/// # Processing:
17/// - Text content should be rendered as markdown
18/// - File content requires metadata lookup and appropriate handling
19///
20/// # Examples
21/// ```rust
22/// use post_archiver::{Content, FileMetaId};
23///
24/// // Text content with markdown
25/// let text = Content::Text("# Heading\n\nSome **bold** text".to_string());
26///
27/// // File reference
28/// let image = Content::File(FileMetaId::new(1));
29///
30/// // Mixed content post
31/// let contents = vec![
32///     Content::Text("Introduction:".to_string()),
33///     Content::File(FileMetaId::new(1)),
34///     Content::Text("*Caption for the above image*".to_string())
35/// ];
36/// ```
37#[cfg_attr(feature = "typescript", derive(TS))]
38#[cfg_attr(feature = "typescript", ts(export))]
39#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
40#[serde(untagged)]
41pub enum Content {
42    /// Markdown-formatted text content
43    ///
44    /// The text content should be processed as markdown when rendering,
45    Text(String),
46    /// Reference to a file via its metadata ID
47    File(FileMetaId),
48}