Skip to content

Commit

Permalink
Generate markup file path based on chat title
Browse files Browse the repository at this point in the history
  • Loading branch information
olljanat committed May 27, 2023
1 parent 0a88431 commit 572bfce
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}) {
Expand Down Expand Up @@ -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' };
}
}
Expand Down

0 comments on commit 572bfce

Please sign in to comment.