Store dates in the document head

This commit is contained in:
Olivier 'reivilibre' 2022-03-28 22:24:36 +01:00
parent 7dc2369dd2
commit 3bfd192c28
3 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,8 @@ pub struct DenseHead {
pub language: String, pub language: String,
/// URL to icon of the page. May be empty if none were discovered. /// URL to icon of the page. May be empty if none were discovered.
pub icon: String, pub icon: String,
/// Datetime of publication (or creation, as a fallback), in seconds since the epoch.
pub datetime: Option<i64>,
} }
impl DenseHead { impl DenseHead {

View File

@ -236,7 +236,7 @@ impl PageExtractionServiceInternal {
} }
} }
find_page_metadata(root_node.clone())?; let metadata = find_page_metadata(root_node.clone())?;
let mut readability = let mut readability =
quickpeep_moz_readability::Readability::new_from_node(root_node.clone()); quickpeep_moz_readability::Readability::new_from_node(root_node.clone());
@ -249,6 +249,11 @@ impl PageExtractionServiceInternal {
title = readability.metadata.title().to_owned(); title = readability.metadata.title().to_owned();
} }
let datetime = metadata
.publication_date
.or(metadata.creation_date)
.map(|dt| dt.timestamp());
let mut document = DenseDocument { let mut document = DenseDocument {
head: DenseHead { head: DenseHead {
title, title,
@ -256,6 +261,7 @@ impl PageExtractionServiceInternal {
icon: icon icon: icon
.map(|url| url.as_str().to_owned()) .map(|url| url.as_str().to_owned())
.unwrap_or(String::with_capacity(0)), .unwrap_or(String::with_capacity(0)),
datetime,
}, },
body_content: Vec::with_capacity(0), body_content: Vec::with_capacity(0),
body_remainder: Vec::with_capacity(0), body_remainder: Vec::with_capacity(0),