Changes for page Linkding + SingleFile Archief
Last modified by XWikiGuest on 2026/03/11 21:04
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -78,6 +78,7 @@ 78 78 </style> 79 79 80 80 <div id="ldsf-wrapper"> 81 + <button id="ldsf-test-btn" style="background:#df691a;color:#fff;padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-bottom:10px;">TEST KLIK</button> 81 81 <div id="ldsf-status">Laden...</div> 82 82 <div id="ldsf-bookmarks"></div> 83 83 <div id="ldsf-viewer-container"> ... ... @@ -90,114 +90,99 @@ 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; 94 +var LDSF_LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/'; 95 +var LDSF_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e'; 96 +var LDSF_TAG = 'Nuclear-&-Energy'; 97 +var LDSF_COUNT = 20; 98 +var LDSF_SHARE = 'eT2X9ttBHK5GoEY'; 99 +var LDSF_WEBDAV = 'https://cloud.rhebergen.org/public.php/webdav/'; 100 +var LDSF_AUTH = 'Basic ' + btoa(LDSF_SHARE + ':'); 101 +var ldsf_urlToFile = {}; 102 +var ldsf_archiveMap = {}; 98 98 99 - var WEBDAV_BASE = 'https://cloud.rhebergen.org/remote.php/dav/files/jan_rhebergen/SingleFile-Archives/'; 100 - var INDEX_URL = WEBDAV_BASE + 'index.json'; 101 - var NC_AUTH = 'Basic amFuX3JoZWJlcmdlbjpAWnMzUUwkJmZ4TVE='; 104 +function ldsfFindArchive(url) { 105 + var v = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; 106 + for (var i = 0; i < v.length; i++) { if (ldsf_urlToFile[v[i]]) return ldsf_urlToFile[v[i]]; } 107 + return null; 108 +} 102 102 103 - var urlToFile = {}; // reverse map: URL -> filename 104 - var archiveMap = {}; // button index -> filename 110 +function ldsfOpen(idx) { 111 + var f = ldsf_archiveMap[idx]; 112 + if (f) ldsfShowArchive(f); 113 +} 105 105 106 - function findArchive(url) { 107 - // Try exact match, with/without trailing slash, and without query string 108 - var variants = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; 109 - for (var i = 0; i < variants.length; i++) { 110 - if (urlToFile[variants[i]]) return urlToFile[variants[i]]; 111 - } 112 - return null; 113 - } 115 +function ldsfShowArchive(filename) { 116 + document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, ''); 117 + document.getElementById('ldsf-viewer-container').style.display = 'block'; 118 + var frame = document.getElementById('ldsf-viewer-frame'); 119 + frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>'; 120 + fetch(LDSF_WEBDAV + encodeURIComponent(filename), { headers: { 'Authorization': LDSF_AUTH } }) 121 + .then(function(r) { return r.text(); }) 122 + .then(function(html) { frame.srcdoc = html; }) 123 + .catch(function(err) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; }); 124 +} 114 114 115 - // Load SingleFile index, then load bookmarks 116 - fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } }) 117 - .then(function(r) { return r.ok ? r.json() : {}; }) 118 - .then(function(index) { 119 - // Build reverse map: URL -> filename 120 - Object.keys(index).forEach(function(fname) { 121 - urlToFile[index[fname]] = fname; 122 - }); 123 - loadBookmarks(); 124 - }) 125 - .catch(function() { 126 - loadBookmarks(); // Continue without index 127 - }); 126 +function ldsfCloseViewer() { 127 + document.getElementById('ldsf-viewer-container').style.display = 'none'; 128 +} 128 128 129 - function loadBookmarks() {130 - var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG);131 - fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_TOKEN } })132 - .then(function(r) { return r.json(); })133 - .then(function(data) {134 - var total = data.count || 0;135 - var archiveCount = 0;136 - var container = document.getElementById('ldsf-bookmarks');137 - varhtml = '<ul>';130 +function ldsfLoadBookmarks() { 131 + var apiUrl = LDSF_LINKDING_URL + '?limit=' + LDSF_COUNT + '&q=%23' + encodeURIComponent(LDSF_TAG); 132 + fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LDSF_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 ul = document.createElement('ul'); 138 138 139 - (data.results || []).forEach(function(bm, idx) {140 - var title = bm.title || bm.website_title || bm.url;141 - var fname = findArchive(bm.url);142 - if (fname) archiveCount++;140 + (data.results || []).forEach(function(bm) { 141 + var title = bm.title || bm.website_title || bm.url; 142 + var fname = ldsfFindArchive(bm.url); 143 + if (fname) archiveCount++; 143 143 144 - html += '<li>'; 145 - if (fname) { 146 - html += '<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">📄</button>'; 147 - archiveMap[idx] = fname; 148 - } 149 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>'; 150 - html += '</li>'; 151 - }); 145 + var li = document.createElement('li'); 152 152 153 - html += '</ul>'; 154 - container.innerHTML = html; 155 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; 147 + if (fname) { 148 + var btn = document.createElement('button'); 149 + btn.className = 'sf-btn'; 150 + btn.title = 'Archief bekijken'; 151 + btn.textContent = '\uD83D\uDCC4'; 152 + btn.addEventListener('click', (function(f) { 153 + return function() { ldsfShowArchive(f); }; 154 + })(fname)); 155 + li.appendChild(btn); 156 + } 156 156 157 - // Event delegation for archive buttons 158 - container.addEventListener('click', function(e) { 159 - var btn = e.target.closest('.sf-btn'); 160 - if (!btn) return; 161 - var idx = btn.getAttribute('data-idx'); 162 - if (idx !== null && archiveMap[idx]) { 163 - ldsfShowArchive(archiveMap[idx], btn); 164 - } 165 - }); 166 - }) 167 - .catch(function(err) { 168 - document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; 158 + var a = document.createElement('a'); 159 + a.href = bm.url; 160 + a.target = '_blank'; 161 + a.textContent = title; 162 + li.appendChild(a); 163 + ul.appendChild(li); 169 169 }); 170 - } 171 171 172 - // Show archive in viewer panel 173 - window.ldsfShowArchive = function(filename, btn) { 174 - var container = document.getElementById('ldsf-viewer-container'); 175 - var frame = document.getElementById('ldsf-viewer-frame'); 176 - var titleEl = document.getElementById('ldsf-viewer-title'); 166 + container.innerHTML = ''; 167 + container.appendChild(ul); 168 + document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; 169 + }) 170 + .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); 171 +} 177 177 178 - // Toggle active button 179 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); 180 - btn.classList.add('active'); 173 +// Debug test button 174 +document.getElementById('ldsf-test-btn').addEventListener('click', function() { 175 + alert('archiveMap: ' + JSON.stringify(ldsf_archiveMap) + '\nurlToFile: ' + JSON.stringify(ldsf_urlToFile)); 176 +}); 181 181 182 - titleEl.textContent = filename.replace(/\.html?$/i, ''); 183 - container.style.display = 'block'; 184 - frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>'; 185 - 186 - fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } }) 187 - .then(function(r) { return r.text(); }) 188 - .then(function(html) { 189 - frame.srcdoc = html; 190 - }) 191 - .catch(function(err) { 192 - frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; 193 - }); 194 - }; 195 - 196 - window.ldsfCloseViewer = function() { 197 - document.getElementById('ldsf-viewer-container').style.display = 'none'; 198 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); 199 - }; 200 -})(); 178 +// Load index then bookmarks 179 +fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } }) 180 +.then(function(r) { return r.ok ? r.json() : {}; }) 181 +.then(function(idx) { 182 + console.log('SingleFile index loaded:', idx); 183 + Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; }); 184 + ldsfLoadBookmarks(); 185 +}) 186 +.catch(function(err) { console.log('SingleFile index FAILED:', err); ldsfLoadBookmarks(); }); 201 201 </script> 202 202 {{/html}} 203 203