feat: localized time on cards
This commit is contained in:
parent
9a80850230
commit
55e67d1e27
5 changed files with 25 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ description: Welcome to my website! I write about tech, politics, food, and hobb
|
|||
<li>
|
||||
<a href="{{ post.url }}" class="post-card">
|
||||
<h2>{{ post.data.title }}</h2>
|
||||
<time datetime="{{ post.data.createdAt | dateTimeFormat }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||
<time class="localizable-time" datetime="{{ post.data.createdAt | isoDateTime }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if post.data.description %}
|
||||
<p>{{ post.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
@ -54,6 +54,7 @@ description: Welcome to my website! I write about tech, politics, food, and hobb
|
|||
<li>
|
||||
<a href="/recipe/{{ recipe.slug }}/" class="post-card">
|
||||
<h2>{{ recipe.data.newest.data.title }}</h2>
|
||||
<time class="localizable-time" datetime="{{ recipe.data.newest.data.createdAt | isoDateTime }}">{{ recipe.data.newest.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if recipe.data.newest.data.description %}
|
||||
<p>{{ recipe.data.newest.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ permalink: /posts/
|
|||
<li>
|
||||
<a href="{{ post.url }}" class="post-card">
|
||||
<h2>{{ post.data.title }}</h2>
|
||||
<time datetime="{{ post.data.createdAt | dateTimeFormat }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||
<time class="localizable-time" datetime="{{ post.data.createdAt | isoDateTime }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if post.data.description %}
|
||||
<p>{{ post.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ permalink: /recipes/
|
|||
<li>
|
||||
<a href="/recipe/{{ slug }}/" class="post-card">
|
||||
<h2>{{ recipeData.newest.data.title }}</h2>
|
||||
<time class="localizable-time" datetime="{{ recipeData.newest.data.createdAt | isoDateTime }}">{{ recipeData.newest.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if recipeData.newest.data.description %}
|
||||
<p>{{ recipeData.newest.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
3
tags.njk
3
tags.njk
|
|
@ -19,7 +19,7 @@ layout: base.njk
|
|||
<li>
|
||||
<a href="{{ post.url }}" class="post-card">
|
||||
<h2>{{ post.data.title }}</h2>
|
||||
<time datetime="{{ post.date | dateTimeFormat }}">{{ post.date | dateTimeFormat }}</time>
|
||||
<time class="localizable-time" datetime="{{ post.data.createdAt | isoDateTime }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if post.data.description %}
|
||||
<p>{{ post.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
@ -36,6 +36,7 @@ layout: base.njk
|
|||
<li>
|
||||
<a href="/recipe/{{ recipe.data.recipeSlug }}/" class="post-card">
|
||||
<h2>{{ recipe.data.title }}</h2>
|
||||
<time class="localizable-time" datetime="{{ recipe.data.createdAt | isoDateTime }}">{{ recipe.data.createdAt | dateTimeFormat }}</time>
|
||||
{% if recipe.data.description %}
|
||||
<p>{{ recipe.data.description }}</p>
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue