parent
a4a60c86df
commit
dc10052c16
2 changed files with 34 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{io::Read, path::PathBuf};
|
||||
use std::{collections::HashSet, io::Read, path::PathBuf};
|
||||
|
||||
use based::{request::RequestContext, result::LogAndIgnore};
|
||||
use maud::html;
|
||||
|
@ -39,6 +39,23 @@ fn internalize_urls(input: &str) -> String {
|
|||
.to_string()
|
||||
}
|
||||
|
||||
/// Extract all domains
|
||||
pub fn extract_domains(input: &str) -> Vec<String> {
|
||||
let url_pattern = r"https?://([a-zA-Z0-9.-]+)(/[\w./-]*)?";
|
||||
let re = regex::Regex::new(url_pattern).unwrap();
|
||||
|
||||
let mut domains = HashSet::new();
|
||||
for caps in re.captures_iter(input) {
|
||||
let domain = caps[1].trim_start_matches("www.");
|
||||
domains.insert(domain.to_string());
|
||||
}
|
||||
|
||||
let mut domains: Vec<_> = domains.into_iter().collect();
|
||||
domains.sort();
|
||||
|
||||
domains
|
||||
}
|
||||
|
||||
/// Represents a directory containg archived websites
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WebsiteArchive {
|
||||
|
|
|
@ -15,7 +15,7 @@ use serde_json::json;
|
|||
|
||||
use webarc::{
|
||||
ai::{generate_embedding, remove_data_urls, EmbedStore, SearchResult},
|
||||
archive::WebsiteArchive,
|
||||
archive::{extract_domains, WebsiteArchive},
|
||||
conf::get_config,
|
||||
render_page,
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ pub async fn domain_info_route(
|
|||
let (path_entries, is_doc) = domain.paths(paths.to_str().unwrap());
|
||||
let path_seperations: Vec<&str> = paths.to_str().unwrap().split('/').collect();
|
||||
|
||||
// TODO : Show domains beeing linked on the page
|
||||
let domains = extract_domains(&document.render_local(None).await.unwrap_or_default());
|
||||
|
||||
let content = html! {
|
||||
h2 class="text-xl font-bold mb-4 flex items-center" {
|
||||
|
@ -134,6 +134,20 @@ pub async fn domain_info_route(
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
@if !domains.is_empty() {
|
||||
div class="max-w-md mx-auto p-4 bg-neutral-900 rounded-lg shadow-md" {
|
||||
h3 class="font-bold mb-2" { "Domains linked on this page:" };
|
||||
ul class="space-y-2 p-4" {
|
||||
@for domain in domains {
|
||||
a href=(format!("/d/{domain}")) class="flex items-center gap-2 p-3 border bg-neutral-800 rounded hover:shadow-lg transition" {
|
||||
(favicon(&domain));
|
||||
span class="font-medium" { (domain) };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
render_page(content, ctx).await
|
||||
|
|
Loading…
Add table
Reference in a new issue