From f6cff2a482bde8980a0678917abad63e4d465f5f Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 1 Jul 2025 14:42:24 +0800 Subject: [PATCH] fix: handle special chat in filename, fixed #3342 - Integrated @sindresorhus/slugify to format file names based on titles. - Updated pnpm-lock.yaml to include new dependencies. - Minor adjustments in package.json files to ensure consistency. Signed-off-by: Innei --- .../main/src/ipc/services/integration.ts | 6 +++++- pnpm-lock.yaml | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/desktop/layer/main/src/ipc/services/integration.ts b/apps/desktop/layer/main/src/ipc/services/integration.ts index 651cc74a7..1b0e00564 100644 --- a/apps/desktop/layer/main/src/ipc/services/integration.ts +++ b/apps/desktop/layer/main/src/ipc/services/integration.ts @@ -2,6 +2,8 @@ import { existsSync } from "node:fs" import fsp from "node:fs/promises" import path from "node:path" +import slugify from "@sindresorhus/slugify" + import type { IpcContext } from "../base" import { IpcMethod, IpcService } from "../base" @@ -30,7 +32,9 @@ export class IntegrationService extends IpcService { try { const { url, title, content, author, publishedAt, vaultPath } = input - const fileName = `${(title || publishedAt).trim().slice(0, 20).replaceAll("/", "-")}.md` + const fileName = `${slugify(title || publishedAt) + .trim() + .slice(0, 20)}.md` const filePath = path.join(vaultPath, fileName) const exists = existsSync(filePath) if (exists) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00e01d194..e816c08d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -514,6 +514,9 @@ importers: '@shikijs/transformers': specifier: 3.7.0 version: 3.7.0 + '@sindresorhus/slugify': + specifier: 2.2.1 + version: 2.2.1 '@tanstack/query-sync-storage-persister': specifier: 5.80.10 version: 5.80.10 @@ -6161,6 +6164,14 @@ packages: resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==} engines: {node: '>=10'} + '@sindresorhus/slugify@2.2.1': + resolution: {integrity: sha512-MkngSCRZ8JdSOCHRaYd+D01XhvU3Hjy6MGl06zhOk614hp9EOAp5gIkBeQg7wtmxpitU6eAL4kdiRMcJa2dlrw==} + engines: {node: '>=12'} + + '@sindresorhus/transliterate@1.6.0': + resolution: {integrity: sha512-doH1gimEu3A46VX6aVxpHTeHrytJAG6HgdxntYnCFiIFHEM/ZGpG8KiZGBChchjQmG0XFIBL552kBTjVcMZXwQ==} + engines: {node: '>=12'} + '@sinonjs/commons@3.0.1': resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==} @@ -22045,6 +22056,15 @@ snapshots: '@sindresorhus/is@4.6.0': {} + '@sindresorhus/slugify@2.2.1': + dependencies: + '@sindresorhus/transliterate': 1.6.0 + escape-string-regexp: 5.0.0 + + '@sindresorhus/transliterate@1.6.0': + dependencies: + escape-string-regexp: 5.0.0 + '@sinonjs/commons@3.0.1': dependencies: type-detect: 4.0.8