Skip to content

Commit

Permalink
feat(#16): configurable page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Oct 26, 2023
1 parent a6131b5 commit b428226
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/routes/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Request, Response, Router } from 'express';

import { messageClientsAt } from '../app';
import parse, { pathHeading } from '../parser/parser';
import config from '../parser/config';

export const router = Router();

Expand All @@ -14,6 +15,11 @@ const liveContent = new Map<string, string>();
const getMimeFromPath = (path: string) =>
execSync(`file --mime-type -b '${path}'`).toString().trim();

const pageTitle = (path: string) => {
if (config.pageTitle) return eval(`const path = "${path}"; ${config.pageTitle}`);
else return join(basename(dirname(path)), basename(path));
};

router.get(/.*/, async (req: Request, res: Response) => {
const path = res.locals.filepath;

Expand Down Expand Up @@ -46,7 +52,7 @@ router.get(/.*/, async (req: Request, res: Response) => {
<!DOCTYPE html>
<html>
<head>
<title>${join(basename(dirname(path)), basename(path))}</title>
<title>${pageTitle(path)}</title>
<link rel="stylesheet" type="text/css" href="/static/style.css"/>
<link rel="stylesheet" type="text/css" href="/static/highlight.css">
<link rel="stylesheet" type="text/css" href="/static/katex/katex.css">
Expand Down

0 comments on commit b428226

Please sign in to comment.