summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-27 11:43:33 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-27 11:43:33 +0100
commite9c68e4b3ddcfe638bc611f421d55f372e0100e9 (patch)
treeadd5778b0eea6879cb49bbd4bbf9164479ece8e8
parent44a72320927ee3752ae600829c0c618b68e0f19d (diff)
fix(project): make sure the project cover is displayed
Next.js does not support the dynamic import of images. Sometimes the images was displayed and other times the loading did not finish. So even if I would like to keep the content in a same place, I choose to put the projects covers inside the public directory. Then I use a hasCover boolean to determine if the project cover need to be printed.
-rw-r--r--public/projects/coldark.jpgbin0 -> 26968 bytes
-rw-r--r--public/projects/dotig.jpgbin0 -> 28730 bytes
-rw-r--r--public/projects/new-vhost.jpgbin0 -> 11263 bytes
-rw-r--r--src/components/ProjectSummary/ProjectSummary.tsx10
m---------src/content0
-rw-r--r--src/pages/projet/[slug].tsx8
-rw-r--r--src/ts/types/app.ts21
7 files changed, 20 insertions, 19 deletions
diff --git a/public/projects/coldark.jpg b/public/projects/coldark.jpg
new file mode 100644
index 0000000..f5a7254
--- /dev/null
+++ b/public/projects/coldark.jpg
Binary files differ
diff --git a/public/projects/dotig.jpg b/public/projects/dotig.jpg
new file mode 100644
index 0000000..4ddbaca
--- /dev/null
+++ b/public/projects/dotig.jpg
Binary files differ
diff --git a/public/projects/new-vhost.jpg b/public/projects/new-vhost.jpg
new file mode 100644
index 0000000..7bf5d7b
--- /dev/null
+++ b/public/projects/new-vhost.jpg
Binary files differ
diff --git a/src/components/ProjectSummary/ProjectSummary.tsx b/src/components/ProjectSummary/ProjectSummary.tsx
index 1b07eb1..b32c11f 100644
--- a/src/components/ProjectSummary/ProjectSummary.tsx
+++ b/src/components/ProjectSummary/ProjectSummary.tsx
@@ -11,25 +11,25 @@ import { useRouter } from 'next/router';
import styles from './ProjectSummary.module.scss';
const ProjectSummary = ({
+ id,
title,
- cover,
meta,
}: {
+ id: string;
title: string;
- cover: string;
meta: ProjectMeta;
}) => {
- const { license, repos, technologies } = meta;
+ const { hasCover, license, repos, technologies } = meta;
const router = useRouter();
const locale = router.locale ? router.locale : config.locales.defaultLocale;
const { data } = useGithubApi(repos?.github ? repos.github : '');
return (
<div className={styles.wrapper}>
- {cover && (
+ {hasCover && (
<div className={styles.cover}>
<Image
- src={cover}
+ src={`/projects/${id}.jpg`}
alt={t`${title} preview`}
layout="fill"
objectFit="contain"
diff --git a/src/content b/src/content
-Subproject 1dc7705299e9e4a05ecddd35dd1357d6426efe0
+Subproject c85ab7210b3fc984bc06e2d672839cedc37344e
diff --git a/src/pages/projet/[slug].tsx b/src/pages/projet/[slug].tsx
index 7ae50d6..b6a9cf2 100644
--- a/src/pages/projet/[slug].tsx
+++ b/src/pages/projet/[slug].tsx
@@ -31,7 +31,7 @@ const Project: NextPageWithLayout<ProjectProps> = ({
}) => {
const router = useRouter();
const projectUrl = `${config.url}${router.asPath}`;
- const { cover, id, intro, meta, title, seo } = project;
+ const { id, intro, meta, title, seo } = project;
const dates = {
publication: meta.publishedOn,
update: meta.updatedOn,
@@ -76,8 +76,8 @@ const Project: NextPageWithLayout<ProjectProps> = ({
dateModified: updateDate.toISOString(),
datePublished: publicationDate.toISOString(),
editor: { '@id': `${config.url}/#branding` },
- thumbnailUrl: cover,
- image: cover,
+ thumbnailUrl: meta.hasCover ? `/projects/${id}.jpg` : '',
+ image: meta.hasCover ? `/projects/${id}.jpg` : '',
inLanguage: config.locales.defaultLocale,
license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr',
mainEntityOfPage: { '@id': `${projectUrl}` },
@@ -111,7 +111,7 @@ const Project: NextPageWithLayout<ProjectProps> = ({
<ToC />
</Sidebar>
<div className={styles.body}>
- <ProjectSummary title={title} cover={cover} meta={meta} />
+ <ProjectSummary id={id} title={title} meta={meta} />
<ProjectContent components={components} />
</div>
<Sidebar position="right">
diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts
index ddd64d1..636aeed 100644
--- a/src/ts/types/app.ts
+++ b/src/ts/types/app.ts
@@ -94,15 +94,6 @@ export type Meta = {
updatedOn: string;
};
-export type ProjectMeta = Omit<Meta, 'title'> & {
- license: string;
- repos?: {
- github?: string;
- gitlab?: string;
- };
- technologies?: string[];
-};
-
export type PageInfo = {
endCursor: string;
hasNextPage: boolean;
@@ -110,7 +101,7 @@ export type PageInfo = {
};
export type Project = {
- cover: string;
+ cover?: string;
id: string;
intro: string;
meta: ProjectMeta;
@@ -123,6 +114,16 @@ export type Project = {
};
};
+export type ProjectMeta = Omit<Meta, 'title'> & {
+ hasCover: boolean;
+ license: string;
+ repos?: {
+ github?: string;
+ gitlab?: string;
+ };
+ technologies?: string[];
+};
+
export type ProjectProps = {
project: Project;
};