[−][src]Struct bloguen::ops::BloguePost
Information about a blogue post.
Use list()
to find valid post directories, then use new()
to get the post data.
A correct post directory name is #+. YYYY-MM-DD [HH-MM[-SS]] name
.
Fields
source_dir: (String, PathBuf)
Directory containing the post data.
number: (usize, String)
Post number.
name: String
Post name.
datetime: DateTime<LocalOffset>
Date & time of posting.
Methods
impl BloguePost
[src]
pub fn list(within: &(String, PathBuf)) -> Result<Vec<(String, PathBuf)>, Error>
[src]
List correct post directories in the specified directory.
A correct post directory name is #+. YYYY-MM-DD [HH-MM[-SS]] name
.
Examples:
For the following directory tree:
posts/
temp/
001. 2018-01-08 16-52 The venture into crocheting/
002. 2018-01-08 acquiescence.md
003. 2018-02-05 release-front - release front-end/
004. stir plate/
blogue.toml
The following holds:
let root: PathBuf = /* obtained elsewhere */; let posts = BloguePost::list(&("$ROOT/posts/".to_string(), root.join("posts"))).unwrap(); assert_eq!(&posts[..], &[("$ROOT/posts/001. 2018-01-08 16-52 The venture into crocheting/".to_string(), root.join("posts").join("001. 2018-01-08 16-52 The venture into crocheting")), ("$ROOT/posts/003. 2018-02-05 release-front - release front-end/".to_string(), root.join("posts").join("003. 2018-02-05 release-front - release front-end"))][..]);
pub fn new(wher: (String, PathBuf)) -> Result<BloguePost, Error>
[src]
Read post data into a BloguePost
instance.
Examples:
let root: PathBuf = /* obtained elsewhere */; let dir = ("$ROOT/posts/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("posts").join("01. 2018-01-08 16-52 The venture into crocheting")); assert_eq!(BloguePost::new(dir.clone()), Ok(BloguePost { source_dir: dir, number: (1, "01".to_string()), name: "The venture into crocheting".to_string(), datetime: LocalOffset.ymd(2018, 01, 08).and_hms(16, 52, 00), })); let dir = ("$ROOT/posts/003. 2018-02-05 release-front - release front-end".to_string(), root.join("posts").join("003. 2018-02-05 release-front - release front-end")); assert_eq!(BloguePost::new(dir.clone()), Ok(BloguePost { source_dir: dir, number: (3, "003".to_string()), name: "release-front - release front-end".to_string(), datetime: LocalOffset.ymd(2018, 02, 05).and_hms(23, 24, 43), })); let dir = ("$ROOT/posts/004. stir plate".to_string(), root.join("posts").join("004. stir plate")); assert_eq!(BloguePost::new(dir.clone()), Err(Error::Parse { tp: "post directory filename", wher: "blogue post".into(), more: "not found".into(), }));
pub fn generate(
&self,
into: &(String, PathBuf),
alt_output: Option<&mut dyn Write>,
center_output: Option<(&str, &mut dyn Write)>,
asset_override: Option<&str>,
post_header: &str,
post_footer: &str,
blog_name: &str,
language: &LanguageTag,
author: &str,
spec_tags: &[TagName],
free_tags: &[TagName],
post_data: &BTreeMap<String, String>,
global_data: &BTreeMap<String, String>,
post_styles: &[StyleElement],
global_styles: &[StyleElement],
post_scripts: &[ScriptElement],
global_scripts: &[ScriptElement]
) -> Result<Vec<String>, Error>
[src]
&self,
into: &(String, PathBuf),
alt_output: Option<&mut dyn Write>,
center_output: Option<(&str, &mut dyn Write)>,
asset_override: Option<&str>,
post_header: &str,
post_footer: &str,
blog_name: &str,
language: &LanguageTag,
author: &str,
spec_tags: &[TagName],
free_tags: &[TagName],
post_data: &BTreeMap<String, String>,
global_data: &BTreeMap<String, String>,
post_styles: &[StyleElement],
global_styles: &[StyleElement],
post_scripts: &[ScriptElement],
global_scripts: &[ScriptElement]
) -> Result<Vec<String>, Error>
Generate an HTML output from the post into the specified output directory.
Alternate output is filled with the HTML-formatted post Markdown.
Center output is filled with the specified template filled-out with additional post_content
data element
consisting of the HTML-formatted post Markdown.
Returns: set of links in the markdown source.
Examples
Given the following:
src/
01. 2018-01-08 16-52 The venture into crocheting/
post.md
The following holds:
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); assert!(post.generate(&("$ROOT/out/".to_string(), root.join("out")), None, None, None, "header", "footer", "Блогг", &LANGUAGE_EN_GB, "autheur", &[], &[], &Default::default(), &Default::default(), &[], &[], &[], &[]).is_ok()); assert!(root.join("out").join("posts") .join("01. 2018-01-08 16-52-00 The venture into crocheting.html").is_file());
pub fn create_machine_output(
&self,
into: &(String, PathBuf),
subpath: &str,
kind: &MachineDataKind
) -> Result<File, Error>
[src]
&self,
into: &(String, PathBuf),
subpath: &str,
kind: &MachineDataKind
) -> Result<File, Error>
Generate machine output of the specified kind from the post into the specified subpath in the specified output directory.
Examples
Given the following:
src/
01. 2018-01-08 16-52 The venture into crocheting/
post.md
The following holds:
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); let machine_output_file = post.create_machine_output(&("$ROOT/out/".to_string(), root.join("out")), "machine/", &MachineDataKind::Json).unwrap(); assert!(root.join("out").join("machine") .join("01. 2018-01-08 16-52-00 The venture into crocheting.json").is_file());
pub fn generate_machine<T: Write>(
&self,
into: &mut T,
kind: &MachineDataKind,
blog_name: &str,
language: &LanguageTag,
author: &str,
spec_tags: &[TagName],
free_tags: &[TagName],
post_data: &BTreeMap<String, String>,
global_data: &BTreeMap<String, String>,
post_styles: &[StyleElement],
global_styles: &[StyleElement],
post_scripts: &[ScriptElement],
global_scripts: &[ScriptElement]
) -> Result<(), Error>
[src]
&self,
into: &mut T,
kind: &MachineDataKind,
blog_name: &str,
language: &LanguageTag,
author: &str,
spec_tags: &[TagName],
free_tags: &[TagName],
post_data: &BTreeMap<String, String>,
global_data: &BTreeMap<String, String>,
post_styles: &[StyleElement],
global_styles: &[StyleElement],
post_scripts: &[ScriptElement],
global_scripts: &[ScriptElement]
) -> Result<(), Error>
Generate machine output of the specified kind from the post into the specified subpath in the specified output directory.
Examples
Given the following:
src/
01. 2018-01-08 16-52 The venture into crocheting/
post.md
The following holds:
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); let mut out = vec![]; assert!(post.generate_machine(&mut out, &MachineDataKind::Json, "Блогг", &LANGUAGE_EN_GB, "autheur", &[], &[], &Default::default(), &Default::default(), &[], &[], &[], &[]).is_ok()); assert!(!out.is_empty()); assert!(str::from_utf8(&out).unwrap().contains("The venture into crocheting")); // &c.
pub fn generate_feed_head<T: Write>(
&self,
into: &mut T,
tp: &FeedType,
fname: &str,
language: &LanguageTag,
author: &str
) -> Result<(), Error>
[src]
&self,
into: &mut T,
tp: &FeedType,
fname: &str,
language: &LanguageTag,
author: &str
) -> Result<(), Error>
Generate header for this post of the specified feed type.
Examples
Given the following:
src/
01. 2018-01-08 16-52 The venture into crocheting/
post.md
The following holds:
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); let mut out = vec![]; assert!(post.generate_feed_head(&mut out, &FeedType::Rss, "feeds/rss.xml", &LANGUAGE_EN_GB, "nabijaczleweli").is_ok()); let out = String::from_utf8(out).unwrap(); let pubdate_local_rfc2822 = /* extracted from output's pubDate tag */; assert_eq!(out, format!(r###" <item> <title>The venture into crocheting</title> <author>nabijaczleweli</author> <link>../posts/01. 2018-01-08 16-52-00 The venture into crocheting.html</link> <pubDate>{}</pubDate> <guid>01. 2018-01-08 16-52-00 The venture into crocheting</guid> <description> "###, pubdate_local_rfc2822));
pub fn generate_feed_foot<T: Write>(
&self,
into: &mut T,
tp: &FeedType
) -> Result<(), Error>
[src]
&self,
into: &mut T,
tp: &FeedType
) -> Result<(), Error>
Generate footer for this post of the specified feed type.
Examples
Given the following:
src/
01. 2018-01-08 16-52 The venture into crocheting/
post.md
The following holds:
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); let mut out = vec![]; assert!(post.generate_feed_foot(&mut out, &FeedType::Rss).is_ok()); assert_eq!(String::from_utf8(out).unwrap(), r###" </description> </item> "###);
pub fn normalised_name(&self) -> String
[src]
Get a normalised output name for this post.
Examples
let root: PathBuf = /* obtained elsewhere */; let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); assert_eq!(post.normalised_name(), "01. 2018-01-08 16-52-00 The venture into crocheting");
pub fn copy_asset(
&self,
into: &(String, PathBuf),
asset_override: Option<&str>,
link: &str
) -> Result<bool, Error>
[src]
&self,
into: &(String, PathBuf),
asset_override: Option<&str>,
link: &str
) -> Result<bool, Error>
Copy a referenced asset to the output directory.
Returns Ok(b)
, where b
is whether the asset existed and was copied, Err(_)
for a copying error.
Examples
let root: PathBuf = /* obtained elsewhere */; let out_pair = ("$ROOT/out/".to_string(), root.join("out")); let post = BloguePost::new(("$ROOT/src/01. 2018-01-08 16-52 The venture into crocheting".to_string(), root.join("src").join("01. 2018-01-08 16-52 The venture into crocheting"))).unwrap(); for link in post.generate(&out_pair, None, None, None, "header", "footer", "Блогг", &LANGUAGE_EN_GB, "autheur", &[], &[], &Default::default(), &Default::default(), &[], &[], &[], &[]) .unwrap().into_iter().filter(|l| util::is_asset_link(l)) { let link = percent_decode(link.as_bytes()).decode_utf8().unwrap(); println!("Copying {}: {:?}", link, post.copy_asset(&out_pair, None, &link)); }
Trait Implementations
impl Eq for BloguePost
[src]
impl Clone for BloguePost
[src]
fn clone(&self) -> BloguePost
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl PartialOrd<BloguePost> for BloguePost
[src]
fn partial_cmp(&self, other: &BloguePost) -> Option<Ordering>
[src]
fn lt(&self, other: &BloguePost) -> bool
[src]
fn le(&self, other: &BloguePost) -> bool
[src]
fn gt(&self, other: &BloguePost) -> bool
[src]
fn ge(&self, other: &BloguePost) -> bool
[src]
impl PartialEq<BloguePost> for BloguePost
[src]
fn eq(&self, other: &BloguePost) -> bool
[src]
fn ne(&self, other: &BloguePost) -> bool
[src]
impl Ord for BloguePost
[src]
fn cmp(&self, other: &BloguePost) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl Hash for BloguePost
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Debug for BloguePost
[src]
Auto Trait Implementations
impl Send for BloguePost
impl Unpin for BloguePost
impl Sync for BloguePost
impl UnwindSafe for BloguePost
impl RefUnwindSafe for BloguePost
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,