This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/workers/dynamic-pages/utils/formatters.js

26 lines
652 B
JavaScript

import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItFootnote from "markdown-it-footnote";
export const formatDate = (date) =>
new Date(date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
export const md = markdownIt({ html: true, linkify: true });
md.use(markdownItAnchor, {
level: [1, 2],
permalink: markdownItAnchor.permalink.headerLink({
safariReaderFix: true,
}),
});
md.use(markdownItFootnote);
export const minifyHTML = (html) =>
html
.replace(/\n\s+/g, "")
.replace(/>\s+</g, "><")
.replace(/<!--.*?-->/g, "");