|
|
发表于 2022-11-24 14:50:29
|
显示全部楼层
其实hugo这样做是比较符合url的规范的,也建议这样做
当然,如果你打算不让它这样做,或许可以自己编译一个魔改的hugo?
// UnicodeSanitize sanitizes string to be used in Hugo URL's, allowing only// a predefined set of special Unicode characters.// If RemovePathAccents configuration flag is enabled, Unicode accents// are also removed.// Spaces will be replaced with a single hyphen, and sequential hyphens will be reduced to one.func (p *PathSpec) UnicodeSanitize(s string) string { if p.RemovePathAccents { s = text.RemoveAccentsString(s) } source := []rune(s) target := make([]rune, 0, len(source)) var prependHyphen bool for i, r := range source { isAllowed := r == '.' || r == '/' || r == '\\' || r == '_' || r == '#' || r == '+' || r == '~' isAllowed = isAllowed || unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsMark(r) isAllowed = isAllowed || (r == '%' && i+2 < len(source) && ishex(source[i+1]) && ishex(source[i+2])) if isAllowed { if prependHyphen { target = append(target, '-') prependHyphen = false } target = append(target, r) } else if len(target) > 0 && (r == '-' || unicode.IsSpace(r)) { prependHyphen = true } } return string(target)}
如果你是考虑hexo迁移至hugo的问题,那或许可以自己写个脚本把%20改成- |
|