From 44cd1d5b4ee6bfbccffbf6c2448b684a7afd31de Mon Sep 17 00:00:00 2001 From: Raphael Kabo Date: Fri, 6 Oct 2023 16:17:03 +0100 Subject: Add config util file --- src/util/config.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/util/config.ts (limited to 'src/util') diff --git a/src/util/config.ts b/src/util/config.ts new file mode 100644 index 0000000..a012398 --- /dev/null +++ b/src/util/config.ts @@ -0,0 +1,17 @@ +import getConfig from "../lib/config.js"; + +const config = getConfig(); + +interface FrontendConfig { + domain: string; + email: string; + siteName: string; + showKofi: boolean; +} + +export const frontendConfig = (): FrontendConfig => ({ + domain: config.general.domain, + email: config.general.email, + siteName: config.general.site_name, + showKofi: config.general.show_kofi, +}); -- cgit v1.2.3 From c64b6febe5298219858bdc7ad27c3dfa1117a4de Mon Sep 17 00:00:00 2001 From: Raphael Kabo Date: Fri, 6 Oct 2023 16:17:14 +0100 Subject: Add util files --- src/util/markdown.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/util/markdown.ts (limited to 'src/util') diff --git a/src/util/markdown.ts b/src/util/markdown.ts new file mode 100644 index 0000000..b1577d9 --- /dev/null +++ b/src/util/markdown.ts @@ -0,0 +1,44 @@ +// Extra marked renderer (used to render plaintext event description for page metadata) +// Adapted from https://dustinpfister.github.io/2017/11/19/nodejs-marked/ + +import { marked } from "marked"; + +// ? to ? helper +function htmlEscapeToText(text: string) { + return text.replace(/\&\#[0-9]*;|&/g, function (escapeCode) { + if (escapeCode.match(/amp/)) { + return "&"; + } + const code = escapeCode.match(/[0-9]+/); + return String.fromCharCode(Number(code)); + }); +} + +export const renderPlain = () => { + var render = new marked.Renderer(); + // render just the text of a link, strong, em + render.link = function (href, title, text) { + return text; + }; + render.strong = function (text) { + return text; + }; + render.em = function (text) { + return text; + }; + // render just the text of a paragraph + render.paragraph = function (text) { + return htmlEscapeToText(text) + "\r\n"; + }; + // render nothing for headings, images, and br + render.heading = function (text, level) { + return ""; + }; + render.image = function (href, title, text) { + return ""; + }; + render.br = function () { + return ""; + }; + return render; +}; -- cgit v1.2.3 From 2996a4d05d0ea2f8446e2a2a0383979ceec748ae Mon Sep 17 00:00:00 2001 From: Raphael Kabo Date: Fri, 6 Oct 2023 16:25:29 +0100 Subject: Run Prettier on all files --- src/util/config.ts | 16 ++++++------- src/util/markdown.ts | 66 ++++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) (limited to 'src/util') diff --git a/src/util/config.ts b/src/util/config.ts index a012398..c65fdb0 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -3,15 +3,15 @@ import getConfig from "../lib/config.js"; const config = getConfig(); interface FrontendConfig { - domain: string; - email: string; - siteName: string; - showKofi: boolean; + domain: string; + email: string; + siteName: string; + showKofi: boolean; } export const frontendConfig = (): FrontendConfig => ({ - domain: config.general.domain, - email: config.general.email, - siteName: config.general.site_name, - showKofi: config.general.show_kofi, + domain: config.general.domain, + email: config.general.email, + siteName: config.general.site_name, + showKofi: config.general.show_kofi, }); diff --git a/src/util/markdown.ts b/src/util/markdown.ts index b1577d9..9f5d384 100644 --- a/src/util/markdown.ts +++ b/src/util/markdown.ts @@ -5,40 +5,40 @@ import { marked } from "marked"; // ? to ? helper function htmlEscapeToText(text: string) { - return text.replace(/\&\#[0-9]*;|&/g, function (escapeCode) { - if (escapeCode.match(/amp/)) { - return "&"; - } - const code = escapeCode.match(/[0-9]+/); - return String.fromCharCode(Number(code)); - }); + return text.replace(/\&\#[0-9]*;|&/g, function (escapeCode) { + if (escapeCode.match(/amp/)) { + return "&"; + } + const code = escapeCode.match(/[0-9]+/); + return String.fromCharCode(Number(code)); + }); } export const renderPlain = () => { - var render = new marked.Renderer(); - // render just the text of a link, strong, em - render.link = function (href, title, text) { - return text; - }; - render.strong = function (text) { - return text; - }; - render.em = function (text) { - return text; - }; - // render just the text of a paragraph - render.paragraph = function (text) { - return htmlEscapeToText(text) + "\r\n"; - }; - // render nothing for headings, images, and br - render.heading = function (text, level) { - return ""; - }; - render.image = function (href, title, text) { - return ""; - }; - render.br = function () { - return ""; - }; - return render; + var render = new marked.Renderer(); + // render just the text of a link, strong, em + render.link = function (href, title, text) { + return text; + }; + render.strong = function (text) { + return text; + }; + render.em = function (text) { + return text; + }; + // render just the text of a paragraph + render.paragraph = function (text) { + return htmlEscapeToText(text) + "\r\n"; + }; + // render nothing for headings, images, and br + render.heading = function (text, level) { + return ""; + }; + render.image = function (href, title, text) { + return ""; + }; + render.br = function () { + return ""; + }; + return render; }; -- cgit v1.2.3