Skip to content

Commit

Permalink
fix page titles
Browse files Browse the repository at this point in the history
add print buttons for presentations and flow-text to settings dropdown
  • Loading branch information
guFalcon committed Jan 15, 2025
1 parent be2d0d8 commit 1783713
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
22 changes: 16 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const DOMPurify = createDOMPurify(window);
const app = express();
app.set("trust proxy", true);

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

async function sanitizeAndParseMarkdown(data, req) {
Expand Down Expand Up @@ -199,12 +199,22 @@ initKeycloak(app).then(() => {
});
});
} else {
sanitizeAndParseMarkdown(data, req).then((html) => {
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
wrapInPage(html, getStartPage(), req).then((r) => {
res.send(r);
const doc = req.query.document;
if (doc) {
sanitizeAndParseMarkdown(data, req).then((html) => {
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
wrapAsDocument(html, req).then((r) => {
res.send(r);
});
});
});
} else {
sanitizeAndParseMarkdown(data, req).then((html) => {
setUserAttribute(req, "lastVisitedUrl", req.originalUrl);
wrapInPage(html, getStartPage(), req).then((r) => {
res.send(r);
});
});
}
}
});
} else {
Expand Down
8 changes: 7 additions & 1 deletion obsidian-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function toggleTopdownMenu() {
}
}

function openAsPresentation() {
function openAsPresentation(print) {
let url = new URL(window.location.href);
if (print) {
url.searchParams.set("print-pdf", "true")
Expand All @@ -174,6 +174,12 @@ function openAsPresentation() {
window.open(url, "_blank");
}

function openAsDocument() {
const url = new URL(window.location.href);
url.searchParams.set("document", "true");
window.open(url, "_blank");
}

let mainFontsArray = [];

let navFontsArray = [];
Expand Down
53 changes: 50 additions & 3 deletions obsidian.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,22 @@ async function getTopdownMenu(req) {
</div>`
: ""
}
<div style="padding: 0px; margin: 0px; margin-left: 0px; margin-top: 25px; margin-bottom: -10px; text-align: left; display: flex;">
<button class="sl-button" style="height: 32px; margin: 0px;" onclick="openAsPresentation(true)">${lucideIcon(
"Printer"
)}
${lucideIcon(
"Presentation"
)}
</button>
<button class="sl-button" style="height: 32px; margin: 0px; margin-left: 6px" onclick="openAsDocument(true)">${lucideIcon(
"Printer"
)}
${lucideIcon(
"ReceiptText"
)}
</button>
</div>
</div>
`;
}
Expand Down Expand Up @@ -1021,9 +1037,6 @@ async function getTopBar(startPage, req) {
<button class="sl-button" style="height: 32px; margin: 6px;" onclick="openAsPresentation(false)">${lucideIcon(
"Presentation"
)}</button>
<button class="sl-button" style="height: 32px; margin: 6px;" onclick="openAsPresentation(true)">${lucideIcon(
"Printer"
)}</button>
<button class="sl-button-accent topdown-menu-chevron" style="height: 32px; margin: 6px;" onclick="toggleTopdownMenu()">${lucideIcon(
"Settings"
)}</button>
Expand Down Expand Up @@ -1062,6 +1075,7 @@ export async function wrapInPage(html, startPage, req) {
</style>
<link rel="stylesheet" href="/css/main.css">
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
<title>${req.file.name}</title>
</head>
<body style="display: none;">
<div id="topbar">${await getTopBar(startPage, req)}</div>
Expand Down Expand Up @@ -1091,6 +1105,39 @@ export async function wrapInPage(html, startPage, req) {
return pre + html + post;
}

export async function wrapAsDocument(html, req) {
const pre = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
${await getFontImports()}
</style>
<link rel="stylesheet" href="/css/main.css">
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
<title>${req.file.name}</title>
</head>
<body style="display: none;">
<div id="wrapper">
<div id="markdown-content">
`;
const post = `
</div>
</div>
<script src="/obsidian-page.js"></script>
<script lang="javascript">
initFonts('${JSON.stringify(mainFontsArray)}', '${JSON.stringify(
navFontsArray
)}');
init();
</script>
</body>
</html>
`;
return pre + html + post;
}

export async function wrapInReveal(reveal, req) {
const pre = `
<!DOCTYPE html>
Expand Down

0 comments on commit 1783713

Please sign in to comment.