Trait blog_tools::Blog
source · pub trait Blog: Clone {
Show 16 methods
// Required methods
fn create<T: AsRef<Path>>(
blog: T,
toc_generation_func: Option<&dyn Fn(&Node) -> String>,
preview_chars: Option<usize>,
) -> Result<Self, BlogError>;
fn get_title(&self) -> String;
fn get_date_listed(&self) -> NaiveDate;
fn get_description(&self) -> Option<String>;
fn get_html(&self) -> String;
fn get_full_slug(&self) -> String;
fn get_part_slug(&self) -> String;
fn get_tags(&self) -> Vec<String>;
fn get_table_of_contents(&self) -> Option<String>;
fn get_keywords(&self) -> Option<Vec<String>>;
fn get_canonicle_link(&self) -> Option<String>;
fn get_author_name(&self) -> Option<String>;
fn get_author_webpage(&self) -> Option<String>;
fn get_preview(&self) -> String;
fn get_last_modified(&self) -> Option<NaiveDate>;
fn get_priority(&self) -> Option<f64>;
}Expand description
Primary trait that describes a single blog post. Any struct which derives this is intended to be converted into a JSON with serde and used in a template. You can of course use any of these other methods for any purpose in the blog
Required Methods§
sourcefn create<T: AsRef<Path>>(
blog: T,
toc_generation_func: Option<&dyn Fn(&Node) -> String>,
preview_chars: Option<usize>,
) -> Result<Self, BlogError>
fn create<T: AsRef<Path>>( blog: T, toc_generation_func: Option<&dyn Fn(&Node) -> String>, preview_chars: Option<usize>, ) -> Result<Self, BlogError>
Create a blog post
Parameters
-
blog: Path to the root of the blog For this to work, you should have a folder, for instance,blogwhich serves as the root. Within this folder, you must have the following structure- blog
- 2023
- 2023-01-01
- my_first_blog.json
- my_first_blog.md
- (other folders)
- 2023-01-01
- 2023
- blog
-
toc_generation_func- A function which parses a blog and generates a table of contents. Optional. -
preview_chars- number of chars to be taken in the preview of the blog. Default is 320.
sourcefn get_date_listed(&self) -> NaiveDate
fn get_date_listed(&self) -> NaiveDate
Get the original publication date
sourcefn get_description(&self) -> Option<String>
fn get_description(&self) -> Option<String>
Get the SEO description
sourcefn get_full_slug(&self) -> String
fn get_full_slug(&self) -> String
Get the full slug - this would be e.g. 2024-03-19/my-blog.
In the JSON, you should NOT include the date in the slug
sourcefn get_part_slug(&self) -> String
fn get_part_slug(&self) -> String
Get the partial slug of the blog. This would be the slug field from the
JSON
Get a list of tags for the blog
sourcefn get_table_of_contents(&self) -> Option<String>
fn get_table_of_contents(&self) -> Option<String>
Get the table of contents. Only present if a table of contents funciton was provided
sourcefn get_keywords(&self) -> Option<Vec<String>>
fn get_keywords(&self) -> Option<Vec<String>>
Get keywords
sourcefn get_canonicle_link(&self) -> Option<String>
fn get_canonicle_link(&self) -> Option<String>
Get the canonicle link
Get the author
Get the author webpage
sourcefn get_preview(&self) -> String
fn get_preview(&self) -> String
Get the blog preview. This is the first few hundred characters of the blog, useful for an index page
sourcefn get_last_modified(&self) -> Option<NaiveDate>
fn get_last_modified(&self) -> Option<NaiveDate>
Get the last modified date, mostly use for sitemaps. This is not the original publication date
sourcefn get_priority(&self) -> Option<f64>
fn get_priority(&self) -> Option<f64>
Get the priority for the sitemap