Last modified by XWikiGuest on 2026/03/11 21:04

From version 13.1
edited by XWikiGuest
on 2026/03/11 21:02
Change comment: There is no comment for this version
To version 12.1
edited by XWikiGuest
on 2026/03/11 20:55
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Linkding + SingleFile Archief
1 +Linkding + SingleFile Test
Content
... ... @@ -1,6 +1,6 @@
1 -= Linkding + SingleFile Archief =
1 += Linkding + SingleFile Test =
2 2  
3 -Bookmarks uit Linkding met inline archief-viewer. Klik op 📄 om de opgeslagen versie te bekijken.
3 +Bookmarks met archief-viewer. Klik op het archief-icoon om de opgeslagen versie te bekijken.
4 4  
5 5  {{html clean="false"}}
6 6  <style>
... ... @@ -10,6 +10,7 @@
10 10   border: 1px solid #4e5d6c;
11 11   border-radius: 4px;
12 12   overflow: hidden;
13 + background: #1a2a3a;
13 13  }
14 14  #ldsf-left {
15 15   width: 35%;
... ... @@ -33,22 +33,11 @@
33 33   min-width: 200px;
34 34   display: flex;
35 35   flex-direction: column;
37 + background: #fff;
36 36  }
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 -}
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; }
52 52  #ldsf-bookmarks li {
53 53   padding: 6px 12px;
54 54   border-bottom: 1px solid rgba(78,93,108,0.3);
... ... @@ -60,13 +60,13 @@
60 60  #ldsf-bookmarks a {
61 61   color: #5bc0de;
62 62   text-decoration: none;
53 + white-space: nowrap;
63 63   overflow: hidden;
64 64   text-overflow: ellipsis;
65 - white-space: nowrap;
66 66   font-size: 13px;
67 67  }
68 68  #ldsf-bookmarks a:hover { color: #df691a; }
69 -.sf-btn {
59 +#ldsf-bookmarks .sf-btn {
70 70   cursor: pointer;
71 71   background: #4e5d6c;
72 72   border: none;
... ... @@ -76,7 +76,7 @@
76 76   font-size: 13px;
77 77   flex-shrink: 0;
78 78  }
79 -.sf-btn:hover { background: #df691a; color: #fff; }
69 +#ldsf-bookmarks .sf-btn:hover { background: #df691a; color: #fff; }
80 80  #ldsf-viewer-bar {
81 81   display: none;
82 82   justify-content: space-between;
... ... @@ -83,7 +83,7 @@
83 83   align-items: center;
84 84   padding: 4px 12px;
85 85   background: #2b3e50;
86 - color: #ebebeb;
76 + color: #6b7c8d;
87 87   font-size: 12px;
88 88   flex-shrink: 0;
89 89   border-bottom: 1px solid #4e5d6c;
... ... @@ -90,6 +90,8 @@
90 90  }
91 91  #ldsf-viewer-bar .close-btn {
92 92   cursor: pointer;
83 + background: none;
84 + border: none;
93 93   color: #d9534f;
94 94   font-size: 18px;
95 95   padding: 0 4px;
... ... @@ -100,7 +100,6 @@
100 100   flex: 1;
101 101   border: none;
102 102   background: #fff;
103 - display: none;
104 104  }
105 105  #ldsf-placeholder {
106 106   display: flex;
... ... @@ -108,7 +108,7 @@
108 108   justify-content: center;
109 109   flex: 1;
110 110   color: #6b7c8d;
111 - font-size: 15px;
102 + font-size: 16px;
112 112   background: #2b3e50;
113 113  }
114 114  </style>
... ... @@ -121,123 +121,124 @@
121 121   <div id="ldsf-divider"></div>
122 122   <div id="ldsf-right">
123 123   <div id="ldsf-viewer-bar">
124 - <span id="ldsf-viewer-title"></span>
115 + <span id="ldsf-viewer-title">...</span>
125 125   <span class="close-btn" data-sfclose="1">&times;</span>
126 126   </div>
127 - <div id="ldsf-placeholder">Klik op &#128196; om een archief te bekijken</div>
128 - <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></iframe>
118 + <div id="ldsf-placeholder">Klik op &#128196; om archief te bekijken</div>
119 + <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin" style="display:none"></iframe>
129 129   </div>
130 130  </div>
131 131  
132 132  <script>
133 -/* --- Configuration --- */
134 -var LDSF = {
135 - linkding: 'https://bookmarks.rhebergen.org/api/bookmarks/',
136 - token: '3b7443e0f84e2b2b269adebb96d7475e4a5e653e',
137 - tag: 'Nuclear-&-Energy',
138 - count: 20,
139 - share: 'eT2X9ttBHK5GoEY',
140 - webdav: 'https://cloud.rhebergen.org/public.php/webdav/'
141 -};
142 -LDSF.auth = 'Basic ' + btoa(LDSF.share + ':');
143 -
144 -/* --- State --- */
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 + ':');
145 145  var ldsf_urlToFile = {};
146 -var ldsf_fileMap = {};
132 +var ldsf_archiveMap = {};
147 147  
148 -/* --- URL matching (exact, with/without slash, without query string) --- */
149 -function ldsfMatch(url) {
150 - var tries = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
151 - for (var i = 0; i < tries.length; i++) {
152 - if (ldsf_urlToFile[tries[i]]) return ldsf_urlToFile[tries[i]];
153 - }
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]]; }
154 154   return null;
155 155  }
156 156  
157 -/* --- Show archived page in viewer --- */
158 -function ldsfShow(filename) {
140 +function ldsfOpen(idx) {
141 + var f = ldsf_archiveMap[idx];
142 + if (f) ldsfShowArchive(f);
143 +}
144 +
145 +function ldsfShowArchive(filename) {
159 159   document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, '');
160 160   document.getElementById('ldsf-viewer-bar').style.display = 'flex';
161 161   document.getElementById('ldsf-placeholder').style.display = 'none';
162 162   var frame = document.getElementById('ldsf-viewer-frame');
163 163   frame.style.display = 'block';
164 - frame.srcdoc = '<p style="padding:20px;color:#888">Laden...</p>';
165 - fetch(LDSF.webdav + encodeURIComponent(filename), { headers: { 'Authorization': LDSF.auth } })
166 - .then(function(r) { return r.text(); })
167 - .then(function(html) { frame.srcdoc = html; })
168 - .catch(function(e) { frame.srcdoc = '<p style="padding:20px;color:#d9534f">Fout: ' + e.message + '</p>'; });
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(err) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; });
169 169  }
170 170  
171 -/* --- Close viewer --- */
172 -function ldsfClose() {
158 +function ldsfCloseViewer() {
173 173   document.getElementById('ldsf-viewer-bar').style.display = 'none';
174 174   document.getElementById('ldsf-viewer-frame').style.display = 'none';
175 175   document.getElementById('ldsf-placeholder').style.display = 'flex';
176 176  }
177 177  
178 -/* --- Render bookmark list --- */
179 -function ldsfRender(data) {
180 - var total = data.count || 0, archived = 0;
181 - var container = document.getElementById('ldsf-bookmarks');
182 - var html = '<ul>';
183 - (data.results || []).forEach(function(bm, i) {
184 - var title = bm.title || bm.website_title || bm.url;
185 - var file = ldsfMatch(bm.url);
186 - if (file) { archived++; ldsf_fileMap[i] = file; }
187 - html += '<li>';
188 - if (file) html += '<span class="sf-btn" data-sf="' + i + '" title="Archief bekijken">&#128196;</span>';
189 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>';
190 - });
191 - container.innerHTML = html + '</ul>';
192 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archived + ' met archief';
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">&#128196;</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; });
193 193  }
194 194  
195 -/* --- Click handler (event delegation, works in XWiki html macro) --- */
190 +// Global click handler for archive buttons and close button
196 196  document.addEventListener('click', function(e) {
197 - var t = e.target;
198 - if (!t || !t.getAttribute) return;
199 - var sf = t.getAttribute('data-sf');
200 - if (sf !== null && ldsf_fileMap[sf]) ldsfShow(ldsf_fileMap[sf]);
201 - if (t.getAttribute('data-sfclose') !== null) ldsfClose();
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 + }
202 202  }, true);
203 203  
204 -/* --- Draggable divider --- */
205 -var ldsf_drag = false;
206 -document.getElementById('ldsf-divider').addEventListener('mousedown', function(e) {
207 - ldsf_drag = true;
208 - this.classList.add('dragging');
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');
209 209   e.preventDefault();
210 210  });
211 211  document.addEventListener('mousemove', function(e) {
212 - if (!ldsf_drag) return;
213 - var box = document.getElementById('ldsf-container').getBoundingClientRect();
214 - var w = e.clientX - box.left;
215 - if (w >= 200 && w <= box.width * 0.6)
216 - document.getElementById('ldsf-left').style.width = w + 'px';
215 + if (!ldsf_dragging) return;
216 + var container = document.getElementById('ldsf-container');
217 + var rect = container.getBoundingClientRect();
218 + var w = e.clientX - rect.left;
219 + if (w >= 200 && w <= rect.width * 0.6) ldsf_left.style.width = w + 'px';
217 217  });
218 218  document.addEventListener('mouseup', function() {
219 - if (ldsf_drag) {
220 - ldsf_drag = false;
221 - document.getElementById('ldsf-divider').classList.remove('dragging');
222 - }
222 + if (ldsf_dragging) { ldsf_dragging = false; ldsf_divider.classList.remove('dragging'); }
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 - for (var f in idx) { if (idx.hasOwnProperty(f)) ldsf_urlToFile[idx[f]] = f; }
230 - })
231 - .catch(function() {})
232 - .then(function() {
233 - return fetch(LDSF.linkding + '?limit=' + LDSF.count + '&q=%23' + encodeURIComponent(LDSF.tag),
234 - { headers: { 'Authorization': 'Token ' + LDSF.token } });
235 - })
236 - .then(function(r) { return r.json(); })
237 - .then(ldsfRender)
238 - .catch(function(e) {
239 - document.getElementById('ldsf-status').textContent = 'Fout: ' + e.message;
240 - });
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(); });
241 241  </script>
242 242  {{/html}}
243 243