This commit is contained in:
Viet An
2026-06-12 10:06:13 +07:00
parent a4f71ddb90
commit 2932730fc3
5 changed files with 15 additions and 47 deletions

View File

@@ -7,6 +7,7 @@ import localizedFormat from "dayjs/plugin/localizedFormat";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import "dayjs/locale/vi";
import { deburr } from "es-toolkit";
dayjs.extend(weekday);
dayjs.extend(weekOfYear);
dayjs.extend(relativeTime);
@@ -213,24 +214,14 @@ export default defineNuxtPlugin((nuxtApp) => {
};
const nonAccent = function (str) {
if ($empty(str)) return null;
str = str.replaceAll("/", "-").replaceAll("%", "-").replaceAll("?", "-");
str = str.toLowerCase();
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
str = str.replace(/đ/g, "d");
// Some system encode vietnamese combining accent as individual utf-8 characters
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ""); // Huyền sắc hỏi ngã nặng
str = str.replace(/\u02C6|\u0306|\u031B/g, ""); // Â, Ê, Ă, Ơ, Ư
str = str
.split(" ")
.filter((s) => s)
.join("-");
return str;
if ($empty(str)) return "";
const result = deburr(str)
.toLowerCase()
.replaceAll(/\u02C6/g, "") // 'ˆ' (Some system encode vietnamese combining accent as individual utf-8 characters)
.replaceAll(/[\/%?]/g, " ")
.replaceAll(/[\s-]+/g, "-");
return result;
};
const linkID = function (link) {