From 0e84111ffe4827a2fcf621f73207cd741e1d5c30 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Wed, 8 Apr 2026 18:34:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=92=8C=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 标题生成后左侧列表实时刷新(2秒轮询) - 增加显示内容预览开关 - 增加置顶/取消置顶功能 - 列表项hover显示隐藏菜单(置顶、删除) --- app.py | 29 ++++++-- run.sh | 0 templates/index.html | 153 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 166 insertions(+), 16 deletions(-) mode change 100644 => 100755 run.sh diff --git a/app.py b/app.py index c9bf710..89763cd 100644 --- a/app.py +++ b/app.py @@ -33,7 +33,9 @@ LLM_CONFIG = { def load_notes(): """加载所有笔记""" if NOTES_FILE.exists(): - return json.loads(NOTES_FILE.read_text(encoding='utf-8')) + notes = json.loads(NOTES_FILE.read_text(encoding='utf-8')) + # 按置顶和更新时间排序 + return sorted(notes, key=lambda x: (not x.get('pinned', False), x.get('updated_at', '')), reverse=True) return [] def save_notes(notes): @@ -118,6 +120,7 @@ def api_notes(): 'updated_at': n['updated_at'], 'created_at': n['created_at'], 'preview': n['content'][:50] if n['content'] else '', + 'pinned': n.get('pinned', False), } for n in notes]) @app.route('/api/notes/') @@ -193,9 +196,11 @@ def api_regenerate_title(note_id): note['title'] = title note['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + # 重新排序 + notes = sorted(notes, key=lambda x: (not x.get('pinned', False), x.get('updated_at', '')), reverse=True) save_notes(notes) - return jsonify({'success': True, 'title': title}) + return jsonify({'success': True, 'title': title, 'note': note}) @app.route('/api/notes/', methods=['DELETE']) def api_delete_note(note_id): @@ -206,6 +211,23 @@ def api_delete_note(note_id): return jsonify({'success': True}) +@app.route('/api/notes//pin', methods=['POST']) +def api_pin_note(note_id): + """置顶/取消置顶笔记""" + notes = load_notes() + note = next((n for n in notes if n['id'] == note_id), None) + + if not note: + return jsonify({'error': 'Note not found'}), 404 + + note['pinned'] = not note.get('pinned', False) + + # 重新排序 + notes = sorted(notes, key=lambda x: (not x.get('pinned', False), x.get('updated_at', '')), reverse=True) + save_notes(notes) + + return jsonify({'success': True, 'pinned': note['pinned'], 'note': note}) + @app.route('/api/search') def api_search(): """搜索笔记""" @@ -217,13 +239,12 @@ def api_search(): notes = load_notes() results = [n for n in notes if keyword in n.get('title', '').lower() or keyword in n.get('content', '').lower()] - results = sorted(results, key=lambda x: x.get('updated_at', ''), reverse=True) - return jsonify([{ 'id': n['id'], 'title': n['title'], 'updated_at': n['updated_at'], 'preview': n['content'][:100] if n['content'] else '', + 'pinned': n.get('pinned', False), } for n in results]) if __name__ == '__main__': diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 diff --git a/templates/index.html b/templates/index.html index 5a6dcea..3ba0f7b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,10 +9,15 @@ @@ -27,6 +32,15 @@ class="w-full pl-10 pr-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:border-purple-400" oninput="searchNotes()"> + + +
+ +
+ @@ -46,10 +60,18 @@