Skip to main content

trek_rs/
types.rs

1//! Type definitions for Trek
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Options for Trek parsing
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct TrekOptions {
10    /// Enable debug logging
11    pub debug: bool,
12
13    /// URL of the page being parsed
14    pub url: Option<String>,
15
16    /// Output format options
17    #[serde(flatten)]
18    pub output: OutputOptions,
19
20    /// Content removal options
21    #[serde(flatten)]
22    pub removal: RemovalOptions,
23}
24
25/// Output format options
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct OutputOptions {
29    /// Convert output to Markdown
30    pub markdown: bool,
31
32    /// Include Markdown in the response
33    pub separate_markdown: bool,
34}
35
36/// Content removal options
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct RemovalOptions {
40    /// Whether to remove elements matching exact selectors
41    pub remove_exact_selectors: bool,
42
43    /// Whether to remove elements matching partial selectors
44    pub remove_partial_selectors: bool,
45}
46
47impl Default for TrekOptions {
48    fn default() -> Self {
49        Self {
50            debug: false,
51            url: None,
52            output: OutputOptions {
53                markdown: false,
54                separate_markdown: false,
55            },
56            removal: RemovalOptions {
57                remove_exact_selectors: true,
58                remove_partial_selectors: true,
59            },
60        }
61    }
62}
63
64/// Metadata extracted from the document
65#[derive(Debug, Clone, Default, Serialize, Deserialize)]
66#[serde(rename_all = "camelCase")]
67pub struct TrekMetadata {
68    /// Page title
69    pub title: String,
70
71    /// Page description
72    pub description: String,
73
74    /// Domain of the page
75    pub domain: String,
76
77    /// Favicon URL
78    pub favicon: String,
79
80    /// Main image URL
81    pub image: String,
82
83    /// Parse time in milliseconds
84    pub parse_time: u64,
85
86    /// Published date
87    pub published: String,
88
89    /// Author name
90    pub author: String,
91
92    /// Site name
93    pub site: String,
94
95    /// Schema.org data
96    pub schema_org_data: Vec<serde_json::Value>,
97
98    /// Word count
99    pub word_count: usize,
100
101    /// Mini App embed data from fc:frame meta tag
102    pub mini_app_embed: Option<MiniAppEmbed>,
103}
104
105/// Meta tag information
106#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(rename_all = "camelCase")]
108pub struct MetaTagItem {
109    /// Meta tag name attribute
110    pub name: Option<String>,
111
112    /// Meta tag property attribute
113    pub property: Option<String>,
114
115    /// Meta tag content
116    pub content: String,
117}
118
119/// Response from Trek parsing
120#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct TrekResponse {
123    /// Extracted HTML content
124    pub content: String,
125
126    /// Extracted content as Markdown (if requested)
127    pub content_markdown: Option<String>,
128
129    /// Type of extractor used (if any)
130    pub extractor_type: Option<String>,
131
132    /// Meta tags found in the document
133    pub meta_tags: Vec<MetaTagItem>,
134
135    /// All metadata fields
136    #[serde(flatten)]
137    pub metadata: TrekMetadata,
138}
139
140/// Variables extracted by site-specific extractors
141pub type ExtractorVariables = HashMap<String, String>;
142
143/// Content extracted by site-specific extractors
144#[derive(Debug, Clone, Default)]
145pub struct ExtractedContent {
146    /// Title override
147    pub title: Option<String>,
148
149    /// Author override
150    pub author: Option<String>,
151
152    /// Published date override
153    pub published: Option<String>,
154
155    /// Text content
156    pub content: Option<String>,
157
158    /// HTML content
159    pub content_html: Option<String>,
160
161    /// Additional variables
162    pub variables: Option<ExtractorVariables>,
163}
164
165/// Mini App action type
166#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
167#[serde(rename_all = "snake_case")]
168pub enum MiniAppActionType {
169    LaunchFrame,
170    ViewToken,
171}
172
173/// Mini App action
174#[derive(Debug, Clone, Serialize, Deserialize)]
175#[serde(rename_all = "camelCase")]
176pub struct MiniAppAction {
177    /// Action type
178    #[serde(rename = "type")]
179    pub action_type: MiniAppActionType,
180
181    /// App URL to open
182    pub url: Option<String>,
183
184    /// Name of the application
185    pub name: Option<String>,
186
187    /// URL of image to show on loading screen
188    pub splash_image_url: Option<String>,
189
190    /// Hex color code to use on loading screen
191    pub splash_background_color: Option<String>,
192}
193
194/// Mini App button
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(rename_all = "camelCase")]
197pub struct MiniAppButton {
198    /// Mini App name
199    pub title: String,
200
201    /// Button action
202    pub action: MiniAppAction,
203}
204
205/// Mini App embed
206#[derive(Debug, Clone, Serialize, Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct MiniAppEmbed {
209    /// Version of the embed
210    pub version: String,
211
212    /// Image URL for the embed
213    pub image_url: String,
214
215    /// Button configuration
216    pub button: MiniAppButton,
217}