use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrekOptions {
pub debug: bool,
pub url: Option<String>,
#[serde(flatten)]
pub output: OutputOptions,
#[serde(flatten)]
pub removal: RemovalOptions,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OutputOptions {
pub markdown: bool,
pub separate_markdown: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemovalOptions {
pub remove_exact_selectors: bool,
pub remove_partial_selectors: bool,
}
impl Default for TrekOptions {
fn default() -> Self {
Self {
debug: false,
url: None,
output: OutputOptions {
markdown: false,
separate_markdown: false,
},
removal: RemovalOptions {
remove_exact_selectors: true,
remove_partial_selectors: true,
},
}
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrekMetadata {
pub title: String,
pub description: String,
pub domain: String,
pub favicon: String,
pub image: String,
pub parse_time: u64,
pub published: String,
pub author: String,
pub site: String,
pub schema_org_data: Vec<serde_json::Value>,
pub word_count: usize,
pub mini_app_embed: Option<MiniAppEmbed>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetaTagItem {
pub name: Option<String>,
pub property: Option<String>,
pub content: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrekResponse {
pub content: String,
pub content_markdown: Option<String>,
pub extractor_type: Option<String>,
pub meta_tags: Vec<MetaTagItem>,
#[serde(flatten)]
pub metadata: TrekMetadata,
}
pub type ExtractorVariables = HashMap<String, String>;
#[derive(Debug, Clone, Default)]
pub struct ExtractedContent {
pub title: Option<String>,
pub author: Option<String>,
pub published: Option<String>,
pub content: Option<String>,
pub content_html: Option<String>,
pub variables: Option<ExtractorVariables>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MiniAppActionType {
LaunchFrame,
ViewToken,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MiniAppAction {
#[serde(rename = "type")]
pub action_type: MiniAppActionType,
pub url: Option<String>,
pub name: Option<String>,
pub splash_image_url: Option<String>,
pub splash_background_color: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MiniAppButton {
pub title: String,
pub action: MiniAppAction,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MiniAppEmbed {
pub version: String,
pub image_url: String,
pub button: MiniAppButton,
}