Linkding + SingleFile Test

Version 1.1 by XWikiGuest on 2026/03/11 19:55
Warning
For security reasons, the document is displayed in restricted mode as it is not the current version. There may be differences and errors due to this.

Linkding + SingleFile Test

Bookmarks met archief-viewer. Klik op het archief-icoon om de opgeslagen versie te bekijken.

#ldsf-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#ldsf-bookmarks {
  color: #ebebeb;
}
#ldsf-bookmarks ul {
  list-style: none;
  padding: 0;
}
#ldsf-bookmarks li {
  padding: 6px 12px;
  background: #2b3e50;
  border-left: 3px solid #df691a;
  border-radius: 0 4px 4px 0;
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
#ldsf-bookmarks li:hover { background: #3b4e60; }
#ldsf-bookmarks a { color: #5bc0de; text-decoration: none; }
#ldsf-bookmarks a:hover { color: #df691a; }
#ldsf-bookmarks .sf-btn {
  cursor: pointer;
  background: #4e5d6c;
  border: none;
  color: #5bc0de;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 14px;
  flex-shrink: 0;
}
#ldsf-bookmarks .sf-btn:hover { background: #df691a; color: #fff; }
#ldsf-bookmarks .sf-btn.active { background: #df691a; color: #fff; }

#ldsf-viewer-container {
  display: none;
  margin-top: 10px;
  border: 1px solid #4e5d6c;
  border-radius: 4px;
  overflow: hidden;
  background: #1a2a3a;
}
#ldsf-viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #2b3e50;
  color: #6b7c8d;
  font-size: 13px;
}
#ldsf-viewer-bar .close-btn {
  cursor: pointer;
  background: none;
  border: none;
  color: #d9534f;
  font-size: 18px;
  padding: 0 4px;
}
#ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; }
#ldsf-viewer-frame {
  width: 100%;
  height: 70vh;
  border: none;
  background: #fff;
}
#ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; }
Laden...
...
(function() {
  var LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/';
  var LINKDING_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e';
  var LINKDING_TAG = 'Nuclear-&-Energy';
  var LINKDING_COUNT = 20;

  var WEBDAV_BASE = 'https://cloud.rhebergen.org/remote.php/dav/files/jan_rhebergen/SingleFile-Archives/';
  var INDEX_URL = WEBDAV_BASE + 'index.json';
  var NC_AUTH = 'Basic amFuX3JoZWJlcmdlbjpAWnMzUUwkJmZ4TVE=';

  var urlToFile = {};  // reverse map: URL -> filename

  // Load SingleFile index, then load bookmarks
  fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
  .then(function(r) { return r.ok ? r.json() : {}; })
  .then(function(index) {
    // Build reverse map: URL -> filename
    Object.keys(index).forEach(function(fname) {
      urlToFile[index[fname]] = fname;
    });
    loadBookmarks();
  })
  .catch(function() {
    loadBookmarks();  // Continue without index
  });

  function loadBookmarks() {
    var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG);
    fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_TOKEN } })
    .then(function(r) { return r.json(); })
    .then(function(data) {
      var total = data.count || 0;
      var archiveCount = 0;
      var container = document.getElementById('ldsf-bookmarks');
      var html = '
  • '; (data.results || []).forEach(function(bm) { var title = bm.title || bm.website_title || bm.url; var hasArchive = urlToFile[bm.url] || urlToFile[bm.url.replace(/\/$/, '')] || urlToFile[bm.url + '/']; if (hasArchive) archiveCount++; html += '
  • '; if (hasArchive) { var fname = urlToFile[bm.url] || urlToFile[bm.url.replace(/\/$/, '')] || urlToFile[bm.url + '/']; html += ''; } html += '' + title + ''; html += ''; }); html += '
'; container.innerHTML = html; document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; }) .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); } // Show archive in viewer panel window.ldsfShowArchive = function(encodedFilename, btn) { var filename = decodeURIComponent(encodedFilename); var container = document.getElementById('ldsf-viewer-container'); var frame = document.getElementById('ldsf-viewer-frame'); var titleEl = document.getElementById('ldsf-viewer-title'); // Toggle active button document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); btn.classList.add('active'); titleEl.textContent = filename.replace(/\.html?$/i, ''); container.style.display = 'block'; frame.srcdoc = '

Laden...

'; fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } }) .then(function(r) { return r.text(); }) .then(function(html) { frame.srcdoc = html; }) .catch(function(err) { frame.srcdoc = '

Fout: ' + err.message + '

'; }); }; window.ldsfCloseViewer = function() { document.getElementById('ldsf-viewer-container').style.display = 'none'; document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); }; })();