From 55e67d1e279a70570d292e697902f41682b2925f Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Thu, 19 Feb 2026 17:35:13 -0600 Subject: [PATCH] feat: localized time on cards --- index.njk | 3 ++- posts-index.njk | 2 +- recipes-index.njk | 1 + recipes/recipes.11tydata.js | 19 +++++++++++++++++++ tags.njk | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/index.njk b/index.njk index b766d44..a5a4eac 100644 --- a/index.njk +++ b/index.njk @@ -22,7 +22,7 @@ description: Welcome to my website! I write about tech, politics, food, and hobb
  • {{ post.data.title }}

    - + {% if post.data.description %}

    {{ post.data.description }}

    {% endif %} @@ -54,6 +54,7 @@ description: Welcome to my website! I write about tech, politics, food, and hobb
  • {{ recipe.data.newest.data.title }}

    + {% if recipe.data.newest.data.description %}

    {{ recipe.data.newest.data.description }}

    {% endif %} diff --git a/posts-index.njk b/posts-index.njk index abb3d19..e64084e 100644 --- a/posts-index.njk +++ b/posts-index.njk @@ -13,7 +13,7 @@ permalink: /posts/
  • {{ post.data.title }}

    - + {% if post.data.description %}

    {{ post.data.description }}

    {% endif %} diff --git a/recipes-index.njk b/recipes-index.njk index cea2fc4..00d3291 100644 --- a/recipes-index.njk +++ b/recipes-index.njk @@ -21,6 +21,7 @@ permalink: /recipes/
  • {{ recipeData.newest.data.title }}

    + {% if recipeData.newest.data.description %}

    {{ recipeData.newest.data.description }}

    {% endif %} diff --git a/recipes/recipes.11tydata.js b/recipes/recipes.11tydata.js index 9c6a9d2..d9a6e3a 100644 --- a/recipes/recipes.11tydata.js +++ b/recipes/recipes.11tydata.js @@ -1,6 +1,7 @@ const fs = require('fs') const path = require("path"); const { execSync } = require("child_process"); +const { DateTime } = require("luxon"); const getSlugFromPath = (filePath) => { // Normalize the path - remove leading ./ if present @@ -62,6 +63,21 @@ const getFileCreatedTime = (filePath) => { } } +const getFileCreatedDateTime = (filePath) => { + const gitTime = getGitCreatedTime(filePath); + if (gitTime) { + return DateTime.fromMillis(gitTime, { zone: 'utc' }); + } + + try { + const stats = fs.statSync(filePath); + const time = stats.birthtime ?? stats.mtime; + return DateTime.fromJSDate(time, { zone: 'utc' }); + } catch (e) { + return DateTime.utc(); + } +} + const getVersion = (filePath) => { const dirName = path.dirname(filePath) @@ -145,6 +161,9 @@ module.exports = { isDraft: (data) => { return data.draft === true; }, + createdAt: (data) => { + return getFileCreatedDateTime(data.page.inputPath); + }, permalink: (data) => { const slug = getSlugFromPath(data.page.inputPath); const version = getVersion(data.page.inputPath); diff --git a/tags.njk b/tags.njk index fad82f2..803627f 100644 --- a/tags.njk +++ b/tags.njk @@ -19,7 +19,7 @@ layout: base.njk
  • {{ post.data.title }}

    - + {% if post.data.description %}

    {{ post.data.description }}

    {% endif %} @@ -36,6 +36,7 @@ layout: base.njk
  • {{ recipe.data.title }}

    + {% if recipe.data.description %}

    {{ recipe.data.description }}

    {% endif %}