From b3655b99b328df29002ff26f645c9515533c0061 Mon Sep 17 00:00:00 2001 From: grassblock Date: Wed, 20 Aug 2025 17:36:02 +0800 Subject: [PATCH] feat: allow to change days before marking an article as outdated --- src/components/OutDatedCallOut.astro | 13 +++++++++++-- src/config.ts | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/OutDatedCallOut.astro b/src/components/OutDatedCallOut.astro index 833525d..6fff5aa 100644 --- a/src/components/OutDatedCallOut.astro +++ b/src/components/OutDatedCallOut.astro @@ -1,14 +1,23 @@ --- import Callout from "./shortcodes/Callout.astro" -const { lastUpdatedAt } = Astro.props + +import { siteConfig} from "../config"; +const daysBeforeOutdated = siteConfig.outdatedCallout.daysBeforeOutdated || 90; + +const { lastUpdatedAt = '' } = Astro.props const lastUpdated = new Date(lastUpdatedAt).getTime() const dateNow = new Date().getTime() const dateDelta = dateNow - lastUpdated const Day = 1000 * 60 * 60 * 24 const daysDelta = Math.round(dateDelta / Day) --- -{ ( lastUpdatedAt && daysDelta >= 30 ) && +{ ( lastUpdatedAt && daysDelta >= daysBeforeOutdated ) && This article was updated {daysDelta} days ago. The content may be outdated. +} +{ (!lastUpdatedAt && daysDelta >= daysBeforeOutdated) && + + This article was updated a long time ago. The content may be outdated. + } \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index d0fb3de..d419c72 100644 --- a/src/config.ts +++ b/src/config.ts @@ -41,7 +41,7 @@ export const siteConfig = { // enable the callout to notify users that the content maybe outdated, this will add a callout to the top of the article page, // initialized by the server islands outdatedCallout: { - enabled: true, + enabled: true, // enable the outdated callout daysBeforeOutdated: 90, // the number of days before the content is considered outdated, defaults to 90 days }, // encryption