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,68 +1,108 @@ 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> 7 -#ldsf- wrapper {7 +#ldsf-container { 8 8 display: flex; 9 + height: 75vh; 10 + border: 1px solid #4e5d6c; 11 + border-radius: 4px; 12 + overflow: hidden; 13 +} 14 +#ldsf-left { 15 + width: 35%; 16 + min-width: 200px; 17 + max-width: 60%; 18 + overflow-y: auto; 19 + background: #2b3e50; 20 + display: flex; 9 9 flex-direction: column; 10 - gap: 0; 11 11 } 23 +#ldsf-divider { 24 + width: 6px; 25 + background: #4e5d6c; 26 + cursor: col-resize; 27 + flex-shrink: 0; 28 + transition: background 0.2s; 29 +} 30 +#ldsf-divider:hover, #ldsf-divider.dragging { background: #df691a; } 31 +#ldsf-right { 32 + flex: 1; 33 + min-width: 200px; 34 + display: flex; 35 + flex-direction: column; 36 +} 37 +#ldsf-status { 38 + color: #6b7c8d; 39 + font-size: 13px; 40 + padding: 8px 12px; 41 + flex-shrink: 0; 42 +} 12 12 #ldsf-bookmarks { 13 - color: #ebebeb; 44 + overflow-y: auto; 45 + flex: 1; 14 14 } 15 15 #ldsf-bookmarks ul { 16 16 list-style: none; 17 17 padding: 0; 50 + margin: 0; 18 18 } 19 19 #ldsf-bookmarks li { 20 20 padding: 6px 12px; 21 - background: #2b3e50; 22 - border-left: 3px solid #df691a; 23 - border-radius: 0 4px 4px 0; 24 - margin: 4px 0; 54 + border-bottom: 1px solid rgba(78,93,108,0.3); 25 25 display: flex; 26 26 align-items: center; 27 27 gap: 8px; 28 28 } 29 29 #ldsf-bookmarks li:hover { background: #3b4e60; } 30 -#ldsf-bookmarks a { color: #5bc0de; text-decoration: none; } 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: #df691a; 68 + color: #fff; 69 + font-size: 11px; 70 + font-weight: bold; 71 + flex-shrink: 0; 72 +} 73 +#ldsf-bookmarks a { 74 + color: #5bc0de; 75 + text-decoration: none; 76 + overflow: hidden; 77 + text-overflow: ellipsis; 78 + white-space: nowrap; 79 + font-size: 13px; 80 +} 31 31 #ldsf-bookmarks a:hover { color: #df691a; } 32 - #ldsf-bookmarks.sf-btn {82 +.sf-btn { 33 33 cursor: pointer; 34 34 background: #4e5d6c; 35 35 border: none; 36 36 color: #5bc0de; 37 - padding: 2px 8px;87 + padding: 2px 6px; 38 38 border-radius: 3px; 39 - font-size: 1 4px;89 + font-size: 13px; 40 40 flex-shrink: 0; 41 41 } 42 -#ldsf-bookmarks .sf-btn:hover { background: #df691a; color: #fff; } 43 -#ldsf-bookmarks .sf-btn.active { background: #df691a; color: #fff; } 44 - 45 -#ldsf-viewer-container { 46 - display: none; 47 - margin-top: 10px; 48 - border: 1px solid #4e5d6c; 49 - border-radius: 4px; 50 - overflow: hidden; 51 - background: #1a2a3a; 52 -} 92 +.sf-btn:hover { background: #df691a; color: #fff; } 53 53 #ldsf-viewer-bar { 54 - display: flex;94 + display: none; 55 55 justify-content: space-between; 56 56 align-items: center; 57 - padding: 6px 12px;97 + padding: 4px 12px; 58 58 background: #2b3e50; 59 - color: #6b7c8d; 60 - font-size: 13px; 99 + color: #ebebeb; 100 + font-size: 12px; 101 + flex-shrink: 0; 102 + border-bottom: 1px solid #4e5d6c; 61 61 } 62 62 #ldsf-viewer-bar .close-btn { 63 63 cursor: pointer; 64 - background: none; 65 - border: none; 66 66 color: #d9534f; 67 67 font-size: 18px; 68 68 padding: 0 4px; ... ... @@ -70,140 +70,147 @@ 70 70 #ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; } 71 71 #ldsf-viewer-frame { 72 72 width: 100%; 73 - height:70vh;113 + flex: 1; 74 74 border: none; 75 75 background: #fff; 116 + display: none; 76 76 } 77 -#ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; } 118 +#ldsf-placeholder { 119 + display: flex; 120 + align-items: center; 121 + justify-content: center; 122 + flex: 1; 123 + color: #6b7c8d; 124 + font-size: 15px; 125 + background: #2b3e50; 126 +} 78 78 </style> 79 79 80 -<div id="ldsf-wrapper"> 81 - <div id="ldsf-status">Laden...</div> 82 - <div id="ldsf-bookmarks"></div> 83 - <div id="ldsf-viewer-container"> 129 +<div id="ldsf-container"> 130 + <div id="ldsf-left"> 131 + <div id="ldsf-status">Laden...</div> 132 + <div id="ldsf-bookmarks"></div> 133 + </div> 134 + <div id="ldsf-divider"></div> 135 + <div id="ldsf-right"> 84 84 <div id="ldsf-viewer-bar"> 85 - <span id="ldsf-viewer-title"> ...</span>86 - < button class="close-btn"onclick="ldsfCloseViewer()">×</button>137 + <span id="ldsf-viewer-title"></span> 138 + <span class="close-btn" data-sfclose="1">×</span> 87 87 </div> 140 + <div id="ldsf-placeholder">Klik op 📄 om een archief te bekijken</div> 88 88 <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></iframe> 89 89 </div> 90 90 </div> 91 91 92 92 <script> 93 -(function() { 94 - var LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/'; 95 - var LINKDING_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e'; 96 - var LINKDING_TAG = 'Nuclear-&-Energy'; 97 - var LINKDING_COUNT = 20; 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 + ':'); 98 98 99 - var SHARE_TOKEN = 'eT2X9ttBHK5GoEY'; 100 - var WEBDAV_BASE = 'https://cloud.rhebergen.org/public.php/webdav/'; 101 - var INDEX_URL = WEBDAV_BASE + 'index.json'; 102 - var NC_AUTH = 'Basic ' + btoa(SHARE_TOKEN + ':'); 157 +/* --- State --- */ 158 +var ldsf_urlToFile = {}; 159 +var ldsf_fileMap = {}; 103 103 104 - var urlToFile = {}; // reverse map: URL -> filename 105 - var archiveMap = {}; // button index -> filename 106 - 107 - function findArchive(url) { 108 - // Try exact match, with/without trailing slash, and without query string 109 - var variants = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; 110 - for (var i = 0; i < variants.length; i++) { 111 - if (urlToFile[variants[i]]) return urlToFile[variants[i]]; 112 - } 113 - return null; 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]]; 114 114 } 167 + return null; 168 +} 115 115 116 - //LoadSingleFileindex,thenloadbookmarks117 - fetch(INDEX_URL,{ headers: { 'Authorization': NC_AUTH } })118 - .t hen(function(r){returnr.ok?r.json(): {};})119 - .t hen(function(index){120 - // Buildreversemap:URL-> filename121 - Object.keys(index).forEach(function(fname){122 - urlToFile[index[fname]]=fname;123 - });124 - loadBookmarks();125 - }) 126 - . catch(function() {127 - loadBookmarks();// Continuewithoutindex128 - });170 +/* --- Show archived page in viewer --- */ 171 +function ldsfShow(filename) { 172 + document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, ''); 173 + document.getElementById('ldsf-viewer-bar').style.display = 'flex'; 174 + document.getElementById('ldsf-placeholder').style.display = 'none'; 175 + var frame = document.getElementById('ldsf-viewer-frame'); 176 + frame.style.display = 'block'; 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>'; }); 182 +} 129 129 130 - function loadBookmarks() { 131 - var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG); 132 - fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_TOKEN } }) 133 - .then(function(r) { return r.json(); }) 134 - .then(function(data) { 135 - var total = data.count || 0; 136 - var archiveCount = 0; 137 - var container = document.getElementById('ldsf-bookmarks'); 138 - var html = '<ul>'; 184 +/* --- Close viewer --- */ 185 +function ldsfClose() { 186 + document.getElementById('ldsf-viewer-bar').style.display = 'none'; 187 + document.getElementById('ldsf-viewer-frame').style.display = 'none'; 188 + document.getElementById('ldsf-placeholder').style.display = 'flex'; 189 +} 139 139 140 - (data.results || []).forEach(function(bm, idx) { 141 - var title = bm.title || bm.website_title || bm.url; 142 - var fname = findArchive(bm.url); 143 - if (fname) archiveCount++; 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'; 206 +} 144 144 145 - html +='<li>';146 - if(fname) {147 - html+='<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">📄</button>';148 - archiveMap[idx]= fname;149 - }150 - html +='<a href="'+ bm.url+'" target="_blank">'+ title+ '</a>';151 - html+='</li>';152 - });208 +/* --- Click handler (event delegation, works in XWiki html macro) --- */ 209 +document.addEventListener('click', function(e) { 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(); 215 +}, true); 153 153 154 - html += '</ul>'; 155 - container.innerHTML = html; 156 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; 157 - 158 - // Bind click handlers directly to buttons 159 - var buttons = container.querySelectorAll('.sf-btn'); 160 - for (var b = 0; b < buttons.length; b++) { 161 - (function(btn) { 162 - var idx = btn.getAttribute('data-idx'); 163 - btn.addEventListener('click', function(ev) { 164 - ev.preventDefault(); 165 - ev.stopPropagation(); 166 - if (archiveMap[idx]) { 167 - ldsfShowArchive(archiveMap[idx], btn); 168 - } 169 - }); 170 - })(buttons[b]); 171 - } 172 - }) 173 - .catch(function(err) { 174 - document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; 175 - }); 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'); 222 + e.preventDefault(); 223 +}); 224 +document.addEventListener('mousemove', function(e) { 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'; 230 +}); 231 +document.addEventListener('mouseup', function() { 232 + if (ldsf_drag) { 233 + ldsf_drag = false; 234 + document.getElementById('ldsf-divider').classList.remove('dragging'); 176 176 } 236 +}); 177 177 178 - // Show archive in viewer panel 179 - window.ldsfShowArchive = function(filename, btn) { 180 - var container = document.getElementById('ldsf-viewer-container'); 181 - var frame = document.getElementById('ldsf-viewer-frame'); 182 - var titleEl = document.getElementById('ldsf-viewer-title'); 183 - 184 - // Toggle active button 185 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); 186 - btn.classList.add('active'); 187 - 188 - titleEl.textContent = filename.replace(/\.html?$/i, ''); 189 - container.style.display = 'block'; 190 - frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>'; 191 - 192 - fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } }) 193 - .then(function(r) { return r.text(); }) 194 - .then(function(html) { 195 - frame.srcdoc = html; 196 - }) 197 - .catch(function(err) { 198 - frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; 199 - }); 200 - }; 201 - 202 - window.ldsfCloseViewer = function() { 203 - document.getElementById('ldsf-viewer-container').style.display = 'none'; 204 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); 205 - }; 206 -})(); 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 + }); 207 207 </script> 208 208 {{/html}} 209 209