bring back Chinese cat mode

This commit is contained in:
naskya 2023-09-24 18:12:29 +09:00
parent 266078b549
commit 3ba12772d8
No known key found for this signature in database
GPG Key ID: 164DFF24E2D40139
2 changed files with 32 additions and 28 deletions

View File

@ -1,6 +1,5 @@
export function nyaize(text: string): string {
return (
text
export function nyaize(text: string, lang?: string): string {
text = text
// ja-JP
.replaceAll("な", "にゃ")
.replaceAll("ナ", "ニャ")
@ -23,6 +22,10 @@ export function nyaize(text: string): string {
// el-GR
.replaceAll("να", "νια")
.replaceAll("ΝΑ", "ΝΙΑ")
.replaceAll("Να", "Νια")
);
.replaceAll("Να", "Νια");
// zh-CN, zh-TW
if (lang === "zh") text = text.replace(/(妙|庙|描|渺|瞄|秒|苗|藐|廟)/g, "喵");
return text;
}

View File

@ -264,7 +264,8 @@ export const NoteRepository = db.getRepository(Note).extend({
const tokens = packed.text ? mfm.parse(packed.text) : [];
function nyaizeNode(node: mfm.MfmNode) {
if (node.type === "quote") return;
if (node.type === "text") node.props.text = nyaize(node.props.text);
if (node.type === "text")
node.props.text = nyaize(node.props.text, packed.lang);
if (node.children) {
for (const child of node.children) {