mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 10:05:40 +02:00
share functionality WIP
This commit is contained in:
@@ -1,20 +1,6 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
*, *:before, *:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body, h1, h2, h3, h4, h5, h6, p, ol, ul {
|
||||
#title {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 20px;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
#layout {
|
||||
@@ -32,6 +18,14 @@ ul {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#menu p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#menu ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
#main {
|
||||
flex-basis: 0;
|
||||
flex-grow: 3;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const shaca = require("./shaca/shaca");
|
||||
const shacaLoader = require("./shaca/shaca_loader");
|
||||
const shareRoot = require("./share_root");
|
||||
const utils = require("../services/utils");
|
||||
const {JSDOM} = require("jsdom");
|
||||
|
||||
function getSubRoot(note) {
|
||||
if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
|
||||
@@ -16,6 +18,69 @@ function getSubRoot(note) {
|
||||
return getSubRoot(parentNote);
|
||||
}
|
||||
|
||||
const NO_CONTENT = '<p>This note has no content.</p>';
|
||||
|
||||
function getChildrenList(note) {
|
||||
if (note.hasChildren()) {
|
||||
const document = new JSDOM().window.document;
|
||||
|
||||
const ulEl = document.createElement("ul");
|
||||
|
||||
for (const childNote of note.getChildNotes()) {
|
||||
const li = document.createElement("li");
|
||||
const link = document.createElement("a");
|
||||
link.appendChild(document.createTextNode(childNote.title));
|
||||
link.setAttribute("href", childNote.noteId);
|
||||
|
||||
li.appendChild(link);
|
||||
ulEl.appendChild(li);
|
||||
}
|
||||
|
||||
return '<p>Child notes:</p>' + ulEl.outerHTML;
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function getContent(note) {
|
||||
let content = note.getContent();
|
||||
|
||||
if (note.type === 'text') {
|
||||
const isEmpty = !content?.trim() || (function() {
|
||||
const document = new JSDOM(content).window.document;
|
||||
|
||||
return document.body.textContent.trim().length === 0
|
||||
&& document.querySelectorAll("img").length === 0;
|
||||
})();
|
||||
|
||||
if (isEmpty) {
|
||||
content = NO_CONTENT + getChildrenList(note);
|
||||
}
|
||||
}
|
||||
else if (note.type === 'code') {
|
||||
if (!content?.trim()) {
|
||||
content = NO_CONTENT + getChildrenList(note);
|
||||
}
|
||||
else {
|
||||
const document = new JSDOM().window.document;
|
||||
|
||||
const preEl = document.createElement('pre');
|
||||
preEl.innerText = content;
|
||||
|
||||
content = preEl.outerHTML;
|
||||
}
|
||||
}
|
||||
else if (note.type === 'book') {
|
||||
content = getChildrenList(note);
|
||||
}
|
||||
else {
|
||||
content = '<p>This note type cannot be displayed.</p>' + getChildrenList(note);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
function register(router) {
|
||||
router.get('/share/:noteId', (req, res, next) => {
|
||||
const {noteId} = req.params;
|
||||
@@ -25,10 +90,13 @@ function register(router) {
|
||||
if (noteId in shaca.notes) {
|
||||
const note = shaca.notes[noteId];
|
||||
|
||||
const content = getContent(note);
|
||||
|
||||
const subRoot = getSubRoot(note);
|
||||
|
||||
res.render("share", {
|
||||
note,
|
||||
content,
|
||||
subRoot
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="shortcut icon" href="../favicon.ico">
|
||||
<link href="../libraries/normalize.min.css" rel="stylesheet">
|
||||
<link href="../stylesheets/share.css" rel="stylesheet">
|
||||
<% if (note.type === 'text' || note.type === 'book') { %>
|
||||
<link href="../libraries/ckeditor/ckeditor-content.css" rel="stylesheet">
|
||||
@@ -14,18 +15,14 @@
|
||||
<button id="menuLink"></button>
|
||||
|
||||
<div id="menu">
|
||||
<div class="pure-menu">
|
||||
<%- include('share-tree-item', {note: subRoot, activeNote: note}) %>
|
||||
</div>
|
||||
<%- include('share-tree-item', {note: subRoot, activeNote: note}) %>
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
<h1 id="title"><%= note.title %></h1>
|
||||
|
||||
<div id="content">
|
||||
<% if (note.type === 'text') { %>
|
||||
<div class="ck-content"><%- note.getContent() %></div>
|
||||
<% } %>
|
||||
<div class="ck-content"><%- content %></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user