From 12ebcf76638ce336511705b6b433ea989e6a0895 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 23 May 2023 16:31:33 +0800 Subject: [PATCH] fix: truncate filename length to 100 --- package-lock.json | 17 ++++++++++++----- package.json | 2 ++ src/settings/template.ts | 9 +++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 773f9f4..cf71161 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "obsidian-omnivore", - "version": "1.2.3", + "version": "1.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-omnivore", - "version": "1.2.3", + "version": "1.3.2", "license": "MIT", "dependencies": { "diff-match-patch": "^1.0.5", + "lodash": "^4.17.21", "luxon": "^3.1.1", "markdown-escape": "^2.0.0", "mustache": "^4.2.0", @@ -22,6 +23,7 @@ "@semantic-release/git": "^10.0.1", "@types/diff-match-patch": "^1.0.32", "@types/jest": "^29.4.0", + "@types/lodash": "^4.14.194", "@types/luxon": "^3.1.0", "@types/markdown-escape": "^1.1.0", "@types/mustache": "^4.2.2", @@ -1771,6 +1773,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.14.194", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.194.tgz", + "integrity": "sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==", + "dev": true + }, "node_modules/@types/luxon": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.2.0.tgz", @@ -5374,8 +5382,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.capitalize": { "version": "4.2.1", @@ -6779,7 +6786,7 @@ } }, "node_modules/npm/node_modules/glob": { - "version": "8.0.3", + "version": "8.1.0", "dev": true, "inBundle": true, "license": "ISC", diff --git a/package.json b/package.json index 4cc56f8..7e4f1c4 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@semantic-release/git": "^10.0.1", "@types/diff-match-patch": "^1.0.32", "@types/jest": "^29.4.0", + "@types/lodash": "^4.14.194", "@types/luxon": "^3.1.0", "@types/markdown-escape": "^1.1.0", "@types/mustache": "^4.2.2", @@ -44,6 +45,7 @@ }, "dependencies": { "diff-match-patch": "^1.0.5", + "lodash": "^4.17.21", "luxon": "^3.1.1", "markdown-escape": "^2.0.0", "mustache": "^4.2.0", diff --git a/src/settings/template.ts b/src/settings/template.ts index 51d3572..3397f1a 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -1,3 +1,4 @@ +import { truncate } from "lodash"; import Mustache from "mustache"; import { stringifyYaml } from "obsidian"; import { Article, HighlightType, PageType } from "../api"; @@ -124,10 +125,15 @@ export const renderFilename = ( folderDateFormat: string ) => { const date = formatDate(article.savedAt, folderDateFormat); - return Mustache.render(filename, { + const renderedFilename = Mustache.render(filename, { ...article, date, }); + + // truncate the filename to 100 characters + return truncate(renderedFilename, { + length: 100, + }); }; export const renderAttachmentFolder = ( @@ -294,4 +300,3 @@ export const renderFolderName = (folder: string, folderDate: string) => { export const preParseTemplate = (template: string) => { Mustache.parse(template); }; -