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 5.1
edited by XWikiGuest
on 2026/03/11 20:26
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,95 +1,68 @@
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>
7 -#ldsf-container {
7 +#ldsf-wrapper {
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;
21 21   flex-direction: column;
10 + gap: 0;
22 22  }
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 -}
43 43  #ldsf-bookmarks {
44 - overflow-y: auto;
45 - flex: 1;
13 + color: #ebebeb;
46 46  }
47 47  #ldsf-bookmarks ul {
48 48   list-style: none;
49 49   padding: 0;
50 - margin: 0;
51 51  }
52 52  #ldsf-bookmarks li {
53 53   padding: 6px 12px;
54 - border-bottom: 1px solid rgba(78,93,108,0.3);
21 + background: #2b3e50;
22 + border-left: 3px solid #df691a;
23 + border-radius: 0 4px 4px 0;
24 + margin: 4px 0;
55 55   display: flex;
56 56   align-items: center;
57 57   gap: 8px;
58 58  }
59 59  #ldsf-bookmarks li:hover { background: #3b4e60; }
60 -#ldsf-bookmarks a {
61 - color: #5bc0de;
62 - text-decoration: none;
63 - overflow: hidden;
64 - text-overflow: ellipsis;
65 - white-space: nowrap;
66 - font-size: 13px;
67 -}
30 +#ldsf-bookmarks a { color: #5bc0de; text-decoration: none; }
68 68  #ldsf-bookmarks a:hover { color: #df691a; }
69 -.sf-btn {
32 +#ldsf-bookmarks .sf-btn {
70 70   cursor: pointer;
71 71   background: #4e5d6c;
72 72   border: none;
73 73   color: #5bc0de;
74 - padding: 2px 6px;
37 + padding: 2px 8px;
75 75   border-radius: 3px;
76 - font-size: 13px;
39 + font-size: 14px;
77 77   flex-shrink: 0;
78 78  }
79 -.sf-btn:hover { background: #df691a; color: #fff; }
80 -#ldsf-viewer-bar {
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 {
81 81   display: none;
47 + margin-top: 10px;
48 + border: 1px solid #4e5d6c;
49 + border-radius: 4px;
50 + overflow: hidden;
51 + background: #1a2a3a;
52 +}
53 +#ldsf-viewer-bar {
54 + display: flex;
82 82   justify-content: space-between;
83 83   align-items: center;
84 - padding: 4px 12px;
57 + padding: 6px 12px;
85 85   background: #2b3e50;
86 - color: #ebebeb;
87 - font-size: 12px;
88 - flex-shrink: 0;
89 - border-bottom: 1px solid #4e5d6c;
59 + color: #6b7c8d;
60 + font-size: 13px;
90 90  }
91 91  #ldsf-viewer-bar .close-btn {
92 92   cursor: pointer;
64 + background: none;
65 + border: none;
93 93   color: #d9534f;
94 94   font-size: 18px;
95 95   padding: 0 4px;
... ... @@ -97,147 +97,128 @@
97 97  #ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; }
98 98  #ldsf-viewer-frame {
99 99   width: 100%;
100 - flex: 1;
73 + height: 70vh;
101 101   border: none;
102 102   background: #fff;
103 - display: none;
104 104  }
105 -#ldsf-placeholder {
106 - display: flex;
107 - align-items: center;
108 - justify-content: center;
109 - flex: 1;
110 - color: #6b7c8d;
111 - font-size: 15px;
112 - background: #2b3e50;
113 -}
77 +#ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; }
114 114  </style>
115 115  
116 -<div id="ldsf-container">
117 - <div id="ldsf-left">
118 - <div id="ldsf-status">Laden...</div>
119 - <div id="ldsf-bookmarks"></div>
120 - </div>
121 - <div id="ldsf-divider"></div>
122 - <div id="ldsf-right">
80 +<div id="ldsf-wrapper">
81 + <div id="ldsf-status">Laden...</div>
82 + <div id="ldsf-bookmarks"></div>
83 + <div id="ldsf-viewer-container">
123 123   <div id="ldsf-viewer-bar">
124 - <span id="ldsf-viewer-title"></span>
125 - <span class="close-btn" data-sfclose="1">&times;</span>
85 + <span id="ldsf-viewer-title">...</span>
86 + <button class="close-btn" onclick="ldsfCloseViewer()">&times;</button>
126 126   </div>
127 - <div id="ldsf-placeholder">Klik op &#128196; om een archief te bekijken</div>
128 128   <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></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 + ':');
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;
143 143  
144 -/* --- State --- */
145 -var ldsf_urlToFile = {};
146 -var ldsf_fileMap = {};
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 + ':');
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]];
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;
153 153   }
154 - return null;
155 -}
156 156  
157 -/* --- Show archived page in viewer --- */
158 -function ldsfShow(filename) {
159 - document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, '');
160 - document.getElementById('ldsf-viewer-bar').style.display = 'flex';
161 - document.getElementById('ldsf-placeholder').style.display = 'none';
162 - var frame = document.getElementById('ldsf-viewer-frame');
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>'; });
169 -}
116 + // Load SingleFile index, then load bookmarks
117 + fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
118 + .then(function(r) { return r.ok ? r.json() : {}; })
119 + .then(function(index) {
120 + // Build reverse map: URL -> filename
121 + Object.keys(index).forEach(function(fname) {
122 + urlToFile[index[fname]] = fname;
123 + });
124 + loadBookmarks();
125 + })
126 + .catch(function() {
127 + loadBookmarks(); // Continue without index
128 + });
170 170  
171 -/* --- Close viewer --- */
172 -function ldsfClose() {
173 - document.getElementById('ldsf-viewer-bar').style.display = 'none';
174 - document.getElementById('ldsf-viewer-frame').style.display = 'none';
175 - document.getElementById('ldsf-placeholder').style.display = 'flex';
176 -}
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>';
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';
193 -}
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++;
194 194  
195 -/* --- Click handler (event delegation, works in XWiki html macro) --- */
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();
202 -}, true);
145 + html += '<li>';
146 + if (fname) {
147 + archiveMap[idx] = fname;
148 + html += '<button class="sf-btn" onclick="ldsfOpen(' + idx + ')" title="Archief bekijken">&#128196;</button>';
149 + }
150 + html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
151 + html += '</li>';
152 + });
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');
209 - e.preventDefault();
210 -});
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';
217 -});
218 -document.addEventListener('mouseup', function() {
219 - if (ldsf_drag) {
220 - ldsf_drag = false;
221 - document.getElementById('ldsf-divider').classList.remove('dragging');
154 + html += '</ul>';
155 + container.innerHTML = html;
156 + document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
157 + })
158 + .catch(function(err) {
159 + document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
160 + });
222 222   }
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 - });
163 + // Open archive by index
164 + window.ldsfOpen = function(idx) {
165 + var filename = archiveMap[idx];
166 + if (!filename) return;
167 + ldsfShowArchive(filename);
168 + };
169 +
170 + // Show archive in viewer panel
171 + window.ldsfShowArchive = function(filename) {
172 + var container = document.getElementById('ldsf-viewer-container');
173 + var frame = document.getElementById('ldsf-viewer-frame');
174 + var titleEl = document.getElementById('ldsf-viewer-title');
175 +
176 + titleEl.textContent = filename.replace(/\.html?$/i, '');
177 + container.style.display = 'block';
178 + frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
179 +
180 + fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } })
181 + .then(function(r) { return r.text(); })
182 + .then(function(html) {
183 + frame.srcdoc = html;
184 + })
185 + .catch(function(err) {
186 + frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>';
187 + });
188 + };
189 +
190 + window.ldsfCloseViewer = function() {
191 + document.getElementById('ldsf-viewer-container').style.display = 'none';
192 + document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
193 + };
194 +})();
241 241  </script>
242 242  {{/html}}
243 243