슬러그 생성기
텍스트를 URL 친화적인 슬러그로 변환.
슬러그 생성기는 제목이나 구문을 URL 친화적인 슬러그로 변환합니다. 슬러그는 특수 문자나 공백이 없는 소문자, 하이픈으로 구분된 문자열입니다. 예를 들어, "나의 첫 블로그 포스트!"는 "나의-첫-블로그-포스트"가 됩니다.
제목이나 구문을 입력하면 도구가 즉시 깨끗한 슬러그를 생성합니다. 변환 과정은 악센트와 발음 구별 기호를 제거하고, 모든 문자를 소문자로 변환하며, 공백과 구두점을 하이픈으로 교체하고, 영숫자나 하이픈이 아닌 나머지 문자를 제거합니다.
잘 만들어진 슬러그는 URL을 읽기 쉽고 페이지 주제와 관련성 있게 만들어 SEO를 향상시킵니다. 검색 엔진은 URL의 단어를 관련성 신호로 처리합니다. 슬러그를 간결하게 유지하고 가능하면 관사와 전치사를 생략하세요.
자주 묻는 질문
코드 구현
import re
import unicodedata
def slugify(text: str, separator: str = "-") -> str:
"""Convert text to a URL-friendly slug."""
# Normalize unicode: decompose accented chars (é → e + combining accent)
text = unicodedata.normalize("NFKD", text)
# Encode to ASCII bytes, ignore errors (drops non-ASCII)
text = text.encode("ascii", "ignore").decode("ascii")
# Lowercase
text = text.lower()
# Replace any non-alphanumeric characters with the separator
text = re.sub(r"[^a-z0-9]+", separator, text)
# Strip leading/trailing separators
text = text.strip(separator)
return text
# Examples
print(slugify("Hello, World!")) # hello-world
print(slugify(" Multiple Spaces ")) # multiple-spaces
print(slugify("Héllo Wörld")) # hello-world
print(slugify("C++ is awesome!")) # c-is-awesome
print(slugify("Blog Post #42")) # blog-post-42
print(slugify("Hello World", "_")) # hello_world (underscore)
# For Python web frameworks like Django, use built-in slugify:
# from django.utils.text import slugify
# slugify("Hello, World!") # "hello-world"Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.