Skip to content

Commit

Permalink
feat: add 404 and 5xx error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuireu committed Aug 20, 2024
1 parent 4a1666c commit 90a14c5
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 174 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/cloudflare": "^11.0.4",
"@astrojs/mdx": "^3.1.3",
"@astrojs/mdx": "^3.1.4",
"@astrojs/partytown": "^2.1.1",
"@astrojs/react": "^3.6.2",
"@astrojs/rss": "^4.0.7",
Expand All @@ -52,21 +52,21 @@
"@fontsource/baskervville": "^5.0.21",
"@hookform/resolvers": "^3.9.0",
"@million/lint": "1.0.0-rc.82-beta.50",
"algoliasearch": "^5.0.0",
"algoliasearch": "^5.1.0",
"astro": "^4.13.4",
"clsx": "^2.1.1",
"contentful": "^10.14.1",
"firebase": "^10.13.0",
"firebase-admin": "^12.3.1",
"gsap": "^3.12.5",
"instantsearch.css": "^8.4.0",
"instantsearch.css": "^8.5.0",
"markdown-it": "^14.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-globe.gl": "^2.27.2",
"react-google-recaptcha-v3": "^1.10.1",
"react-hook-form": "^7.52.2",
"react-instantsearch": "^7.12.4",
"react-instantsearch": "^7.13.0",
"react-router-dom": "^6.26.1",
"resend": "^4.0.0",
"swiper": "^11.1.9",
Expand All @@ -87,7 +87,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/three": "^0.167.1",
"husky": "^9.1.4",
"husky": "^9.1.5",
"lint-staged": "^15.2.9",
"stylelint": "^16.8.2",
"stylelint-config-recommended": "^14.0.1",
Expand Down
4 changes: 4 additions & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="../.astro/env.d.ts" />
/// <reference path="../.astro/actions.d.ts" />
/// <reference path="../.astro/types.d.ts" />
interface ImportMetaEnv {
readonly PUBLIC_SITE_URL: string;
Expand Down
23 changes: 23 additions & 0 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
import type { SeoMetadata } from "@const/types";
import BaseLayout from "@modules/core/components/baseLayout/BaseLayout.astro";
import ErrorLayer from "@modules/core/components/errorLayer/ErrorLayer.astro";
const title = "404: Not Found";
const description = "It seems you've stumbled upon a page that doesn't exist.";
const metadata: Partial<SeoMetadata> = {
title,
description,
robots: {
index: false,
follow: false,
},
};
---
<BaseLayout {...metadata}>
<ErrorLayer>
<h1>{title}</h1>
<p>{description}</p>
</ErrorLayer>
</BaseLayout>
28 changes: 28 additions & 0 deletions src/pages/500.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
import type { SeoMetadata } from "@const/types";
import BaseLayout from "@modules/core/components/baseLayout/BaseLayout.astro";
import ErrorLayer from "@modules/core/components/errorLayer/ErrorLayer.astro";
interface FiveHundredProps {
error: unknown;
}
const { error } = Astro.props as FiveHundredProps;
const title = "500: Whoops!";
const description = `For full transparency this is the error: ${error instanceof Error ? error.message : "Unknown error"}`;
const metadata: Partial<SeoMetadata> = {
title,
description,
robots: {
index: false,
follow: false,
},
};
---
<BaseLayout {...metadata}>
<ErrorLayer>
<h1>{title}</h1>
<p>Clearly something went wrong... Oh gosh this is embarrassing...</p>
<p>{description}</p>
</ErrorLayer>
</BaseLayout>
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MyWork from "@modules/home/components/myWork/MyWork.astro";
import Testimonials from "@modules/home/components/testimonials/Testimonials.astro";
import Welcome from "@modules/home/components/welcome/Welcome.astro";
// todo: favicon
// todo: check metadata all pages
// todo: wait for wrangler webhook --> add Algolia + filters (+ URL filtering) https://www.algolia.com/developers/contentful-search-algolia/ (webhook problem)
// todo: add small transitions & animations
// - home articles: show tags staggered in hover
Expand Down
31 changes: 14 additions & 17 deletions src/pages/tags/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,20 @@ const { tag } = Astro.props as TagProps;
<h1 class="flex justify-center">#{slug}</h1>
<section class="common-wrapper">
<ul class="tag__article__list flex row-wrap">
{tag.articles?.map((article, index) => {

return (
<li class="tag__article__item">
<ArticleCard {...article} />
<script type="application/ld+json" set:html={JSON.stringify({
'@context': 'https://schema.org',
'@type': 'ItemList',
'itemListElement': {
'@type': 'ListItem',
'position': index + 1,
'url': new URL(`/articles/${article.slug}`, Astro.url).href,
},
})} />
</li>
);
})}
{tag.articles?.map((article, index) => (
<li class="tag__article__item">
<ArticleCard {...article} />
<script type="application/ld+json" set:html={JSON.stringify({
'@context': 'https://schema.org',
'@type': 'ItemList',
'itemListElement': {
'@type': 'ListItem',
'position': index + 1,
'url': new URL(`/articles/${article.slug}`, Astro.url).href,
},
})} />
</li>
))}
</ul>
</section>
</BaseLayout>
2 changes: 1 addition & 1 deletion src/pages/tags/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const tags = await tagDTO.render(rawTags as RawTag[]);
{tags[letter].map(({ name, slug, count }) => (
<li class="tag__item font-sans-serif">
<a href={`/tags/${slug}`}>{name}</a>
({count})
(&times;{count})
</li>
<script type="application/ld+json" set:html={JSON.stringify({
'@context': 'https://schema.org',
Expand Down
Binary file removed src/ui/assets/images/favicon/favicon.png
Binary file not shown.
8 changes: 8 additions & 0 deletions src/ui/modules/core/components/errorLayer/ErrorLayer.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
import "./error-layer.css";
---
<section class="error-layer__wrapper common-wrapper flex column-nowrap justify-center align-center">
<slot />
<p>Why not try going back to the <a href="/" class="link">homepage</a>?</p>
</section>
<div class="travolta" />
17 changes: 17 additions & 0 deletions src/ui/modules/core/components/errorLayer/error-layer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.error-layer__wrapper {
height: 100vh;
position: relative;
text-align: center;
translate: 0 -25%;
width: 100vw;
z-index: 1;
}

.travolta {
background: url('https://assets-9gag-fun.9cache.com/s/fab0aa49/033037194a549b0bf83e2ac4ba90706a52a9132e/static/dist/web6/img/404/bg.gif') center center / cover no-repeat;
height: 120%;
inset: 0;
opacity: 0.5;
position: absolute;
width: 100%;
}
42 changes: 5 additions & 37 deletions src/ui/modules/core/components/head/Head.astro
Original file line number Diff line number Diff line change
@@ -1,59 +1,27 @@
---
import { TWITTER_HANDLE } from "astro:env/client";
import type { SeoMetadata } from "@const/types";
import "@fontsource-variable/nunito-sans";
import "@fontsource/baskervville";
import { GOOGLE_ANALYTICS_ID, GOOGLE_TAG_MANAGER_ID } from "astro:env/client";
import { ViewTransitions } from "astro:transitions";
import { DEFAULT_SEO_PARAMS } from "@const/index";
import Seo from "@modules/core/components/seo/Seo.astro";
import "@styles/index.css";
type SiteHeadProps = SeoMetadata;
type HeadProps = SeoMetadata;
const canonical = new URL(Astro.url.pathname, Astro.site);
const { IMAGE, TITLE, DESCRIPTION, ROBOTS } = DEFAULT_SEO_PARAMS;
const {
title = TITLE,
description = DESCRIPTION,
image = IMAGE,
robots = { ...ROBOTS, ...Astro.props },
} = Astro.props as SiteHeadProps;
const props = Astro.props as HeadProps;
---

<head lang="en">
<script define:vars={{ GOOGLE_TAG_MANAGER_ID }}>
<script define:vars={{ GOOGLE_TAG_MANAGER_ID }}>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer',GOOGLE_TAG_MANAGER_ID);
</script>
<ViewTransitions />
<meta name="generator" content={Astro.generator} />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="color-scheme" content="light dark">
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="canonical" href={canonical} />
<link rel="sitemap" href="/sitemap-index.xml" />
<title>{title}</title>
<meta name="title" content={title} />
<meta name="robots" content={`${robots.index ? 'index' : 'noindex'}, ${robots.follow ? 'follow' : 'nofollow'}`} />
<meta name="description" content={description} />
<meta property="og:type" content="website" />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(image, Astro.url)} />
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />
<meta property="twitter:creator" content={TWITTER_HANDLE} />
<meta property="twitter:site" content={TWITTER_HANDLE} />
<Seo {...props} />
</head>
<script define:vars={{ GOOGLE_ANALYTICS_ID }}>
window.dataLayer = window.dataLayer || [];
Expand Down
42 changes: 42 additions & 0 deletions src/ui/modules/core/components/seo/Seo.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
import { TWITTER_HANDLE } from "astro:env/client";
import { DEFAULT_SEO_PARAMS } from "@const/index";
import type { SeoMetadata } from "@const/types";
type SeoProps = SeoMetadata;
const canonical = new URL(Astro.url.pathname, Astro.site);
const { IMAGE, TITLE, DESCRIPTION, ROBOTS } = DEFAULT_SEO_PARAMS;
const {
title = TITLE,
description = DESCRIPTION,
image = IMAGE,
robots = { ...ROBOTS, ...Astro.props.robots },
} = Astro.props as SeoProps;
---
<title>{title} | Bianca Fiore</title>
<meta name="generator" content={Astro.generator} />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="color-scheme" content="light dark">
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="canonical" href={canonical} />
<link rel="sitemap" href="/sitemap-index.xml" />
<meta name="title" content={title} />
<meta name="robots" content={`${robots.index ? 'index' : 'noindex'}, ${robots.follow ? 'follow' : 'nofollow'}`} />
<meta name="googlebot" content={`${robots.index ? 'index' : 'noindex'}, ${robots.follow ? 'follow' : 'nofollow'}`} />
<meta name="description" content={description} />
<meta property="og:type" content="website" />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(image, Astro.url)} />
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />
<meta property="twitter:creator" content={TWITTER_HANDLE} />
<meta property="twitter:site" content={TWITTER_HANDLE} />
1 change: 1 addition & 0 deletions src/ui/modules/core/components/slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { Swiper, SwiperSlide } from "swiper/react";
import type { Swiper as SwiperClass, SwiperOptions } from "swiper/types";
import { SliderNavigation } from "./atoms/SliderNavigation";
import "swiper/css/bundle";

export interface Slider<T> {
items: T[];
Expand Down
8 changes: 4 additions & 4 deletions src/ui/styles/vendor/cookie-consent.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--cc-btn-primary-bg: none !important;
--cc-btn-primary-color: oklch(24.18% 0.004 228.95) !important;
--cc-btn-primary-hover-bg: var(--primary-main) !important;
--cc-btn-primary-hover-border-color: var(--cc-btn-primary-hover-bg) !important;
--cc-btn-primary-hover-border-color: var(--cc-btn-primary-hover-bg) !important;
--cc-btn-primary-hover-color: var(--cc-btn-primary-color) !important;
--cc-btn-primary-border-color: var(--neutral-main) !important;
--cc-btn-secondary-bg: var(--background-main) !important;
Expand Down Expand Up @@ -40,7 +40,7 @@
--cc-footer-border-color: var(--neutral-light-3) !important;

.cm,
.pm {
.pm {
color-scheme: light;
}
.pm__section-arrow svg {
Expand Down Expand Up @@ -98,10 +98,10 @@
--cc-footer-color: var(--cc-primary-color);
--cc-footer-border-color: color-mix(in srgb, var(--neutral-main), var(--white) 70%);
}
.pm__section--expandable.is-expanded{
.pm__section--expandable.is-expanded {
background-color: var(--primary-dark-3) !important;
}
.cc__link{
.cc__link {
color: var(--neutral-main) !important
}
.pm__close-btn:hover {
Expand Down
1 change: 0 additions & 1 deletion src/ui/styles/vendor/vendor.css
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import url('swiper/css/bundle');
@import url('vanilla-cookieconsent/dist/cookieconsent.css');
Loading

0 comments on commit 90a14c5

Please sign in to comment.