Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
Philippe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Philippe
Commits
598bb886
Commit
598bb886
authored
Jun 14, 2021
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Details
parent
c28f43d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
24 deletions
+46
-24
utils.js
lib/utils.js
+22
-8
index.js
pages/index.js
+24
-16
No files found.
lib/utils.js
View file @
598bb886
...
@@ -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
};
pages/index.js
View file @
598bb886
...
@@ -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
((
p
ath
)
=>
(
{
photos
.
map
((
p
hoto
)
=>
(
<
WrapItem
<
WrapItem
key
=
{
"wrap-"
+
p
ath
}
key
=
{
"wrap-"
+
p
hoto
.
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
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment