diff options
author | Raphael <mail@raphaelkabo.com> | 2023-10-09 11:10:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-09 11:10:51 +0100 |
commit | cc6fcb4c405d8cffacbf9b1082abf61e918482fa (patch) | |
tree | 693f324550dccedd50b6313165b88281a8ebcac8 /src/util | |
parent | 25fcdd1023550631f5fec6f750829fe09a311d66 (diff) | |
parent | 31022a7d323a351041b7b8508fb56c14fd699580 (diff) |
Merge pull request #114 from lowercasename/rk/static-pages
Static pages
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/config.ts | 19 | ||||
-rw-r--r-- | src/util/markdown.ts | 16 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/util/config.ts b/src/util/config.ts deleted file mode 100644 index d1fd05b..0000000 --- a/src/util/config.ts +++ /dev/null @@ -1,19 +0,0 @@ -import getConfig from "../lib/config.js"; - -const config = getConfig(); - -interface FrontendConfig { - domain: string; - email: string; - siteName: string; - showKofi: boolean; - isFederated: boolean; -} - -export const frontendConfig = (): FrontendConfig => ({ - domain: config.general.domain, - email: config.general.email, - siteName: config.general.site_name, - showKofi: config.general.show_kofi, - isFederated: config.general.is_federated, -}); diff --git a/src/util/markdown.ts b/src/util/markdown.ts index 9f5d384..bab50bd 100644 --- a/src/util/markdown.ts +++ b/src/util/markdown.ts @@ -1,7 +1,6 @@ -// 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"; +import { JSDOM } from "jsdom"; +import DOMPurify from "dompurify"; // ? to ? helper function htmlEscapeToText(text: string) { @@ -14,6 +13,9 @@ function htmlEscapeToText(text: string) { }); } +// Extra marked renderer (used to render plaintext event description for page metadata) +// Adapted from https://dustinpfister.github.io/2017/11/19/nodejs-marked/ + export const renderPlain = () => { var render = new marked.Renderer(); // render just the text of a link, strong, em @@ -42,3 +44,11 @@ export const renderPlain = () => { }; return render; }; + +export const markdownToSanitizedHTML = (markdown: string) => { + const html = marked.parse(markdown); + const window = new JSDOM("").window; + const purify = DOMPurify(window); + const clean = purify.sanitize(html); + return clean; +}; |