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 <tukon479@gmail.com>
This commit is contained in:
Innei 2025-07-01 14:42:24 +08:00
parent 66591e452b
commit f6cff2a482
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 25 additions and 1 deletions

View File

@ -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) {

View File

@ -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