Skip to content

Commit

Permalink
Merge pull request #1004 from datopian/custom-404
Browse files Browse the repository at this point in the history
[site]: Custom 404 page + JSON-LD breadcrumbs
  • Loading branch information
demenech committed Aug 9, 2023
2 parents ed9b575 + 6a36e65 commit af7812f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion site/content/docs/creating-new-datasets.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'Creating new datasets'
description: 'PortalJS Tutorial II - Learn how to create new datasets on a data portal'
description: 'Learn how to create new datasets on a data portal'
---

So far, the PortalJS app we created only has a single page displaying a dataset. Data catalogs and data portals generally showcase many different datasets.
Expand Down
9 changes: 5 additions & 4 deletions site/content/docs/deploying-your-portaljs-app.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<NextSeo title="Deploying your PortalJS app - PortalJS" />

# Deploying your PortalJS app
---
title: Deploying your PortalJS app
description: 'Learn to deploy PortalJS apps'
---

Finally, let's learn how to deploy PortalJS apps to Vercel or Cloudflare Pages.

Expand Down Expand Up @@ -35,7 +36,7 @@ When you deploy, your PortalJS app will start building. It should finish in unde

When it’s done, you’ll get deployment URLs. Click on one of the URLs and you should see your PortalJS app live.

>[!tip]
> [!tip]
> You can find a more in-depth explanation about this process at https://nextjs.org/learn/basics/deploying-nextjs-app/deploy
### One-Click Deploy
Expand Down
7 changes: 4 additions & 3 deletions site/content/docs/searching-datasets.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<NextSeo title="Searching datasets - PortalJS" />

# Searching datasets
---
title: Searching datasets
description: "Learn how to create a searchable datasets index"
---

Typing out every link in the index page will get cumbersome eventually, and as the portal grows, finding the datasets you are looking for on the index page will become harder and harder, for that we will need search functionality.

Expand Down
7 changes: 4 additions & 3 deletions site/content/docs/showing-metadata.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<NextSeo title="Showing metadata - PortalJS" />

# Showing metadata
---
title: Showing metadata
description: "Learn how to display metadata on the dataset page of a data portal"
---

If you go now to `http://localhost:3000/my-awesome-dataset`, you will see that we now have two titles on the page. That's because `title` is one of the default metadata fields supported by PortalJS.

Expand Down
24 changes: 24 additions & 0 deletions site/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Layout from '@/components/Layout';
import { NextSeo } from 'next-seo';
import Link from 'next/link';

export default function () {
return (
<>
<NextSeo noindex={true} nofollow={true} />
<Layout>
<div className="flex items-center justify-center h-full">
<div className="text-center">
<h1 className="text-2xl">404 - Page not found</h1>
<p className="text-lg mt-5">
It seems like you are looking for a page that doesn't exist.
</p>
<Link className="underline" href="/">
Go back to home
</Link>
</div>
</div>
</Layout>
</>
);
}
11 changes: 11 additions & 0 deletions site/pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CustomAppProps } from './_app.jsx';
import computeFields from '@/lib/computeFields';
import { getAuthorsDetails } from '@/lib/getAuthorsDetails';
import JSONLD from '@/components/JSONLD';
import { BreadcrumbJsonLd } from 'next-seo';

export default function Page({ source, meta, sidebarTree }) {
source = JSON.parse(source);
Expand All @@ -29,9 +30,19 @@ export default function Page({ source, meta, sidebarTree }) {
setTableOfContents(toc ?? []);
}, [router.asPath]); // update table of contents on route change with next/link

const urlSegments = meta.urlPath.split('/');
const breadcrumbs = urlSegments.map((segment, i) => {
return {
position: i + 1,
name: i == urlSegments.length - 1 ? meta.title || segment : segment,
item: '/' + urlSegments.slice(0, i + 1).join('/'),
};
});

return (
<>
<JSONLD meta={meta} source={source.compiledSource} />
<BreadcrumbJsonLd itemListElements={breadcrumbs} />
<Layout
tableOfContents={tableOfContents}
title={meta.title}
Expand Down

1 comment on commit af7812f

@vercel
Copy link

@vercel vercel bot commented on af7812f Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.