Changes for page Linkding + SingleFile Archief
Last modified by XWikiGuest on 2026/03/11 21:04
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -Linkding + SingleFile Test1 +Linkding + SingleFile Archief - Content
-
... ... @@ -1,6 +1,6 @@ 1 -= Linkding + SingleFile Test=1 += Linkding + SingleFile Archief = 2 2 3 -Bookmarks met archief-viewer. Klik op hetarchief-icoon om de opgeslagen versie te bekijken.3 +Bookmarks uit Linkding met inline archief-viewer. Klik op 📄 om de opgeslagen versie te bekijken. 4 4 5 5 {{html clean="false"}} 6 6 <style> ... ... @@ -10,7 +10,6 @@ 10 10 border: 1px solid #4e5d6c; 11 11 border-radius: 4px; 12 12 overflow: hidden; 13 - background: #1a2a3a; 14 14 } 15 15 #ldsf-left { 16 16 width: 35%; ... ... @@ -34,11 +34,22 @@ 34 34 min-width: 200px; 35 35 display: flex; 36 36 flex-direction: column; 37 - background: #fff; 38 38 } 39 -#ldsf-status { color: #6b7c8d; font-size: 13px; padding: 8px 12px; flex-shrink: 0; } 40 -#ldsf-bookmarks { overflow-y: auto; flex: 1; } 41 -#ldsf-bookmarks ul { list-style: none; padding: 0; margin: 0; } 37 +#ldsf-status { 38 + color: #6b7c8d; 39 + font-size: 13px; 40 + padding: 8px 12px; 41 + flex-shrink: 0; 42 +} 43 +#ldsf-bookmarks { 44 + overflow-y: auto; 45 + flex: 1; 46 +} 47 +#ldsf-bookmarks ul { 48 + list-style: none; 49 + padding: 0; 50 + margin: 0; 51 +} 42 42 #ldsf-bookmarks li { 43 43 padding: 6px 12px; 44 44 border-bottom: 1px solid rgba(78,93,108,0.3); ... ... @@ -47,16 +47,29 @@ 47 47 gap: 8px; 48 48 } 49 49 #ldsf-bookmarks li:hover { background: #3b4e60; } 60 +.sf-num { 61 + display: inline-flex; 62 + align-items: center; 63 + justify-content: center; 64 + width: 22px; 65 + height: 22px; 66 + border-radius: 50%; 67 + background: #4e5d6c; 68 + color: #df691a; 69 + font-size: 11px; 70 + font-weight: bold; 71 + flex-shrink: 0; 72 +} 50 50 #ldsf-bookmarks a { 51 51 color: #5bc0de; 52 52 text-decoration: none; 53 - white-space: nowrap; 54 54 overflow: hidden; 55 55 text-overflow: ellipsis; 78 + white-space: nowrap; 56 56 font-size: 13px; 57 57 } 58 58 #ldsf-bookmarks a:hover { color: #df691a; } 59 - #ldsf-bookmarks.sf-btn {82 +.sf-btn { 60 60 cursor: pointer; 61 61 background: #4e5d6c; 62 62 border: none; ... ... @@ -66,7 +66,7 @@ 66 66 font-size: 13px; 67 67 flex-shrink: 0; 68 68 } 69 - #ldsf-bookmarks.sf-btn:hover { background: #df691a; color: #fff; }92 +.sf-btn:hover { background: #df691a; color: #fff; } 70 70 #ldsf-viewer-bar { 71 71 display: none; 72 72 justify-content: space-between; ... ... @@ -73,7 +73,7 @@ 73 73 align-items: center; 74 74 padding: 4px 12px; 75 75 background: #2b3e50; 76 - color: # 6b7c8d;99 + color: #ebebeb; 77 77 font-size: 12px; 78 78 flex-shrink: 0; 79 79 border-bottom: 1px solid #4e5d6c; ... ... @@ -80,8 +80,6 @@ 80 80 } 81 81 #ldsf-viewer-bar .close-btn { 82 82 cursor: pointer; 83 - background: none; 84 - border: none; 85 85 color: #d9534f; 86 86 font-size: 18px; 87 87 padding: 0 4px; ... ... @@ -92,6 +92,7 @@ 92 92 flex: 1; 93 93 border: none; 94 94 background: #fff; 116 + display: none; 95 95 } 96 96 #ldsf-placeholder { 97 97 display: flex; ... ... @@ -99,7 +99,7 @@ 99 99 justify-content: center; 100 100 flex: 1; 101 101 color: #6b7c8d; 102 - font-size: 1 6px;124 + font-size: 15px; 103 103 background: #2b3e50; 104 104 } 105 105 </style> ... ... @@ -112,124 +112,123 @@ 112 112 <div id="ldsf-divider"></div> 113 113 <div id="ldsf-right"> 114 114 <div id="ldsf-viewer-bar"> 115 - <span id="ldsf-viewer-title"> ...</span>137 + <span id="ldsf-viewer-title"></span> 116 116 <span class="close-btn" data-sfclose="1">×</span> 117 117 </div> 118 - <div id="ldsf-placeholder">Klik op 📄 om archief te bekijken</div> 119 - <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin" style="display:none"></iframe>140 + <div id="ldsf-placeholder">Klik op 📄 om een archief te bekijken</div> 141 + <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></iframe> 120 120 </div> 121 121 </div> 122 122 123 123 <script> 124 -var LDSF_LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/'; 125 -var LDSF_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e'; 126 -var LDSF_TAG = 'Nuclear-&-Energy'; 127 -var LDSF_COUNT = 20; 128 -var LDSF_SHARE = 'eT2X9ttBHK5GoEY'; 129 -var LDSF_WEBDAV = 'https://cloud.rhebergen.org/public.php/webdav/'; 130 -var LDSF_AUTH = 'Basic ' + btoa(LDSF_SHARE + ':'); 146 +/* --- Configuration --- */ 147 +var LDSF = { 148 + linkding: 'https://bookmarks.rhebergen.org/api/bookmarks/', 149 + token: '3b7443e0f84e2b2b269adebb96d7475e4a5e653e', 150 + tag: 'Nuclear-&-Energy', 151 + count: 20, 152 + share: 'eT2X9ttBHK5GoEY', 153 + webdav: 'https://cloud.rhebergen.org/public.php/webdav/' 154 +}; 155 +LDSF.auth = 'Basic ' + btoa(LDSF.share + ':'); 156 + 157 +/* --- State --- */ 131 131 var ldsf_urlToFile = {}; 132 -var ldsf_ archiveMap = {};159 +var ldsf_fileMap = {}; 133 133 134 -function ldsfFindArchive(url) { 135 - var v = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; 136 - for (var i = 0; i < v.length; i++) { if (ldsf_urlToFile[v[i]]) return ldsf_urlToFile[v[i]]; } 161 +/* --- URL matching (exact, with/without slash, without query string) --- */ 162 +function ldsfMatch(url) { 163 + var tries = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; 164 + for (var i = 0; i < tries.length; i++) { 165 + if (ldsf_urlToFile[tries[i]]) return ldsf_urlToFile[tries[i]]; 166 + } 137 137 return null; 138 138 } 139 139 140 -function ldsfOpen(idx) { 141 - var f = ldsf_archiveMap[idx]; 142 - if (f) ldsfShowArchive(f); 143 -} 144 - 145 -function ldsfShowArchive(filename) { 170 +/* --- Show archived page in viewer --- */ 171 +function ldsfShow(filename) { 146 146 document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, ''); 147 147 document.getElementById('ldsf-viewer-bar').style.display = 'flex'; 148 148 document.getElementById('ldsf-placeholder').style.display = 'none'; 149 149 var frame = document.getElementById('ldsf-viewer-frame'); 150 150 frame.style.display = 'block'; 151 - frame.srcdoc = '<p style="padding:20px;color:# 666">Laden...</p>';152 - fetch(LDSF _WEBDAV+ encodeURIComponent(filename), { headers: { 'Authorization': LDSF_AUTH} })153 - .then(function(r) { return r.text(); }) 154 - .then(function(html) { frame.srcdoc = html; }) 155 - .catch(function(e rr) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; });177 + frame.srcdoc = '<p style="padding:20px;color:#888">Laden...</p>'; 178 + fetch(LDSF.webdav + encodeURIComponent(filename), { headers: { 'Authorization': LDSF.auth } }) 179 + .then(function(r) { return r.text(); }) 180 + .then(function(html) { frame.srcdoc = html; }) 181 + .catch(function(e) { frame.srcdoc = '<p style="padding:20px;color:#d9534f">Fout: ' + e.message + '</p>'; }); 156 156 } 157 157 158 -function ldsfCloseViewer() { 184 +/* --- Close viewer --- */ 185 +function ldsfClose() { 159 159 document.getElementById('ldsf-viewer-bar').style.display = 'none'; 160 160 document.getElementById('ldsf-viewer-frame').style.display = 'none'; 161 161 document.getElementById('ldsf-placeholder').style.display = 'flex'; 162 162 } 163 163 164 -function ldsfLoadBookmarks() { 165 - var apiUrl = LDSF_LINKDING_URL + '?limit=' + LDSF_COUNT + '&q=%23' + encodeURIComponent(LDSF_TAG); 166 - fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LDSF_TOKEN } }) 167 - .then(function(r) { return r.json(); }) 168 - .then(function(data) { 169 - var total = data.count || 0; 170 - var archiveCount = 0; 171 - var container = document.getElementById('ldsf-bookmarks'); 172 - var html = '<ul>'; 173 - 174 - (data.results || []).forEach(function(bm, idx) { 175 - var title = bm.title || bm.website_title || bm.url; 176 - var fname = ldsfFindArchive(bm.url); 177 - if (fname) { archiveCount++; ldsf_archiveMap[String(idx)] = fname; } 178 - html += '<li>'; 179 - if (fname) html += '<span class="sf-btn" data-sfidx="' + idx + '" title="Archief bekijken">📄</span>'; 180 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>'; 181 - }); 182 - 183 - html += '</ul>'; 184 - container.innerHTML = html; 185 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; 186 - }) 187 - .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); 191 +/* --- Render bookmark list --- */ 192 +function ldsfRender(data) { 193 + var total = data.count || 0, archived = 0; 194 + var container = document.getElementById('ldsf-bookmarks'); 195 + var html = '<ul>'; 196 + (data.results || []).forEach(function(bm, i) { 197 + var title = bm.title || bm.website_title || bm.url; 198 + var file = ldsfMatch(bm.url); 199 + if (file) { archived++; ldsf_fileMap[i] = file; } 200 + html += '<li><span class="sf-num">' + (i + 1) + '</span>'; 201 + if (file) html += '<span class="sf-btn" data-sf="' + i + '" title="Archief bekijken">📄</span>'; 202 + html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>'; 203 + }); 204 + container.innerHTML = html + '</ul>'; 205 + document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archived + ' met archief'; 188 188 } 189 189 190 -/ /Globalclick handlerfor archivebuttonsandclosebutton208 +/* --- Click handler (event delegation, works in XWiki html macro) --- */ 191 191 document.addEventListener('click', function(e) { 192 - var el = e.target; 193 - if (el && el.getAttribute) { 194 - if (el.getAttribute('data-sfidx') !== null) { 195 - var idx = el.getAttribute('data-sfidx'); 196 - if (ldsf_archiveMap[idx]) ldsfShowArchive(ldsf_archiveMap[idx]); 197 - } 198 - if (el.getAttribute('data-sfclose') !== null) { 199 - ldsfCloseViewer(); 200 - } 201 - } 210 + var t = e.target; 211 + if (!t || !t.getAttribute) return; 212 + var sf = t.getAttribute('data-sf'); 213 + if (sf !== null && ldsf_fileMap[sf]) ldsfShow(ldsf_fileMap[sf]); 214 + if (t.getAttribute('data-sfclose') !== null) ldsfClose(); 202 202 }, true); 203 203 204 -// Draggable divider 205 -var ldsf_divider = document.getElementById('ldsf-divider'); 206 -var ldsf_left = document.getElementById('ldsf-left'); 207 -var ldsf_dragging = false; 208 - 209 -ldsf_divider.addEventListener('mousedown', function(e) { 210 - ldsf_dragging = true; 211 - ldsf_divider.classList.add('dragging'); 217 +/* --- Draggable divider --- */ 218 +var ldsf_drag = false; 219 +document.getElementById('ldsf-divider').addEventListener('mousedown', function(e) { 220 + ldsf_drag = true; 221 + this.classList.add('dragging'); 212 212 e.preventDefault(); 213 213 }); 214 214 document.addEventListener('mousemove', function(e) { 215 - if (!ldsf_drag ging) return;216 - var container= document.getElementById('ldsf-container');217 - var rect=container.getBoundingClientRect();218 - varw =e.clientX-rect.left;219 - if(w>= 200 && w <= rect.width * 0.6)ldsf_left.style.width = w + 'px';225 + if (!ldsf_drag) return; 226 + var box = document.getElementById('ldsf-container').getBoundingClientRect(); 227 + var w = e.clientX - box.left; 228 + if (w >= 200 && w <= box.width * 0.6) 229 + document.getElementById('ldsf-left').style.width = w + 'px'; 220 220 }); 221 221 document.addEventListener('mouseup', function() { 222 - if (ldsf_dragging) { ldsf_dragging = false; ldsf_divider.classList.remove('dragging'); } 232 + if (ldsf_drag) { 233 + ldsf_drag = false; 234 + document.getElementById('ldsf-divider').classList.remove('dragging'); 235 + } 223 223 }); 224 224 225 -// Load index then bookmarks 226 -fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } }) 227 -.then(function(r) { return r.ok ? r.json() : {}; }) 228 -.then(function(idx) { 229 - Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; }); 230 - ldsfLoadBookmarks(); 231 -}) 232 -.catch(function() { ldsfLoadBookmarks(); }); 238 +/* --- Load index, then bookmarks --- */ 239 +fetch(LDSF.webdav + 'index.json', { headers: { 'Authorization': LDSF.auth } }) 240 + .then(function(r) { return r.ok ? r.json() : {}; }) 241 + .then(function(idx) { 242 + for (var f in idx) { if (idx.hasOwnProperty(f)) ldsf_urlToFile[idx[f]] = f; } 243 + }) 244 + .catch(function() {}) 245 + .then(function() { 246 + return fetch(LDSF.linkding + '?limit=' + LDSF.count + '&q=%23' + encodeURIComponent(LDSF.tag), 247 + { headers: { 'Authorization': 'Token ' + LDSF.token } }); 248 + }) 249 + .then(function(r) { return r.json(); }) 250 + .then(ldsfRender) 251 + .catch(function(e) { 252 + document.getElementById('ldsf-status').textContent = 'Fout: ' + e.message; 253 + }); 233 233 </script> 234 234 {{/html}} 235 235