UNPKG

@quasibit/eleventy-plugin-sitemap

Version:
25 lines (19 loc) 512 B
"use strict"; const isValidDate = require("./isValidDate"); /** * Formats a date for use in the sitemap. * * @param {Date|string} date Date object or date string (to be passed to Date * constructor). * @returns {string|undefined} Formatted date for sitemap. */ module.exports = function sitemapDateTime(date) { if (!date) { return; } const dateObject = typeof date === "string" ? new Date(date) : date; if (!isValidDate(dateObject)) { return; } return dateObject.toISOString(); };