From ee0b1dd1024b7c1a00e0927755c4ec4cda44c6e5 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:18:10 +0000 Subject: [PATCH] fix: remove punctuation from question slug --- src/faqtory/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/faqtory/models.py b/src/faqtory/models.py index 1437da8..575a24a 100644 --- a/src/faqtory/models.py +++ b/src/faqtory/models.py @@ -1,5 +1,6 @@ from __future__ import annotations +import string from pathlib import Path from typing import List @@ -24,7 +25,12 @@ def slug(self) -> str: Returns: str: Slug suitable for use in an anchor. """ - return self.title.lower().replace(" ", "-").replace("?", "").replace(".", "") + chars_to_remove = string.punctuation + chars_to_remove = chars_to_remove.replace("-", "").replace("_", "") + slug = self.title.lower() + slug = slug.translate(str.maketrans("", "", chars_to_remove)) + slug = slug.replace(" ", "-") + return slug @classmethod def read(cls, path: Path) -> "Question":