update
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2025-02-09 00:07:28 +01:00
parent b530ae4dc3
commit 3e77ec5008
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
11 changed files with 476 additions and 346 deletions

View file

@ -1,6 +1,6 @@
use std::{io::Read, path::PathBuf};
use based::request::RequestContext;
use based::{request::RequestContext, ui::components::Shell};
use maud::html;
use crate::{blacklist::check_blacklist, conf::get_config, render_page};
@ -52,12 +52,17 @@ impl Document {
///
/// # Returns
/// An `Option` containing the rendered content as a string, or `None` if nothing could be rendered.
pub async fn render_local(&self, version: Option<String>) -> Option<String> {
pub async fn render_local(&self, version: Option<String>, shell: &Shell) -> Option<String> {
if check_blacklist(&self.domain) {
let content = html! {
h3 { "This site is blacklisted" };
};
return Some(render_page(content, RequestContext::default()).await.1 .1);
return Some(
render_page(content, RequestContext::default(), shell)
.await
.1
.1,
);
}
let mut file_path = self.doc_dir();
@ -100,6 +105,20 @@ impl Document {
file_path
}
fn latest_time_since(&self) -> Option<usize> {
if let Some(t_str) = self.versions().first() {
let given_date = chrono::NaiveDate::parse_from_str(t_str, "%Y-%m-%d")
.expect("Invalid date format. Expected yyyy-mm-dd.");
let today = chrono::Local::now().date_naive();
let duration = today.signed_duration_since(given_date);
return Some(duration.num_days() as usize);
}
None
}
/// Retrieves available versions of the document.
///
/// # Returns

View file

@ -28,6 +28,7 @@ pub fn read_dir(dir: &PathBuf) -> Vec<String> {
/// Rewrite all URLs in `input` to the format `/s/<domain>/<path..>`
fn internalize_urls(input: &str, base: &str) -> String {
// todo : fix regex, domains without path are not captured
let url_pattern = r#"(\ |"|')(?:(<?)(https?:\/\/([a-zA-Z0-9.-]+))?(\/[\w./-]*))"#;
let re = regex::Regex::new(url_pattern).unwrap();