Skip to content

Commit

Permalink
Merge pull request #40 from TomJGooding/fix-remove-punctuation-from-q…
Browse files Browse the repository at this point in the history
…uestion-slug

fix: remove punctuation from question slug
  • Loading branch information
willmcgugan authored Jan 31, 2024
2 parents 9d4ca40 + ee0b1dd commit bf3f9ef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/faqtory/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import string
from pathlib import Path
from typing import List

Expand All @@ -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":
Expand Down

0 comments on commit bf3f9ef

Please sign in to comment.