Fixed multi component i18n strings and added serverside impressum
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
@@ -142,3 +142,105 @@ pub fn HR() -> Element {
|
||||
hr { class:"h-px my-8 bg-gray-200 border-0 dark:bg-gray-700"}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Props)]
|
||||
pub struct BoldingProp {
|
||||
authors: String,
|
||||
patterns: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn Bolding(prop: BoldingProp) -> Element {
|
||||
let mut elements = vec![];
|
||||
let mut last_index = 0;
|
||||
let authors_text = &prop.authors;
|
||||
|
||||
let mut matches: Vec<(usize, usize, &str)> = vec![];
|
||||
|
||||
for pattern in &prop.patterns {
|
||||
for (start, _) in authors_text.match_indices(pattern) {
|
||||
matches.push((start, start + pattern.len(), pattern));
|
||||
}
|
||||
}
|
||||
|
||||
matches.sort_by_key(|(start, _, _)| *start);
|
||||
|
||||
for (start, end, matched_pattern) in matches {
|
||||
if last_index < start {
|
||||
elements.push(rsx! { "{&authors_text[last_index..start]}" });
|
||||
}
|
||||
|
||||
elements.push(rsx! { b { "{matched_pattern}" } });
|
||||
last_index = end;
|
||||
}
|
||||
|
||||
if last_index < authors_text.len() {
|
||||
elements.push(rsx! { "{&authors_text[last_index..]}" });
|
||||
}
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
P {
|
||||
for i in elements {
|
||||
{i}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Props)]
|
||||
pub struct UrlingProp {
|
||||
#[props(default = "".to_string())]
|
||||
class: String,
|
||||
text: String,
|
||||
patterns: Vec<String>,
|
||||
url: String,
|
||||
#[props(default = true)]
|
||||
new_tab: bool,
|
||||
}
|
||||
|
||||
pub fn Urling(prop: UrlingProp) -> Element {
|
||||
let mut elements = vec![];
|
||||
let mut last_index = 0;
|
||||
let text = &prop.text;
|
||||
|
||||
let mut matches: Vec<(usize, usize, &str)> = vec![];
|
||||
|
||||
for pattern in &prop.patterns {
|
||||
for (start, _) in text.match_indices(pattern) {
|
||||
matches.push((start, start + pattern.len(), pattern));
|
||||
}
|
||||
}
|
||||
|
||||
matches.sort_by_key(|(start, _, _)| *start);
|
||||
|
||||
for (start, end, matched_pattern) in matches {
|
||||
if last_index < start {
|
||||
elements.push(rsx! { "{&text[last_index..start]}" });
|
||||
}
|
||||
|
||||
elements.push(rsx! {
|
||||
Link {
|
||||
class: "{prop.class}",
|
||||
to: "{prop.url}",
|
||||
new_tab: prop.new_tab,
|
||||
"{matched_pattern}"
|
||||
}
|
||||
});
|
||||
last_index = end;
|
||||
}
|
||||
|
||||
if last_index < text.len() {
|
||||
elements.push(rsx! { "{&text[last_index..]}" });
|
||||
}
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
P {
|
||||
for i in elements {
|
||||
{i}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user