obsidian-semantic

Log | Files | Refs | README

commit c975dcc99271f6daf96e0a642d04947a5ff9ff66
parent 9a0b47b7dc3cf1de35abbc4b6b5f396f6ce3f61f
Author: Thomas Vigouroux <thomas.vigouroux@univ-grenoble-alpes.fr>
Date:   Thu, 23 May 2024 14:49:44 +0200

fix: sanitize filename when writing file

Diffstat:
Mmain.ts | 4++--
Mpackage-lock.json | 24+++++++++++++++++++++++-
Mpackage.json | 3++-
3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/main.ts b/main.ts @@ -2,6 +2,7 @@ import { SemanticsSettings } from 'SemanticsSettings'; import { App, Editor, MarkdownView, Modal, Notice, Plugin, SuggestModal, TFile, TFolder, Vault, requestUrl, RequestUrlParam } from 'obsidian'; import * as path from 'path'; import { SemanticApi } from 'SemanticApi'; +import { sanitize } from 'sanitize-filename-ts'; interface SemanticSettings { papersPath: string; @@ -238,8 +239,7 @@ class SemanticModal extends SuggestModal<Paper> { async onChooseSuggestion(item: Paper, evt: MouseEvent | KeyboardEvent) { var final = await Paper.get(this.apiAccess, item.paperId); - var title = final.title.split(":")[0]; - var fname = path.join(this.options.papersPath, title) + ".md"; + var fname = path.join(this.options.papersPath, sanitize(final.title)) + ".md"; if (final.citationStyles == undefined || final.externalIds == undefined) { throw new Error("Missing fields in paper"); diff --git a/package-lock.json b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "p-debounce": "^4.0.0" + "p-debounce": "^4.0.0", + "sanitize-filename-ts": "^1.0.2" }, "devDependencies": { "@types/node": "^16.11.6", @@ -1999,6 +2000,14 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/sanitize-filename-ts": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/sanitize-filename-ts/-/sanitize-filename-ts-1.0.2.tgz", + "integrity": "sha512-bON2VOJoappmaBHlnxvBNk5R7HkUAsirf5m1M5Kz15uZykDGbHfGPCQNcEQKR8HrQhgh9CmQ6Xe9y71yM9ywkw==", + "dependencies": { + "truncate-utf8-bytes": "^1.0.2" + } + }, "node_modules/semver": { "version": "7.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", @@ -2111,6 +2120,14 @@ "node": ">=8.0" } }, + "node_modules/truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==", + "dependencies": { + "utf8-byte-length": "^1.0.1" + } + }, "node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -2187,6 +2204,11 @@ "punycode": "^2.1.0" } }, + "node_modules/utf8-byte-length": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.5.tgz", + "integrity": "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA==" + }, "node_modules/w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", diff --git a/package.json b/package.json @@ -22,6 +22,7 @@ "typescript": "4.7.4" }, "dependencies": { - "p-debounce": "^4.0.0" + "p-debounce": "^4.0.0", + "sanitize-filename-ts": "^1.0.2" } }