Skip to content

Commit 1783713

Browse files
committed
fix page titles
add print buttons for presentations and flow-text to settings dropdown
1 parent be2d0d8 commit 1783713

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

app.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const DOMPurify = createDOMPurify(window);
9595
const app = express();
9696
app.set("trust proxy", true);
9797

98-
import { scanFiles, scanFonts, preParse, manipulateHtml, wrapInPage, wrapInReveal, splitForReveal, parseFirstLineForPermissions } from "./obsidian.js";
98+
import { scanFiles, scanFonts, preParse, manipulateHtml, wrapInPage, wrapInReveal, splitForReveal, parseFirstLineForPermissions, wrapAsDocument } from "./obsidian.js";
9999
import { hasSomeRoles } from "./utils.js";
100100

101101
async function sanitizeAndParseMarkdown(data, req) {
@@ -199,12 +199,22 @@ initKeycloak(app).then(() => {
199199
});
200200
});
201201
} else {
202-
sanitizeAndParseMarkdown(data, req).then((html) => {
203-
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
204-
wrapInPage(html, getStartPage(), req).then((r) => {
205-
res.send(r);
202+
const doc = req.query.document;
203+
if (doc) {
204+
sanitizeAndParseMarkdown(data, req).then((html) => {
205+
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
206+
wrapAsDocument(html, req).then((r) => {
207+
res.send(r);
208+
});
206209
});
207-
});
210+
} else {
211+
sanitizeAndParseMarkdown(data, req).then((html) => {
212+
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
213+
wrapInPage(html, getStartPage(), req).then((r) => {
214+
res.send(r);
215+
});
216+
});
217+
}
208218
}
209219
});
210220
} else {

obsidian-page.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function toggleTopdownMenu() {
165165
}
166166
}
167167

168-
function openAsPresentation() {
168+
function openAsPresentation(print) {
169169
let url = new URL(window.location.href);
170170
if (print) {
171171
url.searchParams.set("print-pdf", "true")
@@ -174,6 +174,12 @@ function openAsPresentation() {
174174
window.open(url, "_blank");
175175
}
176176

177+
function openAsDocument() {
178+
const url = new URL(window.location.href);
179+
url.searchParams.set("document", "true");
180+
window.open(url, "_blank");
181+
}
182+
177183
let mainFontsArray = [];
178184

179185
let navFontsArray = [];

obsidian.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,22 @@ async function getTopdownMenu(req) {
988988
</div>`
989989
: ""
990990
}
991+
<div style="padding: 0px; margin: 0px; margin-left: 0px; margin-top: 25px; margin-bottom: -10px; text-align: left; display: flex;">
992+
<button class="sl-button" style="height: 32px; margin: 0px;" onclick="openAsPresentation(true)">${lucideIcon(
993+
"Printer"
994+
)}
995+
${lucideIcon(
996+
"Presentation"
997+
)}
998+
</button>
999+
<button class="sl-button" style="height: 32px; margin: 0px; margin-left: 6px" onclick="openAsDocument(true)">${lucideIcon(
1000+
"Printer"
1001+
)}
1002+
${lucideIcon(
1003+
"ReceiptText"
1004+
)}
1005+
</button>
1006+
</div>
9911007
</div>
9921008
`;
9931009
}
@@ -1021,9 +1037,6 @@ async function getTopBar(startPage, req) {
10211037
<button class="sl-button" style="height: 32px; margin: 6px;" onclick="openAsPresentation(false)">${lucideIcon(
10221038
"Presentation"
10231039
)}</button>
1024-
<button class="sl-button" style="height: 32px; margin: 6px;" onclick="openAsPresentation(true)">${lucideIcon(
1025-
"Printer"
1026-
)}</button>
10271040
<button class="sl-button-accent topdown-menu-chevron" style="height: 32px; margin: 6px;" onclick="toggleTopdownMenu()">${lucideIcon(
10281041
"Settings"
10291042
)}</button>
@@ -1062,6 +1075,7 @@ export async function wrapInPage(html, startPage, req) {
10621075
</style>
10631076
<link rel="stylesheet" href="/css/main.css">
10641077
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
1078+
<title>${req.file.name}</title>
10651079
</head>
10661080
<body style="display: none;">
10671081
<div id="topbar">${await getTopBar(startPage, req)}</div>
@@ -1091,6 +1105,39 @@ export async function wrapInPage(html, startPage, req) {
10911105
return pre + html + post;
10921106
}
10931107

1108+
export async function wrapAsDocument(html, req) {
1109+
const pre = `
1110+
<!DOCTYPE html>
1111+
<html lang="en">
1112+
<head>
1113+
<meta charset="UTF-8">
1114+
<style>
1115+
${await getFontImports()}
1116+
</style>
1117+
<link rel="stylesheet" href="/css/main.css">
1118+
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
1119+
<title>${req.file.name}</title>
1120+
</head>
1121+
<body style="display: none;">
1122+
<div id="wrapper">
1123+
<div id="markdown-content">
1124+
`;
1125+
const post = `
1126+
</div>
1127+
</div>
1128+
<script src="/obsidian-page.js"></script>
1129+
<script lang="javascript">
1130+
initFonts('${JSON.stringify(mainFontsArray)}', '${JSON.stringify(
1131+
navFontsArray
1132+
)}');
1133+
init();
1134+
</script>
1135+
</body>
1136+
</html>
1137+
`;
1138+
return pre + html + post;
1139+
}
1140+
10941141
export async function wrapInReveal(reveal, req) {
10951142
const pre = `
10961143
<!DOCTYPE html>

0 commit comments

Comments
 (0)