Wiki source code of Linkding + SingleFile Test
Version 2.1 by XWikiGuest on 2026/03/11 20:04
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | = Linkding + SingleFile Test = |
| 2 | |||
| 3 | Bookmarks met archief-viewer. Klik op het archief-icoon om de opgeslagen versie te bekijken. | ||
| 4 | |||
| 5 | {{html clean="false"}} | ||
| 6 | <style> | ||
| 7 | #ldsf-wrapper { | ||
| 8 | display: flex; | ||
| 9 | flex-direction: column; | ||
| 10 | gap: 0; | ||
| 11 | } | ||
| 12 | #ldsf-bookmarks { | ||
| 13 | color: #ebebeb; | ||
| 14 | } | ||
| 15 | #ldsf-bookmarks ul { | ||
| 16 | list-style: none; | ||
| 17 | padding: 0; | ||
| 18 | } | ||
| 19 | #ldsf-bookmarks li { | ||
| 20 | padding: 6px 12px; | ||
| 21 | background: #2b3e50; | ||
| 22 | border-left: 3px solid #df691a; | ||
| 23 | border-radius: 0 4px 4px 0; | ||
| 24 | margin: 4px 0; | ||
| 25 | display: flex; | ||
| 26 | align-items: center; | ||
| 27 | gap: 8px; | ||
| 28 | } | ||
| 29 | #ldsf-bookmarks li:hover { background: #3b4e60; } | ||
| 30 | #ldsf-bookmarks a { color: #5bc0de; text-decoration: none; } | ||
| 31 | #ldsf-bookmarks a:hover { color: #df691a; } | ||
| 32 | #ldsf-bookmarks .sf-btn { | ||
| 33 | cursor: pointer; | ||
| 34 | background: #4e5d6c; | ||
| 35 | border: none; | ||
| 36 | color: #5bc0de; | ||
| 37 | padding: 2px 8px; | ||
| 38 | border-radius: 3px; | ||
| 39 | font-size: 14px; | ||
| 40 | flex-shrink: 0; | ||
| 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 | } | ||
| 53 | #ldsf-viewer-bar { | ||
| 54 | display: flex; | ||
| 55 | justify-content: space-between; | ||
| 56 | align-items: center; | ||
| 57 | padding: 6px 12px; | ||
| 58 | background: #2b3e50; | ||
| 59 | color: #6b7c8d; | ||
| 60 | font-size: 13px; | ||
| 61 | } | ||
| 62 | #ldsf-viewer-bar .close-btn { | ||
| 63 | cursor: pointer; | ||
| 64 | background: none; | ||
| 65 | border: none; | ||
| 66 | color: #d9534f; | ||
| 67 | font-size: 18px; | ||
| 68 | padding: 0 4px; | ||
| 69 | } | ||
| 70 | #ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; } | ||
| 71 | #ldsf-viewer-frame { | ||
| 72 | width: 100%; | ||
| 73 | height: 70vh; | ||
| 74 | border: none; | ||
| 75 | background: #fff; | ||
| 76 | } | ||
| 77 | #ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; } | ||
| 78 | </style> | ||
| 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"> | ||
| 84 | <div id="ldsf-viewer-bar"> | ||
| 85 | <span id="ldsf-viewer-title">...</span> | ||
| 86 | <button class="close-btn" onclick="ldsfCloseViewer()">×</button> | ||
| 87 | </div> | ||
| 88 | <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></iframe> | ||
| 89 | </div> | ||
| 90 | </div> | ||
| 91 | |||
| 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; | ||
| 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='; | ||
| 102 | |||
| 103 | var urlToFile = {}; // reverse map: URL -> filename | ||
| |
2.1 | 104 | var archiveMap = {}; // button index -> filename |
| |
1.1 | 105 | |
| |
2.1 | 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 | } | ||
| 114 | |||
| |
1.1 | 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 | }); | ||
| 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 | var html = '<ul>'; | ||
| 138 | |||
| |
2.1 | 139 | (data.results || []).forEach(function(bm, idx) { |
| |
1.1 | 140 | var title = bm.title || bm.website_title || bm.url; |
| |
2.1 | 141 | var fname = findArchive(bm.url); |
| 142 | if (fname) archiveCount++; | ||
| |
1.1 | 143 | |
| 144 | html += '<li>'; | ||
| |
2.1 | 145 | if (fname) { |
| 146 | html += '<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">📄</button>'; | ||
| 147 | archiveMap[idx] = fname; | ||
| |
1.1 | 148 | } |
| 149 | html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>'; | ||
| 150 | html += '</li>'; | ||
| 151 | }); | ||
| 152 | |||
| 153 | html += '</ul>'; | ||
| 154 | container.innerHTML = html; | ||
| 155 | document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; | ||
| |
2.1 | 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 | }); | ||
| |
1.1 | 166 | }) |
| 167 | .catch(function(err) { | ||
| 168 | document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; | ||
| 169 | }); | ||
| 170 | } | ||
| 171 | |||
| 172 | // Show archive in viewer panel | ||
| |
2.1 | 173 | window.ldsfShowArchive = function(filename, btn) { |
| |
1.1 | 174 | var container = document.getElementById('ldsf-viewer-container'); |
| 175 | var frame = document.getElementById('ldsf-viewer-frame'); | ||
| 176 | var titleEl = document.getElementById('ldsf-viewer-title'); | ||
| 177 | |||
| 178 | // Toggle active button | ||
| 179 | document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); | ||
| 180 | btn.classList.add('active'); | ||
| 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 | })(); | ||
| 201 | </script> | ||
| 202 | {{/html}} | ||
| 203 |