From 499ec2154adb7e2809ec97a2b4e4f8b3e5c7acab Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 4 Mar 2025 22:59:49 +0100 Subject: [PATCH] up --- app.py | 2 +- data.json | 23 ++++++++++-- livre.org | 13 ++++++- personnages.org | 9 +++-- static/js/main.js | 94 ++++++++++++++++++++++++++++++++--------------- 5 files changed, 102 insertions(+), 39 deletions(-) diff --git a/app.py b/app.py index 7481aa9..884644c 100644 --- a/app.py +++ b/app.py @@ -30,7 +30,7 @@ def extract_characters(content): }) current_character = line[3:].strip() current_content = [] - elif current_character: + elif current_character and line.strip() and not line.startswith('*'): current_content.append(line) if current_character: diff --git a/data.json b/data.json index 4fcc90e..5c77458 100644 --- a/data.json +++ b/data.json @@ -1,13 +1,30 @@ { "2025-03-04": { - "words": 229, - "last_update": "2025-03-04 22:36:06" + "words": 233, + "last_update": "2025-03-04 22:58:27" }, "2025-03-03": { "words": 200, "last_update": "2025-03-03 16:14:22" }, - "characters": [], + "2025-03-02": { + "words": 100, + "last_update": "2025-03-03 16:14:22" + }, + "characters": [ + { + "name": "bob", + "content": "- nom:\n- personnalité:\n- objectifs:\n- conflits:\n- évolution:\n- alias: Bob l'éponge, SpongeBob" + }, + { + "name": "chuck norris", + "content": "- nom:\n- personnalité:\n- objectifs:\n- conflits:\n- évolution:\n- alias: le roux; celui dont on ne doit pas prononcer le nom" + }, + { + "name": "bobette", + "content": "- nom:\n- personnalité:\n- objectifs:\n- conflits:\n- évolution:\n- alias:" + } + ], "plots": [ { "name": "intrigue 1 2-3", diff --git a/livre.org b/livre.org index f2761e4..14e66e1 100644 --- a/livre.org +++ b/livre.org @@ -17,16 +17,24 @@ #+END_EXPORT * Livre nom_de_mon_livre :title: +[[https://i.etsystatic.com/38612687/r/il/692ff8/5340918389/il_fullxfull.5340918389_fgfn.jpg]] + +#+begin_comment +wololo un commentaire +#+end_comment ** préambule du cul eeeeeeeeeeeeeeeeeeeee préambule du cul eeeeeeeeeeeeeeeeee cette partie ne devrait pas avoir de titre allez hein zou zou + + ** Chapitre 0 -------------- là non plus pas de titre à afficher ------------- + ** Chapitre 1 :title: celui là on doit le voir: chapitre 1 au dessus ici. @@ -39,14 +47,15 @@ Dans un monde lointain, il y avait une île mystérieuse où les arbres avaient On devrait mettre un peu plus d'électro swing dans cette partie. Ce commentaire n'appraîtra pas à l'export. C'est une notre spécialement pour l'auteur. #+end_comment - blah blah bleh bob trouva un cristal qui lui permit de communiquer avec les esprits de la nature. Avec leur aide, il put vaincre les ténèbres qui menaçaient l'île et restaurer la lumière éternelle. L'île fut sauvée et Eryndor devint un héros légendaire. + 1111111111111111 ** Chapitre 2 :title: 2222222222222 -chuck fait des trucs + + chuck fait des trucs #+begin_comment diff --git a/personnages.org b/personnages.org index 7238531..d7571b7 100644 --- a/personnages.org +++ b/personnages.org @@ -1,19 +1,20 @@ -* bob -* bob +** bob - nom: - personnalité: - objectifs: - conflits: - évolution: - alias: Bob l'éponge, SpongeBob -* chuck norris + +** chuck norris - nom: - personnalité: - objectifs: - conflits: - évolution: - alias: le roux; celui dont on ne doit pas prononcer le nom -* bobette + +** bobette - nom: - personnalité: - objectifs: diff --git a/static/js/main.js b/static/js/main.js index c806c59..412f9ce 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -19,6 +19,8 @@ const editor = CodeMirror.fromTextArea(document.getElementById('editor-content') } }); +let fileToSave = 'livre'; + // Gestion du thème const themeSwitch = document.getElementById('theme-switch'); const htmlElement = document.documentElement; @@ -368,6 +370,14 @@ function orgToHtml(text) { return `${name}`; } else if (type === 'plot') { return `${name}`; + } else if (content.startsWith('http')) { + // Si c'est une URL, on vérifie si c'est une image + const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']; + if (imageExtensions.some(ext => content.toLowerCase().endsWith(ext))) { + return `Image`; + } + // Sinon c'est un lien normal + return `${content}`; } return match; }); @@ -531,6 +541,25 @@ if (enable_auto_update) { let body = `content=${encodeURIComponent(content)}&editor_title=${encodeURIComponent(editorTitle)}`; // Déterminer le bon endpoint en fonction du titre + // Utiliser le type de fichier actuel pour déterminer l'endpoint + if (currentFileType === 'character') { + const name = editorTitle.split(':')[1].trim(); + endpoint = '/update_character'; + body = `name=${encodeURIComponent(name)}&content=${encodeURIComponent(content)}`; + } else if (currentFileType === 'plot') { + const name = editorTitle.split(':')[1].trim(); + endpoint = '/update_plot'; + body = `name=${encodeURIComponent(name)}&content=${encodeURIComponent(content)}`; + } else if (currentFileType === 'characters_file') { + endpoint = '/update_characters_file'; + body = `content=${encodeURIComponent(content)}`; + } else if (currentFileType === 'plots_file') { + endpoint = '/update_plots_file'; + body = `content=${encodeURIComponent(content)}`; + } else if (currentFileType === 'book') { + endpoint = '/update'; + body = `content=${encodeURIComponent(content)}&editor_title=${encodeURIComponent(editorTitle)}`; + } if (editorTitle.startsWith('Éditeur de Personnage:')) { const name = editorTitle.split(':')[1].trim(); endpoint = '/update_character'; @@ -541,8 +570,10 @@ if (enable_auto_update) { body = `name=${encodeURIComponent(name)}&content=${encodeURIComponent(content)}`; } else if (editorTitle === 'Personnages') { endpoint = '/update_characters_file'; + body = `content=${encodeURIComponent(content)}`; } else if (editorTitle === 'Intrigues') { endpoint = '/update_plots_file'; + body = `content=${encodeURIComponent(content)}`; } try { @@ -571,17 +602,37 @@ if (enable_auto_update) { document.getElementById('update-btn').addEventListener('click', async () => { const content = editor.getValue(); const editorTitle = document.querySelector('.editor h2').textContent; + let endpoint = '/update'; + let body = `content=${encodeURIComponent(content)}&editor_title=${encodeURIComponent(editorTitle)}`; + + // Déterminer le bon endpoint en fonction du titre + if (editorTitle.startsWith('Éditeur de Personnage:')) { + const name = editorTitle.split(':')[1].trim(); + endpoint = '/update_character'; + body = `name=${encodeURIComponent(name)}&content=${encodeURIComponent(content)}`; + } else if (editorTitle.startsWith('Éditeur d\'Intrigue:')) { + const name = editorTitle.split(':')[1].trim(); + endpoint = '/update_plot'; + body = `name=${encodeURIComponent(name)}&content=${encodeURIComponent(content)}`; + } else if (editorTitle === 'Personnages') { + endpoint = '/update_characters_file'; + body = `content=${encodeURIComponent(content)}`; + } else if (editorTitle === 'Intrigues') { + endpoint = '/update_plots_file'; + body = `content=${encodeURIComponent(content)}`; + } + try { - const response = await fetch('/update', { + const response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, - body: `content=${encodeURIComponent(content)}&editor_title=${encodeURIComponent(editorTitle)}` + body: body }); const data = await response.json(); if (response.ok) { - if (editorTitle === 'Livre') { + if (endpoint === '/update') { document.getElementById('words-today').textContent = data.words_today; updateProgress(data.words_today, parseInt(wordGoalInput.value)); } @@ -803,8 +854,9 @@ document.addEventListener('DOMContentLoaded', function () { const data = await response.json(); editor.setValue(data.content); // Mettre à jour le titre de l'éditeur - document.querySelector('.editor h2').textContent = `Éditeur de ${type === 'character' ? 'Personnage' : 'Intrigue'}: ${name}`; - updateSaveButtonText(); + const editorTitle = `Éditeur de ${type === 'character' ? 'Personnage' : 'Intrigue'}: ${name}`; + document.querySelector('.editor h2').textContent = editorTitle; + updateSaveButtonText(editorTitle); } else { alert(`Erreur lors du chargement du ${type}`); } @@ -881,7 +933,7 @@ document.addEventListener('DOMContentLoaded', function () { bookLink.addEventListener('click', (e) => { e.preventDefault(); loadBook(); - updateSaveButtonText(); + updateSaveButtonText('livre'); }); } @@ -891,7 +943,7 @@ document.addEventListener('DOMContentLoaded', function () { charactersFileLink.addEventListener('click', (e) => { e.preventDefault(); loadCharactersFile(); - updateSaveButtonText(); + updateSaveButtonText('personnages'); }); } @@ -901,7 +953,7 @@ document.addEventListener('DOMContentLoaded', function () { plotsFileLink.addEventListener('click', (e) => { e.preventDefault(); loadPlotsFile(); - updateSaveButtonText(); + updateSaveButtonText('intrigues'); }); } @@ -941,8 +993,7 @@ document.addEventListener('DOMContentLoaded', function () { editor.setSize(null, 'calc(100vh - 100px)'); // Gérer le changement de thème - const themeToggle = document.getElementById('theme-toggle'); - themeToggle.addEventListener('click', function () { + themeSwitch.addEventListener('change', function () { const isDark = document.body.getAttribute('data-theme') === 'dark'; editor.setOption('theme', isDark ? 'monokai' : 'default'); }); @@ -954,7 +1005,7 @@ document.addEventListener('DOMContentLoaded', function () { if (editorTitle === 'Livre') { updateWordCount(); } - updateSaveButtonText(); + updateSaveButtonText(editorTitle); }); // Gérer le focus @@ -1110,24 +1161,9 @@ function initializeEditor() { } // Fonction pour mettre à jour le texte du bouton de sauvegarde -function updateSaveButtonText() { - const editorTitle = document.querySelector('.editor h2').textContent; +function updateSaveButtonText(fileName) { const updateBtn = document.getElementById('update-btn'); - let fileText = ''; + fileToSave = fileName; + updateBtn.textContent = `Sauvegarder ${fileName}.org`; - if (editorTitle.startsWith('Éditeur de Personnage:')) { - const name = editorTitle.split(':')[1].trim(); - fileText = `Sauvegarder ${name}`; - } else if (editorTitle.startsWith('Éditeur d\'Intrigue:')) { - const name = editorTitle.split(':')[1].trim(); - fileText = `Sauvegarder ${name}`; - } else if (editorTitle === 'Personnages') { - fileText = 'Sauvegarder personnages.org'; - } else if (editorTitle === 'Intrigues') { - fileText = 'Sauvegarder intrigues.org'; - } else { - fileText = 'Sauvegarder livre.org'; - } - - updateBtn.textContent = fileText; } \ No newline at end of file