slug

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package slug 生成与校验 URL 片段。

规则(阶段 3 定稿,文章、页面、分类、标签共用):

  • NFKC 归一化后转小写;
  • 保留任何文字的字母、数字、下划线与组合标记,因此中文等 CJK 原样保留;
  • 其余字符(空白、标点、斜杠等)折叠为单个连字符,并修剪首尾连字符;
  • 长度上限 MaxLength 个字符;
  • 无法生成(如纯表情符号)时返回空串,由调用方决定回退策略。

站点可选拼音策略:Pinyin 先把汉字转成拼音再走同一规则,得到全 ASCII 的片段。

Index

Constants

View Source
const MaxLength = 128

MaxLength 是 slug 的最大字符数(按 Unicode 字符计)。

Variables

This section is empty.

Functions

func Make

func Make(s string) string

Make 由任意文本生成 slug;无法生成时返回空串。

func Pinyin

func Pinyin(s string) string

Pinyin 把汉字转为拼音后再生成 slug,非汉字部分按 Make 的规则处理。

例:「你好 World」→ "ni-hao-world"。多音字按字典首选读音,不做词级消歧。

func Valid

func Valid(s string) bool

Valid 报告 s 是否为规范 slug:非空、不超长,且是 Make 的不动点。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL