Created
May 9, 2020 18:23
-
-
Save kmelve/c3a1d42ee210649aefac3e5e7e4716e0 to your computer and use it in GitHub Desktop.
Structure definition for listing entries by date of the current year for Sanity Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import S from '@sanity/desk-tool/structure-builder' | |
import eachDayOfInterval from 'date-fns/eachDayOfInterval' | |
import startOfYear from 'date-fns/startOfYear' | |
import startOfDay from 'date-fns/startOfDay' | |
import endOfDay from 'date-fns/endOfDay' | |
let now = new Date() | |
export default () => S.listItem() | |
.title('Entries by day this year') | |
.child( | |
S.list() | |
.title('Entries by day this year') | |
.items( | |
eachDayOfInterval({ | |
start: startOfYear(now), | |
end: now | |
}).map(date => { | |
let currentDate = new Date(date) | |
return S.listItem() | |
.title(currentDate.toLocaleDateString()) | |
.child( | |
S.documentList() | |
.title( | |
`Entries for ${currentDate.toLocaleDateString()}` | |
) | |
.filter( | |
'_type == $type && publishedAt >= $startOfDay && publishedAt <= $endOfDay' | |
) | |
.params({ | |
startOfDay: startOfDay(currentDate), | |
endOfDay: endOfDay(currentDate), | |
type: 'yourDocumentType' | |
}) | |
) | |
}) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment