feat: allow to change days before marking an article as outdated

This commit is contained in:
草师傅 2025-08-20 17:36:02 +08:00
parent 65c5fdeae1
commit b3655b99b3
Signed by: gb
GPG key ID: 43330A030E2D6478
2 changed files with 12 additions and 3 deletions

View file

@ -1,14 +1,23 @@
--- ---
import Callout from "./shortcodes/Callout.astro" 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 lastUpdated = new Date(lastUpdatedAt).getTime()
const dateNow = new Date().getTime() const dateNow = new Date().getTime()
const dateDelta = dateNow - lastUpdated const dateDelta = dateNow - lastUpdated
const Day = 1000 * 60 * 60 * 24 const Day = 1000 * 60 * 60 * 24
const daysDelta = Math.round(dateDelta / Day) const daysDelta = Math.round(dateDelta / Day)
--- ---
{ ( lastUpdatedAt && daysDelta >= 30 ) && { ( lastUpdatedAt && daysDelta >= daysBeforeOutdated ) &&
<Callout type="warning" icon="📅"> <Callout type="warning" icon="📅">
This article was updated {daysDelta} days ago. The content may be outdated. This article was updated {daysDelta} days ago. The content may be outdated.
</Callout> </Callout>
}
{ (!lastUpdatedAt && daysDelta >= daysBeforeOutdated) &&
<Callout type="warning" icon="📅">
This article was updated a long time ago. The content may be outdated.
</Callout>
} }

View file

@ -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, // 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 // initialized by the server islands
outdatedCallout: { 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 daysBeforeOutdated: 90, // the number of days before the content is considered outdated, defaults to 90 days
}, },
// encryption // encryption