This commit is contained in:
2025-04-03 12:31:01 +02:00
parent 868c870bf0
commit e16d4270c0
9 changed files with 61 additions and 114 deletions

View File

@@ -0,0 +1,43 @@
// String manipulation functions that will be exposed to Tera templates
// Capitalize the first letter of each word
fn capitalize(text) {
if text.len == 0 {
return "";
}
let words = text.split(" ");
let result = [];
for word in words {
if word.len > 0 {
let first_char = word.substr(0, 1).to_upper();
let rest = word.substr(1, word.len - 1);
result.push(first_char + rest);
} else {
result.push("");
}
}
result.join(" ")
}
// Truncate text with ellipsis
fn truncate(text, max_length) {
if text.len <= max_length {
return text;
}
text.substr(0, max_length - 3) + "..."
}
// Convert text to slug format (lowercase, hyphens)
fn slugify(text) {
let slug = text.to_lower();
slug = slug.replace(" ", "-");
slug = slug.replace(".", "");
slug = slug.replace(",", "");
slug = slug.replace("!", "");
slug = slug.replace("?", "");
slug
}