deno.land / x / lume@v2.1.4 / core / utils / page_date.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { getGitDate, parseDate } from "./date.ts";
import type { Page, RawData } from "../file.ts";
/** Returns the Date instance of a file */export function getPageDate(page: Page): Date { const data = page.data as RawData; const { date } = data;
if (date instanceof Date) { return date; }
if (typeof date === "number") { return new Date(date); }
const { entry } = page.src; const info = entry?.getInfo();
if (typeof date === "string") { if (entry && info) { switch (date.toLowerCase()) { case "git last modified": return getGitDate("modified", entry.src) || info.mtime || new Date(); case "git created": return getGitDate("created", entry.src) || info.birthtime || new Date(); } }
try { return parseDate(date); } catch { throw new Error(`Invalid date: ${date} (${entry?.src})`); } }
return info?.birthtime || info?.mtime || new Date();}
lume

Version Info

Tagged at
7 months ago