mirror of
https://github.com/Xevion/xevion.dev.git
synced 2026-01-31 04:26:43 -06:00
fix: improve slugify to handle periods and use filter_map
This commit is contained in:
+6
-5
@@ -66,13 +66,13 @@ pub async fn health_check(pool: &PgPool) -> Result<(), sqlx::Error> {
|
|||||||
pub fn slugify(text: &str) -> String {
|
pub fn slugify(text: &str) -> String {
|
||||||
text.to_lowercase()
|
text.to_lowercase()
|
||||||
.chars()
|
.chars()
|
||||||
.map(|c| {
|
.filter_map(|c| {
|
||||||
if c.is_alphanumeric() {
|
if c.is_alphanumeric() {
|
||||||
c
|
Some(c)
|
||||||
} else if c.is_whitespace() || c == '-' || c == '_' {
|
} else if c.is_whitespace() || c == '-' || c == '_' || c == '.' {
|
||||||
'-'
|
Some('-')
|
||||||
} else {
|
} else {
|
||||||
'\0'
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
@@ -85,6 +85,7 @@ pub fn slugify(text: &str) -> String {
|
|||||||
/// Project status enum
|
/// Project status enum
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, serde::Serialize, serde::Deserialize)]
|
||||||
#[sqlx(type_name = "project_status", rename_all = "lowercase")]
|
#[sqlx(type_name = "project_status", rename_all = "lowercase")]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum ProjectStatus {
|
pub enum ProjectStatus {
|
||||||
Active,
|
Active,
|
||||||
Maintained,
|
Maintained,
|
||||||
|
|||||||
Reference in New Issue
Block a user