11ty-light-blog/config/filters/index.js
2023-11-25 13:16:04 +01:00

55 lines
1.2 KiB
JavaScript

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.compile(file).css.toString();
}
function renderSassString(string) {
return sass.compileString(string).css.toString();
}
module.exports = {
getDatetime,
getMonthDay,
getYear,
toFullDate,
renderSass,
renderSassString,
}