-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Next > Today): Determine which photos to display based on local …
…date
- Loading branch information
Showing
4 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import styled from 'styled-components' | ||
import { get as getGalleries } from '../../src/lib/galleries' | ||
import { get as getAlbums } from '../../src/lib/albums' | ||
import { get as getAlbum } from '../../src/lib/album' | ||
import ThumbImg from '../../src/components/ThumbImg' | ||
|
||
export async function getStaticProps({ params: { gallery } }) { | ||
const { albums } = await getAlbums(gallery) | ||
|
||
// reverse order for albums in ascending order (oldest on top) | ||
const allItems = await [...albums].reverse().reduce(async (previousPromise, album) => { | ||
const prev = await previousPromise | ||
const { album: { items } } = await getAlbum(gallery, album.name) | ||
const itemsMatchDate = items.filter((item) => item?.filename?.substring?.(5, 10) === new Date().toLocaleDateString().substring(5, 10)) | ||
return prev.concat(itemsMatchDate) | ||
}, Promise.resolve([])) | ||
|
||
return { | ||
props: { items: allItems }, | ||
} | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const { galleries } = await getGalleries() | ||
// Define these galleries as allowed, otherwise 404 | ||
const paths = galleries.map((gallery) => ({ params: { gallery } })) | ||
return { | ||
paths, | ||
fallback: false, | ||
} | ||
} | ||
|
||
const Wrapper = styled.ul` | ||
list-style: none; | ||
padding-left: 2px; | ||
` | ||
|
||
function Today({ items }) { | ||
return ( | ||
<Wrapper> | ||
{items.map((item) => ( | ||
<ThumbImg | ||
caption={item.caption} | ||
key={item.filename} | ||
id={`select${item.id}`} | ||
src={item.thumbPath} | ||
/> | ||
))} | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export default Today |
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