mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 09:15:50 +01:00
server-ts: Convert routes/api/fonts
This commit is contained in:
40
src/routes/api/fonts.ts
Normal file
40
src/routes/api/fonts.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Request, Response } from 'express';
|
||||
import optionService = require('../../services/options');
|
||||
|
||||
function getFontCss(req: Request, res: Response) {
|
||||
res.setHeader('Content-Type', 'text/css');
|
||||
|
||||
if (!optionService.getOptionBool('overrideThemeFonts')) {
|
||||
res.send('');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const optionsMap = optionService.getOptionMap();
|
||||
|
||||
const mainFontFamilyOverridden = optionsMap.mainFontFamily !== 'theme';
|
||||
const treeFontFamilyOverridden = optionsMap.treeFontFamily !== 'theme';
|
||||
const detailFontFamilyOverridden = optionsMap.detailFontFamily !== 'theme';
|
||||
const monospaceFontFamilyOverridden = optionsMap.monospaceFontFamily !== 'theme';
|
||||
|
||||
// using body to be more specific than themes' :root
|
||||
let style = 'body {';
|
||||
|
||||
if (mainFontFamilyOverridden) style += `--main-font-family: ${optionsMap.mainFontFamily};`;
|
||||
if (treeFontFamilyOverridden) style += `--tree-font-family: ${optionsMap.treeFontFamily};`;
|
||||
if (detailFontFamilyOverridden) style += `--detail-font-family: ${optionsMap.detailFontFamily};`;
|
||||
if (monospaceFontFamilyOverridden) style += `--monospace-font-family: ${optionsMap.monospaceFontFamily};`;
|
||||
|
||||
style += `--main-font-size: ${optionsMap.mainFontSize}%;`;
|
||||
style += `--tree-font-size: ${optionsMap.treeFontSize}%;`;
|
||||
style += `--detail-font-size: ${optionsMap.detailFontSize}%;`;
|
||||
style += `--monospace-font-size: ${optionsMap.monospaceFontSize}%;`;
|
||||
|
||||
style += '}';
|
||||
|
||||
res.send(style);
|
||||
}
|
||||
|
||||
export = {
|
||||
getFontCss
|
||||
};
|
||||
Reference in New Issue
Block a user