Skip to content

Commit e1e3db1

Browse files
NeverBehaveclaude
andcommitted
Add stale post warning for articles older than 180 days
Shows a yellow warning banner on posts not updated in 180+ days, with client-side day count based on browser date. Fully client-side threshold check so no rebuild needed when posts cross the threshold. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a942c4d commit e1e3db1

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/_includes/layouts/post.njk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ layout: layouts/base.njk
2828
{% endif %}
2929
</header>
3030

31+
{% set latestDate = updated if updated else date %}
32+
<div id="stale-warning" class="my-6 p-4 border-l-4 border-yellow-400 bg-yellow-50 text-yellow-900 text-sm hidden">
33+
<strong>注意:</strong> 这篇文章已经有相当一段时间没有更新了(已过去 <span id="stale-days"></span> 天)。<br>文章中任何有时效性的信息应当在仔细审阅后再使用。如果有任何更新建议,请留言。
34+
</div>
35+
<script>!function(){var d=Math.floor((Date.now()-new Date("{{ latestDate | isoDate }}"))/(864e5));if(d>180){document.getElementById("stale-days").textContent=d;document.getElementById("stale-warning").classList.remove("hidden")}}();</script>
36+
3137
<div class="prose prose-lg max-w-none">
3238
{{ content | safe }}
3339
</div>

0 commit comments

Comments
 (0)