11ty-light-blog/config/filters/index.js

50 lines
1.1 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.renderSync({ file }).css.toString()
}
module.exports = {
getDatetime,
getMonthDay,
getYear,
toFullDate,
renderSass,
}