diff --git a/config/filters/index.js b/config/filters/index.js new file mode 100644 index 0000000..152a36a --- /dev/null +++ b/config/filters/index.js @@ -0,0 +1,49 @@ +const siteData = require("../../src/_data/meta.js") +const sass = require('sass') + +function toFullDate(value) { + const dateObject = new Date(value) + + const dateParts = new Intl.DateTimeFormat(siteData.lang, { + year: "numeric", + day: "numeric", + month: "long", + }).formatToParts(dateObject) + + const dayPart = dateParts.find((part) => part.type === "day").value + const monthPart = dateParts.find((part) => part.type === "month").value + const yearPart = dateParts.find((part) => part.type === "year").value + + return `${monthPart} ${dayPart}, ${yearPart}` +} + +function getMonthDay(value) { + const dateObject = new Date(value) + + const month = new Intl.DateTimeFormat(siteData.lang, { + month: "long", + }).format(dateObject) + + return `${dateObject.getDate()} ${month}` +} + +function getYear(value) { + const dateObject = new Date(value) + return dateObject.getFullYear() +} + +function getDatetime(value) { + return new Date(value).toISOString().split("T")[0] +} + +function renderSass(file) { + return sass.renderSync({ file }).css.toString() +} + +module.exports = { + getDatetime, + getMonthDay, + getYear, + toFullDate, + renderSass, +}