Commit 598bb886 by PLN (Algolia)

feat: Details

parent c28f43d3
...@@ -2,18 +2,32 @@ import path from "path"; ...@@ -2,18 +2,32 @@ import path from "path";
import fs from "fs"; import fs from "fs";
function getContentDirectory(name) { function getContentDirectory(name) {
return path.join(process.cwd(), "public", name) return path.join(process.cwd(), "public", name);
} }
function getAllPhotos() { const photoDir = "img/Diaporama";
const path = "img/Diaporama"
const contentDirectory = getContentDirectory(path); function photoPath(fileName) {
return "/" + photoDir + "/" + fileName;
}
function getAllPhotos() {
const contentDirectory = getContentDirectory(photoDir);
const fileNames = fs.readdirSync(contentDirectory); const fileNames = fs.readdirSync(contentDirectory);
console.log(`gACD: total pictures: ${fileNames.length}`); console.log(`gACD: total pictures: ${fileNames.length}`);
return fileNames.map(f => path + "/" + f); return fileNames.map((f, i) => {
return {
id: i + 1, // Photos are 1-indexed
path: photoPath(f),
};
});
}
function getPhotoById(id) {
const contentDirectory = getContentDirectory(photoDir);
const fileNames = fs.readdirSync(contentDirectory);
return { id: id, path: photoPath(fileNames[id - 1]) }; // Photos are 1-indexed
} }
export { export { getAllPhotos, getPhotoById };
getAllPhotos
};
...@@ -5,10 +5,10 @@ import { Box, Container, Text, Wrap, WrapItem } from "@chakra-ui/react"; ...@@ -5,10 +5,10 @@ import { Box, Container, Text, Wrap, WrapItem } from "@chakra-ui/react";
import Image from "next/image"; import Image from "next/image";
import { getAllPhotos } from "../lib/utils"; import { getAllPhotos } from "../lib/utils";
import { Img } from "@chakra-ui/react"; import { Img } from "@chakra-ui/react";
import Link from "next/link";
export async function getServerSideProps() { export async function getStaticProps() {
const data = await getAllPhotos(); let data = await getAllPhotos();
console.log(data);
return { return {
props: { props: {
data, data,
...@@ -17,7 +17,6 @@ export async function getServerSideProps() { ...@@ -17,7 +17,6 @@ export async function getServerSideProps() {
} }
export default function Home({ data }) { export default function Home({ data }) {
console.log(data);
const [photos, setPhotos] = useState(data); const [photos, setPhotos] = useState(data);
// TODO: Fallback with random flowers? fallbackSrc // TODO: Fallback with random flowers? fallbackSrc
return ( return (
...@@ -27,7 +26,12 @@ export default function Home({ data }) { ...@@ -27,7 +26,12 @@ export default function Home({ data }) {
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<Box overflow="hidden" bg="gray.100" minH="100vh"> <Box overflow="hidden" bg="gray.100" minH="100vh">
<Container> <Container>
<Image src="/img/signal-2021-06-09-200337_001.jpeg" alt="me" width="64" height="64" /> <Image
src="/img/signal-2021-06-09-200337_001.jpeg"
alt="me"
width="32"
height="32"
/>
<Text <Text
color="gray.700" color="gray.700"
fontWeight="semibold" fontWeight="semibold"
...@@ -40,9 +44,9 @@ export default function Home({ data }) { ...@@ -40,9 +44,9 @@ export default function Home({ data }) {
</Text> </Text>
</Container> </Container>
<Wrap px="2rem" spacing={"10px"} justify="center"> <Wrap px="2rem" spacing={"10px"} justify="center">
{photos.map((path) => ( {photos.map((photo) => (
<WrapItem <WrapItem
key={"wrap-" + path} key={"wrap-" + photo.id}
boxShadow="base" boxShadow="base"
rounded="10px" rounded="10px"
overflow="hidden" overflow="hidden"
...@@ -51,21 +55,25 @@ export default function Home({ data }) { ...@@ -51,21 +55,25 @@ export default function Home({ data }) {
lineHeight="0" lineHeight="0"
_hover={{ boxShadow: "dark-lg" }} _hover={{ boxShadow: "dark-lg" }}
> >
{/*<img <Link href={`/photos/${photo.id}`}>
{/*<img
key={"img-" + path} key={"img-" + path}
src={path} src={path}
height="200px" height="200px"
width="80px" width="80px"
color="gray.700" color="gray.700"
/>*/} />*/}
<Img <Img
key={"img-" + path} key={"img-" + photo.path}
src={path} src={photo.path}
height="180px" height="240px"
width="120px" width="240px"
objectFit="cover" objectFit="cover"
color="gray.700" placeholder="img/Diaporama/f5b1d804-3860-4073-b280-69e54985c66f.jpg"
/> color="gray.700"
quality={100}
/>
</Link>
</WrapItem> </WrapItem>
))} ))}
</Wrap> </Wrap>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment