슬러그 생성기
모든 텍스트를 깔끔한 URL 친화적 슬러그로 변환
입력 텍스트
슬러그
URL 슬러그란 무엇인가?
URL 슬러그는 웹 주소에서 특정 페이지를 사람이 읽을 수 있는 형태로 식별하는 부분입니다. https://example.com/blog/my-first-post라는 URL에서 슬러그는 my-first-post입니다. 슬러그 생성기는 페이지 제목이나 설명을 소문자, 숫자, 하이픈(또는 다른 선택한 구분 기호)만으로 구성된 문자열로 변환합니다. 이 과정에서 공백을 제거하고, 악센트와 발음 기호를 제거하며, 특수 문자를 삭제하고, 공백을 단일 구분 기호로 정규화합니다.
슬러그 생성은 콘텐츠 관리 시스템, 정적 사이트 생성기, 블로그 플랫폼, 그리고 사용자 입력에서 URL을 파생하는 모든 애플리케이션의 표준 단계입니다. WordPress, Ghost, Hugo, Next.js, Django는 모두 슬러그 생성 로직을 포함하고 있는데, 읽기 쉬운 URL이 사용성과 검색 엔진 최적화 모두를 향상시키기 때문입니다. 잘 구성된 슬러그는 링크를 클릭하기 전에 페이지의 내용이 무엇인지 사용자에게 알려줍니다.
"슬러그"라는 용어는 신문 출판에서 유래했으며, 제작 과정에서 기사를 식별하는 짧은 라벨을 가리켰습니다. 웹 개발에서 슬러그는 동일한 기능을 수행합니다. 더 긴 제목이나 이름에서 파생된 간결하고 고유한 URL 안전 식별자입니다. 슬러그는 프로그래밍적으로 파생되므로, 신뢰할 수 있는 슬러그 생성기는 모든 페이지와 로케일에서 일관성을 보장합니다.
이 슬러그 생성기를 사용해야 하는 이유
URL 슬러그를 수동으로 만드는 것은 오류가 발생하기 쉽습니다. 악센트 제거를 빠뜨리거나, 이중 하이픈을 남기거나, 유니코드 입력의 엣지 케이스를 놓치면 깨지거나 보기 흉한 URL이 생성될 수 있습니다. 이 도구는 그런 문제들을 자동으로 처리합니다.
슬러그 생성기 활용 사례
슬러그 생성 규칙 및 문자 처리
슬러그 생성은 예측 가능한 변환 순서를 따릅니다. 각 단계를 이해하면 예상치 못한 출력을 디버깅하거나 직접 slugify 함수를 구축하는 데 도움이 됩니다.
- 1. 유니코드 정규화 (NFD)결합 문자를 기본 문자 + 결합 마크로 분해합니다. 예를 들어 é (U+00E9)는 e + 결합 예음 악센트 (U+0301)가 됩니다. 이로써 다음 단계에서 발음 기호를 제거할 수 있습니다.
- 2. 발음 기호 제거유니코드 결합 발음 기호 블록(U+0300–U+036F)의 모든 문자를 제거합니다. 이 단계 후 café는 cafe가 되고 Ñ은 N이 됩니다.
- 3. 특수 문자 제거문자, 숫자, 공백, 하이픈이 아닌 모든 문자를 공백으로 교체합니다. 구두점, 기호, ASCII에 해당하는 값이 없는 문자가 삭제됩니다.
- 4. 공백 정리 및 축소앞뒤 공백을 제거한 후, 연속된 공백, 언더스코어, 하이픈을 선택한 단일 구분 기호로 축소합니다.
- 5. 대소문자 및 구분 기호 적용소문자로 변환하고(선택 사항) 선택한 구분 기호 문자(하이픈(-), 언더스코어(_), 점(.))로 단어를 연결합니다.
문자 변환 참고표
아래 표는 슬러그 생성 중 일반적인 문자들이 어떻게 처리되는지 보여줍니다:
| 입력 | 출력 | 적용 규칙 |
|---|---|---|
| Hello World | hello-world | Lowercase + space → hyphen |
| Café au Lait | cafe-au-lait | NFD normalization strips é → e |
| naïve résumé | naive-resume | Multiple diacritics removed |
| Price: $9.99! | price-9-99 | Symbols ($, !, :) removed |
| too many | too-many | Whitespace trimmed and collapsed |
| one--two___three | one-two-three | Mixed separators collapsed |
| Привет мир | privet-mir | Cyrillic (if transliteration) or removed |
| file_name.txt | file-name-txt | Dots and underscores replaced |
| React & Vue | react-vue | Ampersand removed |
| 2026-03-30 | 2026-03-30 | Digits and hyphens preserved |
코드 예시
인기 있는 언어와 프레임워크에서의 슬러그 생성 예시입니다. 각 예시는 유니코드 정규화, 발음 기호 제거, 구분 기호 삽입을 처리합니다.
function slugify(text, separator = '-') {
return text
.normalize('NFD') // decompose accented chars
.replace(/[\u0300-\u036f]/g, '') // strip diacritics
.toLowerCase()
.replace(/[^\w\s-]/g, ' ') // drop special chars
.trim()
.replace(/[\s_-]+/g, separator) // collapse whitespace → separator
// slugify('Café au Lait') → "cafe-au-lait"
// slugify('Hello World', '_') → "hello_world"
}
// Node.js alternative using the `slugify` npm package:
// npm install slugify
// const slugify = require('slugify')
// slugify('Hello World', { lower: true, strict: true }) → "hello-world"import re
import unicodedata
def slugify(text: str, separator: str = '-') -> str:
"""Convert text to a URL-safe slug."""
text = unicodedata.normalize('NFD', text)
text = text.encode('ascii', 'ignore').decode('ascii') # strip non-ASCII
text = text.lower()
text = re.sub(r'[^\w\s-]', ' ', text)
text = text.strip()
text = re.sub(r'[\s_-]+', separator, text)
return text
# slugify('Café au Lait') → "cafe-au-lait"
# slugify('Hello World', '_') → "hello_world"
# Alternative: python-slugify (pip install python-slugify)
# from slugify import slugify
# slugify('Café au Lait') → "cafe-au-lait"package main
import (
"regexp"
"strings"
"unicode"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/transform"
"golang.org/x/text/runes"
)
func slugify(text string) string {
// NFD normalize and strip diacritics
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
result, _, _ := transform.String(t, text)
result = strings.ToLower(result)
re := regexp.MustCompile(`[^\w\s-]+`)
result = re.ReplaceAllString(result, " ")
result = strings.TrimSpace(result)
re = regexp.MustCompile(`[\s_-]+`)
result = re.ReplaceAllString(result, "-")
return result
}
// slugify("Café au Lait") → "cafe-au-lait"
// slugify("Hello World") → "hello-world"function slugify(string $text, string $separator = '-'): string {
// Transliterate non-ASCII characters
$text = transliterator_transliterate(
'Any-Latin; Latin-ASCII; Lower()', $text
);
// Remove anything that is not a word char, space, or hyphen
$text = preg_replace('/[^\w\s-]/', ' ', $text);
$text = trim($text);
$text = preg_replace('/[\s_-]+/', $separator, $text);
return $text;
}
// slugify('Café au Lait') → "cafe-au-lait"
// slugify('Hello World', '_') → "hello_world"