52 lines
3 KiB
Python
52 lines
3 KiB
Python
|
|
import os
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
path = r'z:\source\forgejo\spotnotes.app\static\assets\js\map.js'
|
|||
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
new_render = """ const shareToken = note.share_token || '';
|
|||
|
|
const shareBtn = `<button onclick="window.SpotNotes.shareNote(${note.id}, '${shareToken}')" class="btn-note-share">🔗 Share</button>`;
|
|||
|
|
|
|||
|
|
const dateStr = new Date(note.created_at).toLocaleString();
|
|||
|
|
|
|||
|
|
const padColor = (note.notepad && note.notepad.color) ? note.notepad.color : '#3388ff';
|
|||
|
|
|
|||
|
|
const directionsBtn = `<a href="https://www.google.com/maps/dir/?api=1&destination=${note.lat},${note.lng}" target="_blank" class="btn-note-directions" style="display:inline-block; margin-top:5px; margin-right:5px; font-size:0.8rem; text-decoration:none;">🗺️ Directions</a>`;
|
|||
|
|
|
|||
|
|
if (showFull) {
|
|||
|
|
const icon = L.divIcon({
|
|||
|
|
className: '',
|
|||
|
|
html: `<div class="map-note-card" style="border-top: 4px solid ${padColor};">
|
|||
|
|
<div style="font-weight:bold; margin-bottom:4px;">${window.SpotNotes.escapeHtml(note.title)}</div>
|
|||
|
|
<div style="white-space: pre-wrap;">${window.SpotNotes.escapeHtml(note.content)}</div>
|
|||
|
|
<div style="font-size:0.7rem; color:#888; margin-top:4px;">${dateStr}</div>
|
|||
|
|
${directionsBtn} ${shareBtn} ${actionBtns}
|
|||
|
|
</div>`,
|
|||
|
|
iconSize: [200, 'auto'],
|
|||
|
|
iconAnchor: [100, 0]
|
|||
|
|
});
|
|||
|
|
marker = L.marker([note.lat, note.lng], { icon: icon });
|
|||
|
|
} else {
|
|||
|
|
const svgIcon = L.divIcon({
|
|||
|
|
className: 'custom-div-icon',
|
|||
|
|
html: `<div style="background-color: ${padColor}; width: 16px; height: 16px; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 4px rgba(0,0,0,0.5);"></div>`,
|
|||
|
|
iconSize: [20, 20],
|
|||
|
|
iconAnchor: [10, 10],
|
|||
|
|
popupAnchor: [0, -10]
|
|||
|
|
});
|
|||
|
|
marker = L.marker([note.lat, note.lng], { icon: svgIcon });
|
|||
|
|
marker.bindPopup(`<b>${window.SpotNotes.escapeHtml(note.title)}</b><br><div style="white-space: pre-wrap;">${window.SpotNotes.escapeHtml(note.content)}</div><span style="font-size:0.7rem; color:#888;">${dateStr}</span><br>${directionsBtn} ${shareBtn} ${actionBtns}`);
|
|||
|
|
}"""
|
|||
|
|
|
|||
|
|
# Extract old chunk to replace
|
|||
|
|
old_chunk_start = "const shareToken = note.share_token || '';"
|
|||
|
|
old_chunk_end = "marker.bindPopup(`<b>${window.SpotNotes.escapeHtml(note.title)}</b><br><div style=\"white-space: pre-wrap;\">${window.SpotNotes.escapeHtml(note.content)}</div><span style=\"font-size:0.7rem; color:#888;\">${dateStr}</span><br>${directionsBtn} ${shareBtn} ${actionBtns}`);\n }"
|
|||
|
|
|
|||
|
|
pattern = re.escape(old_chunk_start) + r'.*?' + re.escape(old_chunk_end)
|
|||
|
|
content = re.sub(pattern, new_render, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print('Marker logic updated with colors.')
|