Skip to content

Commit

Permalink
Add & use 30-day scope on snippet for update logs
Browse files Browse the repository at this point in the history
This ensures that update logs are pinned as announcements for 30 days at most.
  • Loading branch information
Chalarangelo committed Dec 11, 2024
1 parent a105f4b commit 21ca26f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ svg
nowrap
codepen
inputmode
updatelog
8 changes: 6 additions & 2 deletions src/adapters/page/homePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ export default class HomePage extends Page {
const latestUpdateLog = Snippet.scope(
'updateLogs',
'published',
'byNew'
).first;
'byNew',
'last30Days'
)?.first;

if (!latestUpdateLog) return null;

return {
text: 'Read the latest update log:',
linkText: latestUpdateLog.previewTitle,
Expand Down
6 changes: 6 additions & 0 deletions src/models/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default class Snippet extends ContentModel {
return records.order((a, b) => b.dateModified - a.dateModified);
}

static last30Days(records) {
let date = new Date();
date.setDate(date.getDate() - 30);
return records.where({ dateModified: d => d > date });
}

static published(records) {
const now = new Date();
return records.where({ dateModified: d => d < now });
Expand Down

0 comments on commit 21ca26f

Please sign in to comment.