From 0ce16462adf4279cdf2fc8d4a1aaddfa9764cc6b Mon Sep 17 00:00:00 2001 From: Olli Janatuinen Date: Sat, 27 May 2023 08:34:17 +0200 Subject: [PATCH] Generate markup file path based on chat title --- scripts/export.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/export.js b/scripts/export.js index 3af006e93..457316c43 100644 --- a/scripts/export.js +++ b/scripts/export.js @@ -164,8 +164,12 @@ async function exportInit() { .join(''); const data = ExportMD.turndown(content); const { id, filename } = getName(); - await invoke('save_file', { name: `notes/${id}.md`, content: data }); - await invoke('download_list', { pathname: 'chat.notes.json', filename, id, dir: 'notes' }); + const sanitizedText = filename.replace(/[<>:\"\/\?\'\\*\.#]/g, ''); + const withoutSpaces = sanitizedText.replace(/ /g, '_'); + const parts = withoutSpaces.split('|'); + const filePath = `notes/${parts.join('/')}.md`; + await invoke('save_file', { name: filePath, content: data }); + await invoke('download_list', { pathname: 'chat.notes.json', withoutSpaces, id, dir: 'notes' }); } async function downloadThread({ as = Format.PNG } = {}) { @@ -310,7 +314,7 @@ async function exportInit() { function getName() { const id = window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36); const name = - document.querySelector('nav .overflow-y-auto a.hover\\:bg-gray-800')?.innerText?.trim() || ''; + document.querySelector('title')?.innerText?.trim() || ''; return { filename: name ? name : id, id, pathname: 'chat.download.json' }; } }