mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-02 05:02:27 +08:00
refactor(server): split font route in two functions
This commit is contained in:
parent
80af0899b8
commit
8667c0a686
@ -1,5 +1,6 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import optionService from "../../services/options.js";
|
import optionService from "../../services/options.js";
|
||||||
|
import { OptionMap } from '../../services/options_interface.js';
|
||||||
|
|
||||||
function getFontCss(req: Request, res: Response) {
|
function getFontCss(req: Request, res: Response) {
|
||||||
res.setHeader('Content-Type', 'text/css');
|
res.setHeader('Content-Type', 'text/css');
|
||||||
@ -12,29 +13,47 @@ function getFontCss(req: Request, res: Response) {
|
|||||||
|
|
||||||
const optionsMap = optionService.getOptionMap();
|
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
|
// using body to be more specific than themes' :root
|
||||||
let style = 'body {';
|
let style = 'body {';
|
||||||
|
style += getFontFamily(optionsMap);
|
||||||
if (mainFontFamilyOverridden) style += `--main-font-family: ${optionsMap.mainFontFamily};`;
|
style += getFontSize(optionsMap);
|
||||||
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 += '}';
|
style += '}';
|
||||||
|
|
||||||
res.send(style);
|
res.send(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFontFamily(optionsMap: OptionMap) {
|
||||||
|
let style = "";
|
||||||
|
|
||||||
|
if (optionsMap.mainFontFamily !== 'theme') {
|
||||||
|
style += `--main-font-family: ${optionsMap.mainFontFamily};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optionsMap.treeFontFamily !== 'theme') {
|
||||||
|
style += `--tree-font-family: ${optionsMap.treeFontFamily};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optionsMap.detailFontFamily !== 'theme') {
|
||||||
|
style += `--detail-font-family: ${optionsMap.detailFontFamily};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optionsMap.monospaceFontFamily !== 'theme') {
|
||||||
|
style += `--monospace-font-family: ${optionsMap.monospaceFontFamily};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFontSize(optionsMap: OptionMap) {
|
||||||
|
let style = "";
|
||||||
|
style += `--main-font-size: ${optionsMap.mainFontSize}%;`;
|
||||||
|
style += `--tree-font-size: ${optionsMap.treeFontSize}%;`;
|
||||||
|
style += `--detail-font-size: ${optionsMap.detailFontSize}%;`;
|
||||||
|
style += `--monospace-font-size: ${optionsMap.monospaceFontSize}%;`;
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getFontCss
|
getFontCss
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user