Skip to content

Commit

Permalink
use file system stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixel998 committed Feb 19, 2025
1 parent 13596ba commit 979ef4f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
15 changes: 3 additions & 12 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const path = require("node:path");
const fs = require("node:fs");
const yaml = require("js-yaml");
const { DateTime } = require("luxon");
const { execSync } = require("node:child_process");

//-----------------------------------------------------------------------------
// Eleventy Config
Expand Down Expand Up @@ -160,19 +159,11 @@ module.exports = eleventyConfig => {
value1.concat(value2),
);

eleventyConfig.addFilter("gitLastUpdated", filepath => {
// Only check git history in production
eleventyConfig.addFilter("fileLastUpdated", filepath => {
if (CONTEXT) {
try {
const date = execSync(`git log -1 --format=%cD ${filepath}`, {
encoding: "utf-8",
}).trim();

if (!date) {
return null;
}

return new Date(date);
const stats = fs.statSync(filepath);
return stats.mtime;
} catch {
return null;
}
Expand Down
10 changes: 7 additions & 3 deletions src/_includes/partials/post-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ <h2 class="post__sidebar-module__title">Contributors</h2>
{% endfor %}
</div>

{% set git_last_updated = page.inputPath | gitLastUpdated %}
{% set last_updated = page.date if git_last_updated and git_last_updated < page.date else git_last_updated %}
{% set file_last_updated = page.inputPath | fileLastUpdated %}
{% set last_updated = page.date if file_last_updated and file_last_updated < page.date else file_last_updated %}
{% if last_updated %}
<div class="post__sidebar-module">
<h2 class="post__sidebar-module__title">Last updated <time datetime="{{ last_updated | readableDate }}">{{ last_updated | readableDate }}</time></h2>
<h2 class="post__sidebar-module__title">Last Updated On</h2>
<div class="post-last-updated">
<svg focusable="false" width="20" height="20" viewBox="0 0 610.398 610.398" aria-hidden="true" fill="currentColor"><path d="M159.567 0h-15.329c-1.956 0-3.811.411-5.608.995-8.979 2.912-15.616 12.498-15.616 23.997v51.613c0 2.611.435 5.078 1.066 7.44 2.702 10.146 10.653 17.552 20.158 17.552h15.329c11.724 0 21.224-11.188 21.224-24.992V24.992c0-13.804-9.5-24.992-21.224-24.992zM461.288 0h-15.329c-11.724 0-21.224 11.188-21.224 24.992v51.613c0 13.804 9.5 24.992 21.224 24.992h15.329c11.724 0 21.224-11.188 21.224-24.992V24.992C482.507 11.188 473.007 0 461.288 0z"/><path d="M539.586 62.553h-37.954v14.052c0 24.327-18.102 44.117-40.349 44.117h-15.329c-22.247 0-40.349-19.79-40.349-44.117V62.553H199.916v14.052c0 24.327-18.102 44.117-40.349 44.117h-15.329c-22.248 0-40.349-19.79-40.349-44.117V62.553H70.818c-21.066 0-38.15 16.017-38.15 35.764v476.318c0 19.784 17.083 35.764 38.15 35.764h468.763c21.085 0 38.149-15.984 38.149-35.764V98.322c.005-19.747-17.059-35.769-38.144-35.769zM527.757 557.9l-446.502-.172V173.717h446.502V557.9z"/><path d="M353.017 266.258h117.428c10.193 0 18.437-10.179 18.437-22.759s-8.248-22.759-18.437-22.759H353.017c-10.193 0-18.437 10.179-18.437 22.759 0 12.575 8.243 22.759 18.437 22.759zM353.017 348.467h117.428c10.193 0 18.437-10.179 18.437-22.759 0-12.579-8.248-22.758-18.437-22.758H353.017c-10.193 0-18.437 10.179-18.437 22.758 0 12.58 8.243 22.759 18.437 22.759zM353.017 430.676h117.428c10.193 0 18.437-10.18 18.437-22.759s-8.248-22.759-18.437-22.759H353.017c-10.193 0-18.437 10.18-18.437 22.759s8.243 22.759 18.437 22.759zM353.017 512.89h117.428c10.193 0 18.437-10.18 18.437-22.759 0-12.58-8.248-22.759-18.437-22.759H353.017c-10.193 0-18.437 10.179-18.437 22.759 0 12.579 8.243 22.759 18.437 22.759zM145.032 266.258H262.46c10.193 0 18.436-10.179 18.436-22.759s-8.248-22.759-18.436-22.759H145.032c-10.194 0-18.437 10.179-18.437 22.759.001 12.575 8.243 22.759 18.437 22.759zM145.032 348.467H262.46c10.193 0 18.436-10.179 18.436-22.759 0-12.579-8.248-22.758-18.436-22.758H145.032c-10.194 0-18.437 10.179-18.437 22.758.001 12.58 8.243 22.759 18.437 22.759zM145.032 430.676H262.46c10.193 0 18.436-10.18 18.436-22.759s-8.248-22.759-18.436-22.759H145.032c-10.194 0-18.437 10.18-18.437 22.759s8.243 22.759 18.437 22.759zM145.032 512.89H262.46c10.193 0 18.436-10.18 18.436-22.759 0-12.58-8.248-22.759-18.436-22.759H145.032c-10.194 0-18.437 10.179-18.437 22.759.001 12.579 8.243 22.759 18.437 22.759z"/></svg>
<time datetime="{{ last_updated | readableDate }}">{{ last_updated | readableDate }}</time>
</div>
</div>
{% endif %}

Expand Down
5 changes: 5 additions & 0 deletions src/assets/scss/blog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ ul.tag-list {
font-size: var(--step-0);
}

.post-last-updated {
display: flex;
gap: 0.5rem;
}

// author bios
.post__author-bios {
padding-top: var(--space-m);
Expand Down

0 comments on commit 979ef4f

Please sign in to comment.