Create custom filters file

This commit is contained in:
TheThomaas 2023-11-13 21:33:39 +01:00
parent 907b756c39
commit 6814cdca3d

49
config/filters/index.js Normal file
View file

@ -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,
}