mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
various tweaks to shared notes
This commit is contained in:
parent
b8fe9a41db
commit
3128a7d62f
@ -72,6 +72,47 @@ iframe.pdf-view {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#child-links.grid ul {
|
||||||
|
list-style-type: none;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#child-links.grid ul li {
|
||||||
|
width: 180px;
|
||||||
|
height: 140px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#child-links.grid ul li a {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 5px;
|
||||||
|
justify-content: center;
|
||||||
|
align-content: center;
|
||||||
|
text-align: center;
|
||||||
|
font-size: large;
|
||||||
|
}
|
||||||
|
|
||||||
|
#child-links.grid ul li a:hover {
|
||||||
|
background: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#child-links.list ul {
|
||||||
|
list-style-type: none;
|
||||||
|
display: inline-flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#child-links.list ul li {
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
#menuButton::after {
|
#menuButton::after {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: -2px;
|
top: -2px;
|
||||||
|
@ -54,7 +54,7 @@ function getYearNote(dateStr, rootNote) {
|
|||||||
rootNote = getRootCalendarNote();
|
rootNote = getRootCalendarNote();
|
||||||
}
|
}
|
||||||
|
|
||||||
const yearStr = dateStr.substr(0, 4);
|
const yearStr = dateStr.trim().substr(0, 4);
|
||||||
|
|
||||||
let yearNote = attributeService.getNoteWithLabel(YEAR_LABEL, yearStr);
|
let yearNote = attributeService.getNoteWithLabel(YEAR_LABEL, yearStr);
|
||||||
|
|
||||||
@ -138,6 +138,8 @@ function getDateNoteTitle(rootNote, dayNumber, dateObj) {
|
|||||||
|
|
||||||
/** @returns {Note} */
|
/** @returns {Note} */
|
||||||
function getDateNote(dateStr) {
|
function getDateNote(dateStr) {
|
||||||
|
dateStr = dateStr.trim().substr(0, 10);
|
||||||
|
|
||||||
let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr);
|
let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr);
|
||||||
|
|
||||||
if (dateNote) {
|
if (dateNote) {
|
||||||
|
@ -1,43 +1,18 @@
|
|||||||
const {JSDOM} = require("jsdom");
|
const {JSDOM} = require("jsdom");
|
||||||
const NO_CONTENT = '<p>This note has no content.</p>';
|
|
||||||
const shaca = require("./shaca/shaca");
|
const shaca = require("./shaca/shaca");
|
||||||
|
|
||||||
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) {
|
function getContent(note) {
|
||||||
let content = note.getContent();
|
let content = note.getContent();
|
||||||
|
let header = '';
|
||||||
|
let isEmpty = false;
|
||||||
|
|
||||||
if (note.type === 'text') {
|
if (note.type === 'text') {
|
||||||
const document = new JSDOM(content || "").window.document;
|
const document = new JSDOM(content || "").window.document;
|
||||||
|
|
||||||
const isEmpty = document.body.textContent.trim().length === 0
|
isEmpty = document.body.textContent.trim().length === 0
|
||||||
&& document.querySelectorAll("img").length === 0;
|
&& document.querySelectorAll("img").length === 0;
|
||||||
|
|
||||||
if (isEmpty) {
|
if (!isEmpty) {
|
||||||
content = NO_CONTENT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (const linkEl of document.querySelectorAll("a")) {
|
for (const linkEl of document.querySelectorAll("a")) {
|
||||||
const href = linkEl.getAttribute("href");
|
const href = linkEl.getAttribute("href");
|
||||||
|
|
||||||
@ -49,6 +24,7 @@ function getContent(note) {
|
|||||||
|
|
||||||
if (linkedNote) {
|
if (linkedNote) {
|
||||||
linkEl.setAttribute("href", linkedNote.shareId);
|
linkEl.setAttribute("href", linkedNote.shareId);
|
||||||
|
linkEl.classList.add("type-" + linkedNote.type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
linkEl.removeAttribute("href");
|
linkEl.removeAttribute("href");
|
||||||
@ -59,25 +35,36 @@ function getContent(note) {
|
|||||||
content = document.body.innerHTML;
|
content = document.body.innerHTML;
|
||||||
|
|
||||||
if (content.includes(`<span class="math-tex">`)) {
|
if (content.includes(`<span class="math-tex">`)) {
|
||||||
content += `<script src="../../libraries/katex/katex.min.js"></script>`;
|
header += `
|
||||||
content += `<link rel="stylesheet" href="../../libraries/katex/katex.min.css">`;
|
<script src="../../libraries/katex/katex.min.js"></script>
|
||||||
content += `<script src="../../libraries/katex/auto-render.min.js" onload="renderMathInElement(document.getElementById('content'));"></script>`;
|
<link rel="stylesheet" href="../../libraries/katex/katex.min.css">
|
||||||
content += `<script src="../../libraries/katex/mhchem.min.js"></script>`;
|
<script src="../../libraries/katex/auto-render.min.js" onload="renderMathInElement(document.getElementById('content'));"></script>
|
||||||
|
<script src="../../libraries/katex/mhchem.min.js"></script>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (note.type === 'code') {
|
else if (note.type === 'code') {
|
||||||
if (!content?.trim()) {
|
if (!content?.trim()) {
|
||||||
content = NO_CONTENT;
|
isEmpty = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
content = `<textarea style="width:100px;" id="code">${content}</textarea>`
|
const document = new JSDOM().window.document;
|
||||||
content += `<link rel="stylesheet" href="../../libraries/codemirror/codemirror.css">`
|
|
||||||
content += `<script src="../../libraries/codemirror/codemirror.js" onload="var editor = CodeMirror.fromTextArea(document.getElementById('code'), {lineNumbers: true, lineWrapping: true});"></script>`
|
const preEl = document.createElement('pre');
|
||||||
|
preEl.appendChild(document.createTextNode(content));
|
||||||
|
|
||||||
|
content = preEl.outerHTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (note.type === 'mermaid') {
|
else if (note.type === 'mermaid') {
|
||||||
content = `<div class=\"mermaid\">${content}</div><script src=\"../../libraries/mermaid.min.js\"></script><hr><details><summary>Chart source</summary><pre>${content}</pre></details>`
|
content = `
|
||||||
|
<div class="mermaid">${content}</div>
|
||||||
|
<hr>
|
||||||
|
<details>
|
||||||
|
<summary>Chart source</summary>
|
||||||
|
<pre>${content}</pre>
|
||||||
|
</details>`
|
||||||
|
header += `<script src="../../libraries/mermaid.min.js"></script>`;
|
||||||
}
|
}
|
||||||
else if (note.type === 'image') {
|
else if (note.type === 'image') {
|
||||||
content = `<img src="api/images/${note.noteId}/${note.title}?${note.utcDateModified}">`;
|
content = `<img src="api/images/${note.noteId}/${note.title}?${note.utcDateModified}">`;
|
||||||
@ -90,13 +77,18 @@ function getContent(note) {
|
|||||||
content = `<button type="button" onclick="location.href='api/notes/${note.noteId}/download'">Download file</button>`;
|
content = `<button type="button" onclick="location.href='api/notes/${note.noteId}/download'">Download file</button>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (note.type === 'book') {
|
||||||
|
isEmpty = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
content = '<p>This note type cannot be displayed.</p>';
|
content = '<p>This note type cannot be displayed.</p>';
|
||||||
}
|
}
|
||||||
var child = getChildrenList(note);
|
|
||||||
content += child === '' ? '' : `<hr>${child}`;
|
|
||||||
|
|
||||||
return content;
|
return {
|
||||||
|
header,
|
||||||
|
content,
|
||||||
|
isEmpty
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -29,13 +29,15 @@ function register(router) {
|
|||||||
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
const content = contentRenderer.getContent(note);
|
const {header, content, isEmpty} = contentRenderer.getContent(note);
|
||||||
|
|
||||||
const subRoot = getSharedSubTreeRoot(note);
|
const subRoot = getSharedSubTreeRoot(note);
|
||||||
|
|
||||||
res.render("share/page", {
|
res.render("share/page", {
|
||||||
note,
|
note,
|
||||||
|
header,
|
||||||
content,
|
content,
|
||||||
|
isEmpty,
|
||||||
subRoot
|
subRoot
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,46 @@
|
|||||||
<% for (const cssRelation of note.getRelations("shareCss")) { %>
|
<% for (const cssRelation of note.getRelations("shareCss")) { %>
|
||||||
<link href="api/notes/<%= cssRelation.value %>/download" rel="stylesheet">
|
<link href="api/notes/<%= cssRelation.value %>/download" rel="stylesheet">
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<%- header %>
|
||||||
<title><%= note.title %></title>
|
<title><%= note.title %></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="layout">
|
<div id="layout">
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<br>
|
<br>
|
||||||
<% if (note.parents[0].noteId !== 'share' && note.parents.length != 0) { %>
|
<% if (note.parents[0].noteId !== 'share' && note.parents.length !== 0) { %>
|
||||||
<nav class="parent-link">
|
<nav id="parent-link">
|
||||||
<a href="<%= note.parents[0].noteId %>">< Parent note (<%= note.parents[0].title %>)</a>
|
Parent note: <a href="<%= note.parents[0].noteId %>" class="type-<% note.type %>"><%= note.parents[0].title %></a>
|
||||||
</nav>
|
</nav>
|
||||||
<% } %>
|
<% } %>
|
||||||
<h1 id="title"><%= note.title %></h1>
|
<h1 id="title"><%= note.title %></h1>
|
||||||
|
|
||||||
<div id="content" class="note-<%= note.type %><% if (note.type === 'text') { %>ck-content<% } %>">
|
<% if (note.type === 'book') { %>
|
||||||
|
<% } else if (isEmpty) { %>
|
||||||
|
<p>This note has no content.</p>
|
||||||
|
<% } else { %>
|
||||||
|
<div id="content" class="type-<%= note.type %><% if (note.type === 'text') { %>ck-content<% } %>">
|
||||||
<%- content %>
|
<%- content %>
|
||||||
</div>
|
</div>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
<% if (note.hasChildren()) { %>
|
||||||
|
<nav id="child-links" class="<% if (isEmpty) { %>grid<% } else { %>list<% } %>">
|
||||||
|
<% if (!isEmpty) { %>
|
||||||
|
<hr>
|
||||||
|
<span>Child notes: </span>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% for (const childNote of note.getChildNotes()) { %>
|
||||||
|
<li>
|
||||||
|
<a href="<%= childNote.shareId %>"
|
||||||
|
class="type-<% childNote.type %>"><%= childNote.title %></a>
|
||||||
|
</li>
|
||||||
|
<% } %>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if (subRoot.hasChildren()) { %>
|
<% if (subRoot.hasChildren()) { %>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<% if (activeNote.noteId === note.noteId) { %>
|
<% if (activeNote.noteId === note.noteId) { %>
|
||||||
<strong><%= note.title %></strong>
|
<strong><%= note.title %></strong>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a href="./<%= note.shareId %>"><%= note.title %></a>
|
<a class="type-<%= note.type %>" href="./<%= note.shareId %>"><%= note.title %></a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user