Compare commits
16 Commits
538-banner
...
878-how-to
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11144758ca | ||
|
|
f443dab92c | ||
|
|
d9be7d0f5b | ||
|
|
7c21993b92 | ||
|
|
3f06aa3f01 | ||
|
|
d191178ecf | ||
|
|
a0eb06ee19 | ||
|
|
539fd6c77e | ||
|
|
8fa930b3f4 | ||
|
|
3be88f1cdb | ||
|
|
d0ee06e8d0 | ||
|
|
4e91e88f2b | ||
|
|
ebcb93c996 | ||
|
|
1fc2499c71 | ||
|
|
1af24ef57e | ||
|
|
698c06efda |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,6 +16,7 @@ node_modules
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
.obsidian
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
This is a replica of the awesome data.fivethirtyeight.com using PortalJS.
|
||||
|
||||
You might be asking why we did that, there are three main reasons:
|
||||
|
||||
- The website has a great UI, with multiple datasets being displayed elegantly and with simplicity.
|
||||
- PortalJS allows us to add more functionality to it e.g dataset previews and search functionality.
|
||||
- The project follows our same principles of open sourcing and free data, with every dataset being publicly available on Github.
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
@@ -9,10 +9,36 @@ export default function Document() {
|
||||
type="image/x-icon"
|
||||
href="https://projects.fivethirtyeight.com/shared/favicon.ico"
|
||||
/>
|
||||
<meta property="og:image" content="https://portaljs-fivethirtyeight.vercel.app/share_image.png" />
|
||||
<meta property="twitter:image" content="https://portaljs-fivethirtyeight.vercel.app/share_image.png" />
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://portaljs-fivethirtyeight.vercel.app/share_image.png"
|
||||
/>
|
||||
<meta
|
||||
property="twitter:image"
|
||||
content="https://portaljs-fivethirtyeight.vercel.app/share_image.png"
|
||||
/>
|
||||
</Head>
|
||||
<body>
|
||||
<div className="px-2 max-w-5xl mx-auto pb-2">
|
||||
<div className="mt-2 px-2 bg-[#3c3c3c] text-white">
|
||||
<div className="p-2 text-center">
|
||||
This is a replica to the awesome{' '}
|
||||
<a
|
||||
className="hover:underline font-bold"
|
||||
href="https://data.fivethirtyeight.com"
|
||||
>
|
||||
data.fivethirtyeight.com
|
||||
</a>{' '}
|
||||
website.{' '}
|
||||
<a
|
||||
className="hover:underline font-bold"
|
||||
href="https://github.com/datopian/portaljs/tree/main/examples/fivethirtyeight"
|
||||
>
|
||||
Read more here
|
||||
</a>{' '}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<header className="max-w-5xl mx-auto mt-8 w-full">
|
||||
<div className="border-b-2 pb-2.5 mx-2 border-zinc-800 flex justify-between">
|
||||
<h1 className="flex gap-x-1 items-end">
|
||||
@@ -23,18 +49,16 @@ export default function Document() {
|
||||
alt="FiveThirtyEight"
|
||||
src="data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MjEgNTMuNzYiPjxkZWZzPjxzdHlsZT4uY2xzLTF7ZmlsbDojMDEwMTAxO308L3N0eWxlPjwvZGVmcz48dGl0bGU+QXJ0Ym9hcmQgOTU8L3RpdGxlPjxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTAgMGgyNXY4SDl2MTBoMTV2OEg5djE3SDBWMHpNMzEgMzZoNVYxOGgtNXYtOGgxM3YyNmg0djdIMzF6bTUtMzZoOHY4aC04ek0xNzkgMzZoNVYxOGgtNXYtOGgxM3YyNmg0djdoLTE3em01LTM2aDh2OGgtOHpNMzE2IDM2aDVWMThoLTV2LThoMTN2MjZoNHY3aC0xN3ptNS0zNmg4djhoLTh6TTU0IDI3VjEwaDh2MTVsNCA5Ljk4aDFMNzEgMjVWMTBoOHYxN2wtNyAxNkg2MWwtNy0xNnpNMTExIDQzSDk3LjQyQzg5LjIzIDQzIDg1IDM5LjE5IDg1IDMxLjE3VjIyYzAtNy41NyA0LjMtMTMgMTMtMTMgOS4zMyAwIDEzIDUuMDcgMTMgMTR2N0g5NHYxLjc0YzAgMi42MiAxIDQuMjYgMy40MiA0LjI2SDExMXpNOTQgMjNoOHYtMS41NWMwLTIuNjItMS4wNi01LjQ1LTQuMTMtNS40NS0yLjc5IDAtMy44NyAyLjItMy44NyA1LjQ1ek0xMjUgOGgtMTBWMGgyOXY4aC0xMHYzNWgtOVY4ek0yMDIgNDNWMTBoOHY0YzEuMTQtMi40NSAzLjc1LTQgNy4yMi00SDIyMHY4aC02Yy0yLjg0IDAtNCAuOTQtNCAzLjlWNDN6TTI0NSA0M2gtNC44NEMyMzMuMDUgNDMgMjMwIDM5LjMxIDIzMCAzMS44NVYxOGgtNnYtOGg2VjNoOHY3aDd2OGgtN2wtLjA3IDEzLjkzYzAgMi4yMi45MyA0LjA3IDMuNjYgNC4wN0gyNDV6TTQyMSA0M2gtNC44NEM0MDkuMDUgNDMgNDA2IDM5LjMxIDQwNiAzMS44NVYxOGgtNnYtOGg2VjNoOHY3aDd2OGgtN2wtLjA3IDEzLjkzYzAgMi4yMi45MyA0LjA3IDMuNjYgNC4wN0g0MjF6TTI1NC4yNiA1My43Nmw0LjYxLTkuNUwyNTEgMjdWMTBoOHYxNWw0IDEwaDFsNC0xMFYxMGg4djE3bC0xMi4zIDI2Ljc2aC05LjQ0ek0yODQgMGgyNXY4aC0xNnY5aDE1djhoLTE1djEwaDE2djhoLTI1VjB6TTMzNyA0OHYtMmgxNi4xYzIgMCAyLjktLjE4IDIuOS0xLjI3di0uMzRjMC0xLjA4LS45MS0xLjM5LTIuOS0xLjM5SDM0MHYtNWw1LTVjLTUuMjktMS40OC04LTUuNDMtOC0xMXYtMWMwLTcuNTYgNC40NC0xMiAxNC0xMmEyMS45MyAyMS45MyAwIDAgMSA1Ljk1IDFMMzYxIDRsNSAzLTQgNmMxLjM3IDEuOTMgMyA0LjkzIDMgOHYxYzAgNy0zLjMgMTAuNjYtMTIgMTFsLTMgNGg2YzUuOTIgMCA5IDIuNjIgOSA3LjY4di4xMWMwIDUuMDYtMi43MSA4LjIxLTguNjIgOC4yMWgtMTNjLTQuMjkgMC02LjM4LTEuODQtNi4zOC01em0xOS0yNXYtM2MwLTMuMy0xLjMzLTQtNS00cy01IC43LTUgNHYzYzAgMy4zIDEuMzkgNCA1IDRzNS0uNyA1LTR6TTM4MCA0M2gtOFYwaDh2MTRjMS4xNC0yLjY3IDMuNC00IDctNCA2LjI2IDAgOSAzLjA4IDkgMTAuNzZWNDNoLThWMjJjMC0zLjEzLTEuMDctNS00LTVzLTQgMS44Ny00IDV6TTE1NyA0M2gtOFYwaDh2MTRjMS4xNC0yLjY3IDMuOTEtNCA3LjQ5LTQgNi4yNiAwIDguNTEgMy4xMyA4LjUxIDEwLjgxVjQzaC04VjIxYzAtMy4xMy0xLjA3LTQuNDQtNC00LjQ0cy00IDIuMjYtNCA1LjM5eiIvPjwvc3ZnPg=="
|
||||
/>{' '}
|
||||
<span className="-mb-0.5 text-[#3c3c3c]">
|
||||
tribute by PortalJS
|
||||
</span>
|
||||
<span className="-mb-0.5 text-[#3c3c3c]">replica</span>
|
||||
</h1>
|
||||
<div className='md:flex items-center gap-x-3 text-[#3c3c3c] -mb-1 hidden'>
|
||||
<div className="md:flex items-center gap-x-3 text-[#3c3c3c] -mb-1 hidden">
|
||||
<a
|
||||
className="hover:opacity-75 transition"
|
||||
href="https://portaljs.org"
|
||||
>
|
||||
Built with 🌀PortalJS
|
||||
</a>
|
||||
<hr className='h-[80%] border border-[#3c3c3c] opacity-75 my-2'></hr>
|
||||
<hr className="h-[80%] border border-[#3c3c3c] opacity-75 my-2"></hr>
|
||||
<a
|
||||
className="hover:opacity-75 transition"
|
||||
href="https://github.com/datopian/portaljs/tree/main/examples/fivethirtyeight"
|
||||
|
||||
@@ -143,19 +143,6 @@ export default function Home({ datasets }: { datasets: Dataset[] }) {
|
||||
return (
|
||||
<>
|
||||
<NextSeo title="FiveThirtyEight tribute by PortalJS" />
|
||||
<div className="max-w-5xl mx-auto mt-2 px-2 text-[#3c3c3c]">
|
||||
<div className="border border-zinc-600 p-4 text-left">
|
||||
This page is a tribute to the{' '}
|
||||
<a className='hover:underline font-bold' href="https://data.fivethirtyeight.com">
|
||||
data.fivethirtyeight.com
|
||||
</a>{' '}
|
||||
website made by the amazing 538 team. All content is credited to the original creators, intended for
|
||||
educational purposes only. Visit their{' '}
|
||||
<a className='hover:underline font-bold' href="https://fivethirtyeight.com/">website</a> for in-depth analyses
|
||||
on politics, sports, culture, and more. No copyright infringement
|
||||
intended.
|
||||
</div>
|
||||
</div>
|
||||
<main
|
||||
className={`flex min-h-screen flex-col items-center max-w-5xl mx-auto pt-20 px-2.5 ${inter.className}`}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"next",
|
||||
"next/core-web-vitals"
|
||||
],
|
||||
"extends": ["next", "next/core-web-vitals"],
|
||||
"ignorePatterns": ["!**/*", ".next/**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
|
||||
7
examples/github-backed-catalog/.prettierignore
Normal file
7
examples/github-backed-catalog/.prettierignore
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
**/.next/**
|
||||
**/_next/**
|
||||
**/dist/**
|
||||
**/__tmp__/**
|
||||
lerna.json
|
||||
.github
|
||||
1
examples/github-backed-catalog/.prettierrc.json
Normal file
1
examples/github-backed-catalog/.prettierrc.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -99,4 +99,3 @@ And run the production build with:
|
||||
```
|
||||
npm run start
|
||||
```
|
||||
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
import Link from "next/link";
|
||||
import HomeIcon from "../icons/HomeIcon";
|
||||
|
||||
export default function Breadcrumbs({ links }: { links: { title: string, href?: string, target?: string }[] }) {
|
||||
export default function Breadcrumbs({
|
||||
links,
|
||||
}: {
|
||||
links: { title: string; href?: string; target?: string }[];
|
||||
}) {
|
||||
const current = links.at(-1);
|
||||
|
||||
return <div className="flex items-center uppercase font-black text-xs">
|
||||
<Link className="flex items-center" href='/'><HomeIcon /></Link>
|
||||
return (
|
||||
<div className="flex items-center uppercase font-black text-xs">
|
||||
<Link className="flex items-center" href="/">
|
||||
<HomeIcon />
|
||||
</Link>
|
||||
|
||||
{/* {links.length > 1 && links.slice(0, -1).map((link) => {
|
||||
{/* {links.length > 1 && links.slice(0, -1).map((link) => {
|
||||
return <>
|
||||
<span className="mx-4">/</span>
|
||||
<Link href={link.href}>{link.title}</Link>
|
||||
</>
|
||||
})} */}
|
||||
|
||||
<span className="mx-4">/</span>
|
||||
<span>{current.title}</span>
|
||||
</div >
|
||||
}
|
||||
<span className="mx-4">/</span>
|
||||
<span>{current.title}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
export default function ExternalLinkIcon({ className = "" }) {
|
||||
return <div className={`inline-block w-4 ${className}`}><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentColor"><path d="M 40 10 C 38.896 10 38 10.896 38 12 C 38 13.104 38.896 14 40 14 L 47.171875 14 L 30.585938 30.585938 C 29.804938 31.366938 29.804938 32.633063 30.585938 33.414062 C 30.976938 33.805063 31.488 34 32 34 C 32.512 34 33.023063 33.805062 33.414062 33.414062 L 50 16.828125 L 50 24 C 50 25.104 50.896 26 52 26 C 53.104 26 54 25.104 54 24 L 54 12 C 54 10.896 53.104 10 52 10 L 40 10 z M 18 12 C 14.691 12 12 14.691 12 18 L 12 46 C 12 49.309 14.691 52 18 52 L 46 52 C 49.309 52 52 49.309 52 46 L 52 34 C 52 32.896 51.104 32 50 32 C 48.896 32 48 32.896 48 34 L 48 46 C 48 47.103 47.103 48 46 48 L 18 48 C 16.897 48 16 47.103 16 46 L 16 18 C 16 16.897 16.897 16 18 16 L 30 16 C 31.104 16 32 15.104 32 14 C 32 12.896 31.104 12 30 12 L 18 12 z"/></svg></div>
|
||||
}
|
||||
return (
|
||||
<div className={`inline-block w-4 ${className}`}>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 64 64"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="M 40 10 C 38.896 10 38 10.896 38 12 C 38 13.104 38.896 14 40 14 L 47.171875 14 L 30.585938 30.585938 C 29.804938 31.366938 29.804938 32.633063 30.585938 33.414062 C 30.976938 33.805063 31.488 34 32 34 C 32.512 34 33.023063 33.805062 33.414062 33.414062 L 50 16.828125 L 50 24 C 50 25.104 50.896 26 52 26 C 53.104 26 54 25.104 54 24 L 54 12 C 54 10.896 53.104 10 52 10 L 40 10 z M 18 12 C 14.691 12 12 14.691 12 18 L 12 46 C 12 49.309 14.691 52 18 52 L 46 52 C 49.309 52 52 49.309 52 46 L 52 34 C 52 32.896 51.104 32 50 32 C 48.896 32 48 32.896 48 34 L 48 46 C 48 47.103 47.103 48 46 48 L 18 48 C 16.897 48 16 47.103 16 46 L 16 18 C 16 16.897 16.897 16 18 16 L 30 16 C 31.104 16 32 15.104 32 14 C 32 12.896 31.104 12 30 12 L 18 12 z" />
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
export default function HomeIcon({ className = "" }) {
|
||||
return <div className={`inline-block w-4 ${className}`}><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 12 2 A 1 1 0 0 0 11.289062 2.296875 L 1.203125 11.097656 A 0.5 0.5 0 0 0 1 11.5 A 0.5 0.5 0 0 0 1.5 12 L 4 12 L 4 20 C 4 20.552 4.448 21 5 21 L 9 21 C 9.552 21 10 20.552 10 20 L 10 14 L 14 14 L 14 20 C 14 20.552 14.448 21 15 21 L 19 21 C 19.552 21 20 20.552 20 20 L 20 12 L 22.5 12 A 0.5 0.5 0 0 0 23 11.5 A 0.5 0.5 0 0 0 22.796875 11.097656 L 12.716797 2.3027344 A 1 1 0 0 0 12.710938 2.296875 A 1 1 0 0 0 12 2 z"/></svg></div>
|
||||
}
|
||||
return (
|
||||
<div className={`inline-block w-4 ${className}`}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
{" "}
|
||||
<path d="M 12 2 A 1 1 0 0 0 11.289062 2.296875 L 1.203125 11.097656 A 0.5 0.5 0 0 0 1 11.5 A 0.5 0.5 0 0 0 1.5 12 L 4 12 L 4 20 C 4 20.552 4.448 21 5 21 L 9 21 C 9.552 21 10 20.552 10 20 L 10 14 L 14 14 L 14 20 C 14 20.552 14.448 21 15 21 L 19 21 C 19.552 21 20 20.552 20 20 L 20 12 L 22.5 12 A 0.5 0.5 0 0 0 23 11.5 A 0.5 0.5 0 0 0 22.796875 11.097656 L 12.716797 2.3027344 A 1 1 0 0 0 12.710938 2.296875 A 1 1 0 0 0 12 2 z" />
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@
|
||||
"owner": "datasets",
|
||||
"branch": "main",
|
||||
"repo": "investor-flow-of-funds-us",
|
||||
"files": [
|
||||
"data/monthly.csv",
|
||||
"data/weekly.csv"
|
||||
],
|
||||
"files": ["data/monthly.csv", "data/weekly.csv"],
|
||||
"readme": "README.md"
|
||||
},
|
||||
{
|
||||
@@ -38,7 +35,10 @@
|
||||
"owner": "fivethirtyeight",
|
||||
"repo": "data",
|
||||
"branch": "master",
|
||||
"files": ["nba-raptor/historical_RAPTOR_by_player.csv", "nba-raptor/historical_RAPTOR_by_team.csv"],
|
||||
"files": [
|
||||
"nba-raptor/historical_RAPTOR_by_player.csv",
|
||||
"nba-raptor/historical_RAPTOR_by_team.csv"
|
||||
],
|
||||
"readme": "nba-raptor/README.md"
|
||||
}
|
||||
]
|
||||
|
||||
2
examples/github-backed-catalog/index.d.ts
vendored
2
examples/github-backed-catalog/index.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
declare module '*.svg' {
|
||||
declare module "*.svg" {
|
||||
const content: any;
|
||||
export const ReactComponent: any;
|
||||
export default content;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Octokit } from 'octokit';
|
||||
import { Octokit } from "octokit";
|
||||
|
||||
export interface GithubProject {
|
||||
owner: string;
|
||||
@@ -26,15 +26,16 @@ export async function getProjectReadme(
|
||||
ref: branch,
|
||||
});
|
||||
const data = response.data as { content?: string };
|
||||
const fileContent = data.content ? data.content : '';
|
||||
if (fileContent === '') {
|
||||
const fileContent = data.content ? data.content : "";
|
||||
if (fileContent === "") {
|
||||
return null;
|
||||
}
|
||||
const decodedContent = Buffer.from(fileContent, 'base64').toString();
|
||||
const decodedContent = Buffer.from(fileContent, "base64").toString();
|
||||
return decodedContent;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return null;
|
||||
throw new Error(
|
||||
"Couldn't get project readme please make sure that you are pointing to a valid repo and that the repo in question contains a README.md"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +51,13 @@ export async function getLastUpdated(
|
||||
const response = await octokit.rest.repos.listCommits({
|
||||
owner,
|
||||
repo,
|
||||
path: readme,
|
||||
ref: branch,
|
||||
});
|
||||
return response.data[0].commit.committer.date;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return null;
|
||||
throw new Error(
|
||||
"Couldn't get project list of commits please make sure that you are pointing to a valid repo"
|
||||
);
|
||||
}
|
||||
}
|
||||
export async function getProjectMetadata(
|
||||
@@ -72,8 +73,9 @@ export async function getProjectMetadata(
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return null;
|
||||
throw new Error(
|
||||
"Couldn't get project metadata please make sure that you are pointing to a valid repo"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +96,32 @@ export async function getRepoContents(
|
||||
ref: branch,
|
||||
path: path,
|
||||
});
|
||||
const data = response.data as { download_url?: string, name: string, size: number };
|
||||
contents.push({ download_url: data.download_url, name: data.name, size: data.size});
|
||||
const data = response.data as {
|
||||
download_url?: string;
|
||||
name: string;
|
||||
size: number;
|
||||
};
|
||||
contents.push({
|
||||
download_url: data.download_url,
|
||||
name: data.name,
|
||||
size: data.size,
|
||||
});
|
||||
}
|
||||
return contents;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return null;
|
||||
if (
|
||||
error.message ===
|
||||
'This endpoint can only return blobs smaller than 100 MB in size. The requested blob is too large to fetch via the API, but you can always clone the repository via Git to obtain it.: {"resource":"Blob","field":"data","code":"too_large"}'
|
||||
) {
|
||||
throw new Error(
|
||||
`The requested files ${files.join(
|
||||
", "
|
||||
)} are too big making it impossible to fetch via Github API`
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
"Couldn't get project contents please make sure that you are pointing to a valid repo"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,22 +141,20 @@ export async function getProject(project: GithubProject, github_pat?: string) {
|
||||
project.readme,
|
||||
github_pat
|
||||
);
|
||||
if (!projectReadme) {
|
||||
return null;
|
||||
let projectData = [];
|
||||
if (project.files) {
|
||||
projectData = await getRepoContents(
|
||||
project.owner,
|
||||
project.repo,
|
||||
project.branch,
|
||||
project.files,
|
||||
github_pat
|
||||
);
|
||||
}
|
||||
const projectData = await getRepoContents(
|
||||
project.owner,
|
||||
project.repo,
|
||||
project.branch,
|
||||
project.files,
|
||||
github_pat
|
||||
);
|
||||
if (!projectData) {
|
||||
return null;
|
||||
}
|
||||
const projectBase = project.readme.split('/').length > 1
|
||||
? project.readme.split('/').slice(0, -1).join('/')
|
||||
: '/'
|
||||
const projectBase =
|
||||
project.readme && project.readme.split("/").length > 1
|
||||
? project.readme.split("/").slice(0, -1).join("/")
|
||||
: "/";
|
||||
const last_updated = await getLastUpdated(
|
||||
project.owner,
|
||||
project.repo,
|
||||
@@ -143,5 +162,11 @@ export async function getProject(project: GithubProject, github_pat?: string) {
|
||||
projectBase,
|
||||
github_pat
|
||||
);
|
||||
return { ...projectMetadata, files: projectData, readmeContent: projectReadme, last_updated, base_path: projectBase };
|
||||
return {
|
||||
...projectMetadata,
|
||||
files: projectData,
|
||||
readmeContent: projectReadme,
|
||||
last_updated,
|
||||
base_path: projectBase,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ const nextConfig = {
|
||||
return {
|
||||
beforeFiles: [
|
||||
{
|
||||
source: '/@:org/:project*',
|
||||
destination: '/@org/:org/:project*',
|
||||
source: "/@:org/:project*",
|
||||
destination: "/@org/:org/:project*",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
16
examples/github-backed-catalog/package-lock.json
generated
16
examples/github-backed-catalog/package-lock.json
generated
@@ -27,6 +27,7 @@
|
||||
"@tailwindcss/typography": "^0.5.9",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.23",
|
||||
"prettier": "2.8.8",
|
||||
"tailwindcss": "^3.3.1"
|
||||
}
|
||||
},
|
||||
@@ -4677,6 +4678,21 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/prop-types": {
|
||||
"version": "15.8.1",
|
||||
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
"lint": "next lint",
|
||||
"prettier": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "18.16.0",
|
||||
@@ -28,6 +29,7 @@
|
||||
"@tailwindcss/typography": "^0.5.9",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.23",
|
||||
"prettier": "2.8.8",
|
||||
"tailwindcss": "^3.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
import { NextSeo } from 'next-seo';
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import getConfig from 'next/config';
|
||||
import { getProject, GithubProject } from '../../../lib/octokit';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import Breadcrumbs from '../../../components/_shared/Breadcrumbs';
|
||||
import { NextSeo } from "next-seo";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import getConfig from "next/config";
|
||||
import { getProject, GithubProject } from "../../../lib/octokit";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import Breadcrumbs from "../../../components/_shared/Breadcrumbs";
|
||||
|
||||
export default function ProjectPage({ project }) {
|
||||
const repoId = `@${project.repo_config.owner}/${project.repo_config.repo}`
|
||||
const repoId = `@${project.repo_config.owner}/${project.repo_config.repo}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<NextSeo title={`${repoId}${project.base_path !== '/' ? '/' + project.base_path : ''} - GitHub Datasets`} />
|
||||
<NextSeo
|
||||
title={`${repoId}${
|
||||
project.base_path !== "/" ? "/" + project.base_path : ""
|
||||
} - GitHub Datasets`}
|
||||
/>
|
||||
<main className="prose mx-auto my-8">
|
||||
<Breadcrumbs links={[{ title: repoId, href: "" }]} />
|
||||
<h1 className="mb-0 mt-16">{project.repo_config.name || repoId}</h1>
|
||||
<p className='mb-8'><span className='font-semibold'>Repository:</span> <a target="_blank" href={project.html_url}>{project.html_url}</a></p>
|
||||
<p className="mb-8">
|
||||
<span className="font-semibold">Repository:</span>{" "}
|
||||
<a target="_blank" href={project.html_url}>
|
||||
{project.html_url}
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h2 className="mb-0 mt-10">Files</h2>
|
||||
<div className="inline-block min-w-full py-2 align-middle">
|
||||
@@ -54,7 +63,7 @@ export default function ProjectPage({ project }) {
|
||||
|
||||
<hr />
|
||||
|
||||
<h2 className='uppercase font-black'>Readme</h2>
|
||||
<h2 className="uppercase font-black">Readme</h2>
|
||||
<ReactMarkdown remarkPlugins={[remarkGfm]}>
|
||||
{project.readmeContent}
|
||||
</ReactMarkdown>
|
||||
@@ -65,17 +74,14 @@ export default function ProjectPage({ project }) {
|
||||
|
||||
// Generates `/posts/1` and `/posts/2`
|
||||
export async function getStaticPaths() {
|
||||
const jsonDirectory = path.join(
|
||||
process.cwd(),
|
||||
'datasets.json'
|
||||
);
|
||||
const repos = await fs.readFile(jsonDirectory, 'utf8');
|
||||
const jsonDirectory = path.join(process.cwd(), "datasets.json");
|
||||
const repos = await fs.readFile(jsonDirectory, "utf8");
|
||||
|
||||
return {
|
||||
paths: JSON.parse(repos).map((repo) => {
|
||||
const projectPath =
|
||||
repo.readme.split('/').length > 1
|
||||
? repo.readme.split('/').slice(0, -1)
|
||||
repo.readme && repo.readme.split("/").length > 1
|
||||
? repo.readme.split("/").slice(0, -1)
|
||||
: null;
|
||||
let path = [repo.repo];
|
||||
if (projectPath) {
|
||||
@@ -92,16 +98,13 @@ export async function getStaticPaths() {
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }) {
|
||||
const jsonDirectory = path.join(
|
||||
process.cwd(),
|
||||
'datasets.json'
|
||||
);
|
||||
const reposFile = await fs.readFile(jsonDirectory, 'utf8');
|
||||
const jsonDirectory = path.join(process.cwd(), "datasets.json");
|
||||
const reposFile = await fs.readFile(jsonDirectory, "utf8");
|
||||
const repos: GithubProject[] = JSON.parse(reposFile);
|
||||
const repo = repos.find((_repo) => {
|
||||
const projectPath =
|
||||
_repo.readme.split('/').length > 1
|
||||
? _repo.readme.split('/').slice(0, -1)
|
||||
_repo.readme && _repo.readme.split("/").length > 1
|
||||
? _repo.readme.split("/").slice(0, -1)
|
||||
: null;
|
||||
let path = [_repo.repo];
|
||||
if (projectPath) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AppProps } from 'next/app';
|
||||
import Head from 'next/head';
|
||||
import './styles.css';
|
||||
import { AppProps } from "next/app";
|
||||
import Head from "next/head";
|
||||
import "./styles.css";
|
||||
|
||||
function CustomApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import { getProject } from '../lib/octokit';
|
||||
import getConfig from 'next/config';
|
||||
import ExternalLinkIcon from '../components/icons/ExternalLinkIcon';
|
||||
import TimeAgo from 'react-timeago';
|
||||
import Link from 'next/link';
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { getProject } from "../lib/octokit";
|
||||
import getConfig from "next/config";
|
||||
import ExternalLinkIcon from "../components/icons/ExternalLinkIcon";
|
||||
import TimeAgo from "react-timeago";
|
||||
import Link from "next/link";
|
||||
import { NextSeo } from "next-seo";
|
||||
|
||||
export async function getStaticProps() {
|
||||
const jsonDirectory = path.join(
|
||||
process.cwd(),
|
||||
'/datasets.json'
|
||||
);
|
||||
const repos = await fs.readFile(jsonDirectory, 'utf8');
|
||||
const jsonDirectory = path.join(process.cwd(), "/datasets.json");
|
||||
const repos = await fs.readFile(jsonDirectory, "utf8");
|
||||
const github_pat = getConfig().serverRuntimeConfig.github_pat;
|
||||
|
||||
const projects = await Promise.all(
|
||||
(JSON.parse(repos)).map(async (repo) => {
|
||||
JSON.parse(repos).map(async (repo) => {
|
||||
const project = await getProject(repo, github_pat);
|
||||
return { ...project, repo_config: repo };
|
||||
})
|
||||
@@ -29,88 +27,112 @@ export async function getStaticProps() {
|
||||
|
||||
export function Datasets({ projects }) {
|
||||
return (
|
||||
<div className="bg-white min-h-screen">
|
||||
<div className="mx-auto max-w-7xl px-6 py-16 sm:py-24 lg:px-8">
|
||||
<div className='text-center'>
|
||||
<h2 className="text-3xl font-bold leading-10 tracking-tight">
|
||||
GitHub Datasets
|
||||
</h2>
|
||||
<p className="mt-3 mx-auto max-w-2xl text-base leading-7 text-gray-500">
|
||||
Data catalog with datasets hosted on GitHub by <Link target="_blank" className='underline' href="https://portaljs.org/">🌀 PortalJS</Link>
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-20">
|
||||
<div className="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div className="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
|
||||
<table className="min-w-full divide-y divide-gray-300">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Name
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Repository
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Description
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Last updated
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="relative py-3.5 pl-3 pr-4 sm:pr-0"
|
||||
></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-200">
|
||||
{projects.map((project) => (
|
||||
<tr key={project.id}>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm text-gray-500">
|
||||
{project.repo_config.name
|
||||
? project.repo_config.name
|
||||
: project.full_name + (project.base_path === '/' ? '' : '/' + project.base_path)}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm group text-gray-500 hover:text-gray-900 transition-all duration-250">
|
||||
<a href={project.html_url} target="_blank" className='flex items-center'>@{project.full_name} <ExternalLinkIcon className='ml-1' /></a>
|
||||
</td>
|
||||
<td className="px-3 py-4 text-sm text-gray-500">
|
||||
{project.repo_config.description
|
||||
? project.repo_config.description
|
||||
: project.description}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm text-gray-500">
|
||||
<TimeAgo date={new Date(project.last_updated)} />
|
||||
</td>
|
||||
<td className="relative whitespace-nowrap py-6 pl-3 pr-4 text-right text-sm font-medium sm:pr-0">
|
||||
<a
|
||||
href={`/@${project.repo_config.owner}/${project.repo_config.repo}/${project.base_path === '/' ? '' : project.base_path}`}
|
||||
className='border border-gray-900 text-gray-900 px-4 py-2 transition-all hover:bg-gray-900 hover:text-white'
|
||||
>
|
||||
info
|
||||
</a>
|
||||
</td>
|
||||
<>
|
||||
<NextSeo title="GitHub Datasets" />
|
||||
<div className="bg-white min-h-screen">
|
||||
<div className="mx-auto max-w-7xl px-6 py-16 sm:py-24 lg:px-8">
|
||||
<div className="text-center">
|
||||
<h2 className="text-3xl font-bold leading-10 tracking-tight">
|
||||
GitHub Datasets
|
||||
</h2>
|
||||
<p className="mt-3 mx-auto max-w-2xl text-base leading-7 text-gray-500">
|
||||
Data catalog with datasets hosted on GitHub by{" "}
|
||||
<Link
|
||||
target="_blank"
|
||||
className="underline"
|
||||
href="https://portaljs.org/"
|
||||
>
|
||||
🌀 PortalJS
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-20">
|
||||
<div className="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div className="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
|
||||
<table className="min-w-full divide-y divide-gray-300">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Name
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Repository
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Description
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
|
||||
>
|
||||
Last updated
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="relative py-3.5 pl-3 pr-4 sm:pr-0"
|
||||
></th>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-200">
|
||||
{projects.map((project) => (
|
||||
<tr key={project.id}>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm text-gray-500">
|
||||
{project.repo_config.name
|
||||
? project.repo_config.name
|
||||
: project.full_name +
|
||||
(project.base_path === "/"
|
||||
? ""
|
||||
: "/" + project.base_path)}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm group text-gray-500 hover:text-gray-900 transition-all duration-250">
|
||||
<a
|
||||
href={project.html_url}
|
||||
target="_blank"
|
||||
className="flex items-center"
|
||||
>
|
||||
@{project.full_name}{" "}
|
||||
<ExternalLinkIcon className="ml-1" />
|
||||
</a>
|
||||
</td>
|
||||
<td className="px-3 py-4 text-sm text-gray-500">
|
||||
{project.repo_config.description
|
||||
? project.repo_config.description
|
||||
: project.description}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-3 py-6 text-sm text-gray-500">
|
||||
<TimeAgo date={new Date(project.last_updated)} />
|
||||
</td>
|
||||
<td className="relative whitespace-nowrap py-6 pl-3 pr-4 text-right text-sm font-medium sm:pr-0">
|
||||
<a
|
||||
href={`/@${project.repo_config.owner}/${
|
||||
project.repo_config.repo
|
||||
}/${
|
||||
project.base_path === "/" ? "" : project.base_path
|
||||
}`}
|
||||
className="border border-gray-900 text-gray-900 px-4 py-2 transition-all hover:bg-gray-900 hover:text-white"
|
||||
>
|
||||
info
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@ module.exports = {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,8 +8,5 @@ module.exports = {
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [
|
||||
require('@tailwindcss/typography')
|
||||
],
|
||||
}
|
||||
|
||||
plugins: [require("@tailwindcss/typography")],
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ In the following page type `content/datasets/<name-of-the-file>.md`. if you want
|
||||
|
||||
### Fill in content
|
||||
|
||||
Copy the contents of `templates/dataset.md` or `templates/keywords.md` respectively to the camp below, filling out the fields with the correct data format
|
||||
Copy the contents of `templates/dataset.md` or `templates/keywords.md` respectively to the camp below, filling out the fields with the correct data format. Everything below the second `---` will automatically get rendered into the page, so you may add any standard markdown fields e.g tables, headings, lists...
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -161,13 +161,14 @@ export default function Layout({
|
||||
>
|
||||
Built by{' '}
|
||||
<img
|
||||
src={
|
||||
theme === 'dark'
|
||||
? '/images/datopian-light-logotype.svg'
|
||||
: '/images/datopian-dark-logotype.svg'
|
||||
}
|
||||
src="/images/datopian-light-logotype.svg"
|
||||
alt="Datopian Logo"
|
||||
className="h-6 ml-2"
|
||||
className="h-6 ml-2 hidden dark:block"
|
||||
/>
|
||||
<img
|
||||
src="/images/datopian-dark-logotype.svg"
|
||||
alt="Datopian Logo"
|
||||
className="h-6 ml-2 dark:hidden"
|
||||
/>
|
||||
</a>
|
||||
</footer>
|
||||
|
||||
BIN
site/content/assets/howto/catalog-example.png
Normal file
BIN
site/content/assets/howto/catalog-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
site/content/assets/howto/catalog-facets-example.png
Normal file
BIN
site/content/assets/howto/catalog-facets-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
site/content/assets/howto/comments-example.png
Normal file
BIN
site/content/assets/howto/comments-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
BIN
site/content/assets/howto/linechart-example.png
Normal file
BIN
site/content/assets/howto/linechart-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
site/content/assets/howto/table-example.png
Normal file
BIN
site/content/assets/howto/table-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
77
site/content/howto/analytics.md
Normal file
77
site/content/howto/analytics.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# How to add Google Analytics?
|
||||
|
||||
>[!todo] Prerequisites
|
||||
>- [Google Analytics account](https://support.google.com/analytics/answer/9304153?hl=en)
|
||||
>- [Google tag ID](https://support.google.com/analytics/answer/12270356?hl=en#:~:text=A%20Measurement%20ID%20is%20an,same%20as%20your%20destination%20ID.)
|
||||
|
||||
The following piece of code adds pageview tracking functionality to the custom Next.js App in `/pages/_app.tsx`, but you can use it only in specific pages if you want.
|
||||
|
||||
```tsx
|
||||
// /pages/_app.tsx
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect } from "react";
|
||||
import Script from "next/script";
|
||||
|
||||
// Step 0:
|
||||
// Add your Google tag ID to your local .env.local file, e.g. under GA_TRACKING_ID
|
||||
|
||||
// Step 1: create the following pageview function
|
||||
const pageview = ({
|
||||
url,
|
||||
analyticsID,
|
||||
}: {
|
||||
url: string;
|
||||
analyticsID: string;
|
||||
}) => {
|
||||
if (typeof window.gtag !== undefined) {
|
||||
window.gtag("config", analyticsID, {
|
||||
page_path: url,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default function MyApp({ Component, pageProps }) {
|
||||
const router = useRouter();
|
||||
|
||||
// ... your code
|
||||
|
||||
// Step 3: Add the following useEffect to trigger pageview on each route change
|
||||
useEffect(() => {
|
||||
const handleRouteChange = (url) => {
|
||||
pageview(url, GA_TRACKING_ID);
|
||||
};
|
||||
router.events.on("routeChangeComplete", handleRouteChange);
|
||||
return () => {
|
||||
router.events.off("routeChangeComplete", handleRouteChange);
|
||||
};
|
||||
}, [router.events]);
|
||||
|
||||
return (
|
||||
{/* Step 4: Install Google Analytics tag */}
|
||||
<>
|
||||
<Script
|
||||
strategy="afterInteractive"
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
|
||||
/>
|
||||
<Script
|
||||
id="gtag-init"
|
||||
strategy="afterInteractive"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${GA_TRACKING_ID}', {
|
||||
page_path: window.location.pathname,
|
||||
});
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
<Component {...pageProps} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> For more info on measuring pageviews with Google Analytics see [Google Analytics documentation](https://developers.google.com/analytics/devguides/collection/gtagjs/pages).
|
||||
75
site/content/howto/blog.md
Normal file
75
site/content/howto/blog.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# How to add a simple blog?
|
||||
|
||||
## Setup
|
||||
|
||||
The following example uses components imported from the [`@flowershow/core` package](https://github.com/datopian/flowershow). If you want to follow along install it too:
|
||||
|
||||
```sh
|
||||
npm i @flowershow/core
|
||||
```
|
||||
|
||||
## Create home page for your blogs
|
||||
|
||||
Add the following code to the Next.js page that is going to be your blog home page, e.g. to `/pages/blog/index.tsx`:
|
||||
|
||||
```tsx
|
||||
import { BlogsList, SimpleLayout } from "@flowershow/core";
|
||||
|
||||
// pass a list of blogs, home page title and home page description, e.g. from `getStaticProps`
|
||||
export default function BlogIndex({ blogs, title, description }) {
|
||||
return (
|
||||
<SimpleLayout title={title} description={description}>
|
||||
<BlogsList blogs={blogs} />
|
||||
</SimpleLayout>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
`BlogsList` component has the following API:
|
||||
|
||||
```ts
|
||||
interface BlogsListProps {
|
||||
blogs: Blog;
|
||||
}
|
||||
|
||||
interface Blog {
|
||||
title: string;
|
||||
date: string;
|
||||
urlPath: string;
|
||||
description?: string;
|
||||
authors?: Array<string>;
|
||||
tags?: Array<string>;
|
||||
}
|
||||
```
|
||||
|
||||
## Create blog post pages
|
||||
|
||||
Add the following code to your blog pages, e.g. to `/pages/blog/[...slug].tsx`:
|
||||
|
||||
```tsx
|
||||
import { BlogLayout } from "@flowershow/core";
|
||||
|
||||
export default BlogPost({ content, title, date, authors }) {
|
||||
return (
|
||||
<BlogLayout title={title} date={date} authors={authors}
|
||||
{content}
|
||||
</BlogLayout>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
`BlogLayout` component has the following API:
|
||||
|
||||
```ts
|
||||
interface BlogLayoutProps {
|
||||
title?: string;
|
||||
date?: string;
|
||||
authors?: Array<Author>;
|
||||
}
|
||||
|
||||
interface Author {
|
||||
name: string;
|
||||
avatar: string; // avatar image path
|
||||
urlPath?: string; // author page
|
||||
}
|
||||
```
|
||||
106
site/content/howto/comments.md
Normal file
106
site/content/howto/comments.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# How to add user comments?
|
||||
|
||||
![[comments-example.png]]
|
||||
|
||||
## Setup
|
||||
|
||||
Page comments can be setup with any one of the following supported providers:
|
||||
|
||||
1. [giscus](https://giscus.app/)
|
||||
2. [utterances](https://utteranc.es/)
|
||||
3. [disqus](https://disqus.com/)
|
||||
|
||||
Each provider has it's own configuration options that you should add to your `.env` file.
|
||||
|
||||
>[!Info]
|
||||
>If you are hosting your website on hosting providers like Netlify, Vercel or Cloudflare, you will also need to add the environment variables there.
|
||||
|
||||
### Giscus
|
||||
|
||||
[Giscus](https://giscus.app/) uses your github repo's discussions feature to store your comments and display them on your site.
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
1. You have a public [github repository](https://docs.github.com/en/get-started/quickstart/create-a-repo) with the [discussions](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/enabling-or-disabling-github-discussions-for-a-repository) feature activated which will be used to store your comments.
|
||||
2. The [giscus app](https://github.com/apps/giscus) installed in your repo by following their configuration setup at [https://giscus.app/](https://giscus.app/)
|
||||
|
||||
Once the above steps are completed, head over to [https://giscus.app](https://giscus.app/) and follow the steps there by filling out the fields to get your config values.
|
||||
|
||||
>[!important]
|
||||
> Make sure to choose `pathname` under page discussions mapping.
|
||||
|
||||
After filling out the fields, you will be provided with a script tag that contains your config values. Add them to your `.env` file, like so:
|
||||
|
||||
```
|
||||
NEXT_PUBLIC_GISCUS_REPO=
|
||||
NEXT_PUBLIC_GISCUS_REPOSITORY_ID=
|
||||
NEXT_PUBLIC_GISCUS_CATEGORY=
|
||||
NEXT_PUBLIC_GISCUS_CATEGORY_ID=
|
||||
```
|
||||
|
||||
When a user visits a web page, Giscus searches for a discussion whose title contains the page's pathname URL component. If there are no matches (i.e., no comments have been made about that page), then a new discussion is created for that page.
|
||||
|
||||
By using the pathname for mapping with a page, Giscus ensures that each discussion is unique to a particular page and that comments made on that page are kept together.
|
||||
|
||||
More info on how this connection is achieved can be found on their '**how it works**' section in their repo - [https://github.com/giscus/giscus#how-it-works](https://github.com/giscus/giscus#how-it-works) and also in the '**Page Discussions Mapping**' section at [https://giscus.app/](https://giscus.app/)
|
||||
|
||||
### Utterances
|
||||
|
||||
[Utterances](https://utteranc.es/) uses your github repo's issues to store comments for your pages and display them on your site. To setup comments with utterances, you would need to do the following:
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
1. You have a public [github repository](https://docs.github.com/en/get-started/quickstart/create-a-repo)
|
||||
2. The utterances app installed in your repo by following their configuration setup at [https://utteranc.es/](https://utteranc.es/)
|
||||
|
||||
Once installed fill in the required fields and you will see a script tag with your repo value which you can add to your `.env` file, like so:
|
||||
|
||||
```
|
||||
NEXT_PUBLIC_UTTERANCES_REPO=
|
||||
```
|
||||
|
||||
### Disqus
|
||||
|
||||
[Disqus](https://disqus.com/) is a feature rich provider which can be used to add comments to your site. You can configure flowershow to use disqus by creating an account on their site and following their process. You will be asked to enter a shortname for your site. Once completed, we can use this shortname in our comments configuration as below.
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
1. Create an account on [Disqus](https://disqus.com/) and follow their setup process.
|
||||
|
||||
You will be asked to enter a shortname for your site. Add it to your `.env` file as well, like so:
|
||||
|
||||
```
|
||||
NEXT_PUBLIC_DISQUS_SHORTNAME=
|
||||
```
|
||||
|
||||
## Add comments to your page layout
|
||||
|
||||
You can use `@flowershow/core` to import the comments section component. Install it with:
|
||||
|
||||
```sh
|
||||
npm i @flowershow/core
|
||||
```
|
||||
|
||||
Then, add the following to your custom layout (or directly to your pages):
|
||||
|
||||
```tsx
|
||||
import Navbar from './navbar';
|
||||
import Footer from './footer';
|
||||
|
||||
export default function Layout({ children }) {
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
<main>{children}</main>
|
||||
<div>
|
||||
<Comments commentsConfig={commentsConfig} slug={urlPath} />
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Add user comments
|
||||
|
||||
Learn how to add support for user comments in [[comments|this guide]].
|
||||
334
site/content/howto/drd.md
Normal file
334
site/content/howto/drd.md
Normal file
@@ -0,0 +1,334 @@
|
||||
# How to create data-rich documents with charts and tables?
|
||||
|
||||
> [!info] Prerequisites
|
||||
> If you want to enrich your markdown content with charts and tables, you first need to add support for rendering markdown files in your PortalJS app. Follow [[markdown|this guide]] to learn how to do this.
|
||||
|
||||
PortalJS comes with a library of components that provides essential pieces for your data portal. The best way to explore the components is to look at our [Storybook](https://storybook.portaljs.org/) that contains all the details on how to use them. Below is an overview of available components.
|
||||
|
||||
You can install the library with:
|
||||
|
||||
```sh
|
||||
npm i @portaljs/components
|
||||
```
|
||||
|
||||
Now, in order to use these components in your markdown files, we need to pass them to our `MDXRemote` component (see [[markdown#Import, parse and render your markdown files|this section in our markdown guide]]):
|
||||
|
||||
```tsx
|
||||
// e.g. /blog/[[...slug]].tsx
|
||||
import fs from "fs";
|
||||
import { LineChart, Table, Catalog, Vega, VegaLite } from "@portaljs/components";
|
||||
|
||||
import { MdxRemote } from "next-mdx-remote";
|
||||
import clientPromise from "@/lib/mddb.mjs";
|
||||
import parse from "@/lib/markdown";
|
||||
|
||||
const components = {
|
||||
Table: Table,
|
||||
Vega: Vega,
|
||||
VegaLite: VegaLite,
|
||||
LineChart: LineChart,
|
||||
};
|
||||
|
||||
|
||||
export default function Page({ source }) {
|
||||
source = JSON.parse(source);
|
||||
|
||||
return (
|
||||
<>
|
||||
<MdxRemote source={source} components={components} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Import metadata of a file matching the static path and return its parsed source and frontmatter object
|
||||
export const getStaticProps = async ({ params }) => {
|
||||
const urlPath = params?.slug ? (params.slug as string[]).join("/") : "/";
|
||||
|
||||
const mddb = await clientPromise;
|
||||
const dbFile = await mddb.getFileByUrl(urlPath);
|
||||
const filePath = dbFile!.file_path;
|
||||
// const frontMatter = dbFile!.metadata ?? {};
|
||||
|
||||
const source = fs.readFileSync(filePath, { encoding: "utf-8" });
|
||||
const { mdxSource } = await parse(source, "mdx", {});
|
||||
|
||||
return {
|
||||
props: {
|
||||
source: JSON.stringify(mdxSource),
|
||||
// frontMatter
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
You can now use these components in your markdown, like so:
|
||||
|
||||
```md
|
||||
### My Data Rich Note
|
||||
|
||||
Some markdown here.
|
||||
|
||||
<Table csv={`
|
||||
Year,Temp Anomaly
|
||||
1850,-0.418
|
||||
2020,0.923
|
||||
`} />
|
||||
|
||||
Some markdown here.
|
||||
```
|
||||
|
||||
## PortalJS components
|
||||
|
||||
### Table
|
||||
|
||||
An easy-to-use table component with built-in pagination, search, and sorting. It can be used with raw data, raw CSV strings or with URLs to hosted CSV files.
|
||||
|
||||
![[table-example.png]]
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
<Table
|
||||
cols={[
|
||||
{
|
||||
key: 'id',
|
||||
name: 'ID'
|
||||
},
|
||||
{
|
||||
key: 'firstName',
|
||||
name: 'First name'
|
||||
},
|
||||
{
|
||||
key: 'lastName',
|
||||
name: 'Last name'
|
||||
},
|
||||
{
|
||||
key: 'age',
|
||||
name: 'Age'
|
||||
}
|
||||
]}
|
||||
data={[
|
||||
{
|
||||
age: 35,
|
||||
firstName: 'Jon',
|
||||
id: 1,
|
||||
lastName: 'Snow'
|
||||
},
|
||||
{
|
||||
age: 42,
|
||||
firstName: 'Cersei',
|
||||
id: 2,
|
||||
lastName: 'Lannister'
|
||||
}
|
||||
]}
|
||||
/>
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> More info on the [storybook page](https://storybook.portaljs.org/?path=/docs/components-table--docs)
|
||||
|
||||
### Linechart
|
||||
|
||||
A simple component that allows the creation of an opinionated line chart without the need to go deep into charting standards. It can be used with raw data, raw CSV strings or with URLs to hosted CSV files.
|
||||
|
||||
![[linechart-example.png]]
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
<LineChart
|
||||
data={[
|
||||
[
|
||||
'1850',
|
||||
-0.41765878
|
||||
],
|
||||
[
|
||||
'1851',
|
||||
-0.2333498
|
||||
],
|
||||
[
|
||||
'1852',
|
||||
-0.22939907
|
||||
],
|
||||
[
|
||||
'1853',
|
||||
-0.27035445
|
||||
],
|
||||
[
|
||||
'1854',
|
||||
-0.29163003
|
||||
]
|
||||
]}
|
||||
/>
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> More info on the [storybook page](https://storybook.portaljs.org/?path=/docs/components-linechart--docs)
|
||||
|
||||
### Vega chart
|
||||
|
||||
A wrapper around the [Vega specification](https://vega.github.io/vega/) that allows you to build pretty much any kind of chart imaginable.
|
||||
|
||||
Example usage:
|
||||

|
||||
|
||||
```js
|
||||
<Vega
|
||||
data={{
|
||||
table: [
|
||||
{
|
||||
x: 1850,
|
||||
y: -0.418
|
||||
},
|
||||
{
|
||||
x: 2020,
|
||||
y: 0.923
|
||||
}
|
||||
]
|
||||
}}
|
||||
spec={{
|
||||
$schema: 'https://vega.github.io/schema/vega-lite/v4.json',
|
||||
data: {
|
||||
name: 'table'
|
||||
},
|
||||
encoding: {
|
||||
x: {
|
||||
field: 'x',
|
||||
type: 'ordinal'
|
||||
},
|
||||
y: {
|
||||
field: 'y',
|
||||
type: 'quantitative'
|
||||
}
|
||||
},
|
||||
mark: 'bar'
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
> [!info]
|
||||
> More info on the [storybook page](https://storybook.portaljs.org/?path=/docs/components-vega--docs)
|
||||
|
||||
### VegaLite chart
|
||||
|
||||
A wrapper around the [Vega Lite specification](https://vega.github.io/vega-lite/) which allows for a more concise grammar than Vega around the building of charts.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
<VegaLite
|
||||
data={{
|
||||
table: [
|
||||
{
|
||||
x: 1850,
|
||||
y: -0.418
|
||||
},
|
||||
{
|
||||
x: 2020,
|
||||
y: 0.923
|
||||
}
|
||||
]
|
||||
}}
|
||||
spec={{
|
||||
$schema: 'https://vega.github.io/schema/vega-lite/v4.json',
|
||||
data: {
|
||||
name: 'table'
|
||||
},
|
||||
encoding: {
|
||||
x: {
|
||||
field: 'x',
|
||||
type: 'ordinal'
|
||||
},
|
||||
y: {
|
||||
field: 'y',
|
||||
type: 'quantitative'
|
||||
}
|
||||
},
|
||||
mark: 'bar'
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> More info on the [storybook page](https://storybook.portaljs.org/?path=/docs/components-vegalite--docs)
|
||||
|
||||
### Catalog
|
||||
|
||||
A searchable catalog that will index a list of datasets and allow for contextual searching + filters.
|
||||
|
||||
![[catalog-example.png]]
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
<Catalog
|
||||
datasets={[
|
||||
{
|
||||
_id: '07026b22d49916754df1dc8ffb9ccd1c31878aae',
|
||||
metadata: {
|
||||
'details-of-task': 'Detect and categorise abusive language in social media data',
|
||||
language: 'Albanian',
|
||||
'level-of-annotation': [
|
||||
'Posts'
|
||||
],
|
||||
'link-to-data': 'https://doi.org/10.6084/m9.figshare.19333298.v1',
|
||||
'link-to-publication': 'https://arxiv.org/abs/2107.13592',
|
||||
medium: [
|
||||
'Text'
|
||||
],
|
||||
'percentage-abusive': 13.2,
|
||||
platform: [
|
||||
'Instagram',
|
||||
'Youtube'
|
||||
],
|
||||
reference: 'Nurce, E., Keci, J., Derczynski, L., 2021. Detecting Abusive Albanian. arXiv:2107.13592',
|
||||
'size-of-dataset': 11874,
|
||||
'task-description': 'Hierarchical (offensive/not; untargeted/targeted; person/group/other)',
|
||||
title: 'Detecting Abusive Albanian'
|
||||
},
|
||||
url_path: 'dataset-4'
|
||||
},
|
||||
]}
|
||||
/>
|
||||
```
|
||||
|
||||
You can also add facets that are going to act as filters for your metadata.
|
||||
|
||||
![[catalog-facets-example.png]]
|
||||
|
||||
```js
|
||||
<Catalog
|
||||
datasets={[
|
||||
{
|
||||
_id: '07026b22d49916754df1dc8ffb9ccd1c31878aae',
|
||||
metadata: {
|
||||
'details-of-task': 'Detect and categorise abusive language in social media data',
|
||||
language: 'Albanian',
|
||||
'level-of-annotation': [
|
||||
'Posts'
|
||||
],
|
||||
'link-to-data': 'https://doi.org/10.6084/m9.figshare.19333298.v1',
|
||||
'link-to-publication': 'https://arxiv.org/abs/2107.13592',
|
||||
medium: [
|
||||
'Text'
|
||||
],
|
||||
'percentage-abusive': 13.2,
|
||||
platform: [
|
||||
'Instagram',
|
||||
'Youtube'
|
||||
],
|
||||
reference: 'Nurce, E., Keci, J., Derczynski, L., 2021. Detecting Abusive Albanian. arXiv:2107.13592',
|
||||
'size-of-dataset': 11874,
|
||||
'task-description': 'Hierarchical (offensive/not; untargeted/targeted; person/group/other)',
|
||||
title: 'Detecting Abusive Albanian'
|
||||
},
|
||||
url_path: 'dataset-4'
|
||||
},
|
||||
]}
|
||||
facets={['platform', 'language']}
|
||||
/>
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> More info on the [storybook page](https://storybook.portaljs.org/?path=/docs/components-catalog--docs)
|
||||
12
site/content/howto/index.md
Normal file
12
site/content/howto/index.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Guides and tutorials
|
||||
|
||||
- [[howto/analytics|How to add web analytics?]]
|
||||
- [[howto/seo|How to customize page metadata for SEO?]]
|
||||
- [[howto/sitemap|How to build a sitemap?]]
|
||||
- [[howto/markdown|How to add markdown-based content pages?]]
|
||||
- [[howto/blog|How to add a simple blog?]]
|
||||
- [[howto/drd|How to create data-rich documents with charts and tables?]]
|
||||
- [[howto/comments|How to add user comments?]]
|
||||
|
||||
If you have questions about anything related to PortalJS, you're always welcome to ask our community on [GitHub Discussions](https://github.com/datopian/portaljs/discussions) or on [our chat channel on Discord](https://discord.gg/EeyfGrGu4U).
|
||||
|
||||
169
site/content/howto/markdown.md
Normal file
169
site/content/howto/markdown.md
Normal file
@@ -0,0 +1,169 @@
|
||||
# How to add markdown-based content pages?
|
||||
|
||||
## Add content layer to your app
|
||||
|
||||
Create a folder where you'll keep your markdown files and add some markdown files to it.
|
||||
|
||||
```sh
|
||||
cd my-portaljs-project
|
||||
mkdir content
|
||||
# touch content/index.md ...
|
||||
```
|
||||
|
||||
Install [MarkdownDB](https://github.com/datopian/markdowndb) package:
|
||||
|
||||
```
|
||||
npm i @flowershow/markdowndb
|
||||
```
|
||||
|
||||
And add the following to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"mddb": "mddb <path-to-your-content-folder>",
|
||||
"prebuild": "npm run mddb"
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
You can give it a go by running `npm run mddb`. You should see a `markdown.db` file created in the root of your project. You can inspect it with any SQLite viewer or in the command line. In the `files` table you should see all your markdown files from your content folder.
|
||||
|
||||
Now, once the data is in the database, you can add the following script to your project (e.g. in `/lib` folder). It will allow you to establish a single connection to the database and use it across your app.
|
||||
|
||||
```ts
|
||||
// lib/mddb.ts
|
||||
import { MarkdownDB } from "@flowershow/markdowndb";
|
||||
|
||||
// path to the markdown.db file created by the mddb script
|
||||
const dbPath = "markdown.db";
|
||||
|
||||
const client = new MarkdownDB({
|
||||
client: "sqlite3",
|
||||
connection: {
|
||||
filename: dbPath,
|
||||
},
|
||||
});
|
||||
|
||||
const clientPromise = client.init();
|
||||
|
||||
export default clientPromise;
|
||||
```
|
||||
|
||||
Now you can import it across your project to query the database, e.g.:
|
||||
|
||||
```ts
|
||||
import clientPromise from "@/lib/mddb";
|
||||
|
||||
const mddb = await clientPromise;
|
||||
const blogs = await mddb.getFiles({
|
||||
folder: "blog",
|
||||
extensions: ["md", "mdx"],
|
||||
});
|
||||
```
|
||||
|
||||
## Write a markdown parser
|
||||
|
||||
Install [next-mdx-remote](https://github.com/hashicorp/next-mdx-remote) package, which we'll first use to parse markdown files and then to render them in Next.js app.
|
||||
|
||||
```sh
|
||||
npm i next-mdx-remote
|
||||
```
|
||||
|
||||
Create the following basic parser for your markdown files, e.g. in `/lib/markdown.ts`:
|
||||
|
||||
```ts
|
||||
import matter from "gray-matter";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { serialize } from "next-mdx-remote/serialize";
|
||||
|
||||
|
||||
const parse = async function (source) {
|
||||
const { content } = matter(source);
|
||||
|
||||
const mdxSource = await serialize(
|
||||
{ value: content },
|
||||
{
|
||||
mdxOptions: {
|
||||
remarkPlugins: [
|
||||
remarkGfm,
|
||||
// ... your remark plugins
|
||||
],
|
||||
rehypePlugins: [
|
||||
// ... your plugins
|
||||
],
|
||||
format,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
mdxSource
|
||||
};
|
||||
};
|
||||
|
||||
export default parse;
|
||||
|
||||
```
|
||||
|
||||
## Import, parse and render your markdown files
|
||||
|
||||
Create a page in the `/pages` folder that will render your markdown content, e.g. `pages/blog/[[...slug]].tsx`:
|
||||
|
||||
```tsx
|
||||
import fs from "fs";
|
||||
|
||||
import { MdxRemote } from "next-mdx-remote";
|
||||
import clientPromise from "@/lib/mddb.mjs";
|
||||
import parse from "@/lib/markdown";
|
||||
|
||||
|
||||
export default function Page({ source }) {
|
||||
source = JSON.parse(source);
|
||||
|
||||
return (
|
||||
<>
|
||||
<MdxRemote source={source} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Import metadata of a file matching the static path and return its parsed source and frontmatter object
|
||||
export const getStaticProps = async ({ params }) => {
|
||||
const urlPath = params?.slug ? (params.slug as string[]).join("/") : "/";
|
||||
|
||||
const mddb = await clientPromise;
|
||||
const dbFile = await mddb.getFileByUrl(urlPath);
|
||||
const filePath = dbFile!.file_path;
|
||||
// const frontMatter = dbFile!.metadata ?? {};
|
||||
|
||||
const source = fs.readFileSync(filePath, { encoding: "utf-8" });
|
||||
const { mdxSource } = await parse(source, "mdx", {});
|
||||
|
||||
return {
|
||||
props: {
|
||||
source: JSON.stringify(mdxSource),
|
||||
// frontMatter
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Import metadata of your markdown files from MarkdownDB and return a list of static paths
|
||||
export const getStaticPaths = async () => {
|
||||
const mddb = await clientPromise;
|
||||
const allDocuments = await mddb.getFiles({ extensions: ["md", "mdx"] });
|
||||
const paths = allDocuments
|
||||
.map((page) => {
|
||||
const url = decodeURI(page.url_path);
|
||||
const parts = url.split("/");
|
||||
return { params: { slug: parts } };
|
||||
});
|
||||
|
||||
return {
|
||||
paths,
|
||||
fallback: false,
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
79
site/content/howto/seo.md
Normal file
79
site/content/howto/seo.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# How to customize page metadata for SEO?
|
||||
|
||||
>[!info]
|
||||
>See [`next-seo` documentation](https://github.com/garmeeh/next-seo) to learn more.
|
||||
|
||||
## Setup
|
||||
|
||||
Install `next-seo` package:
|
||||
|
||||
```sh
|
||||
npm i next-seo
|
||||
```
|
||||
|
||||
## Default SEO configuration
|
||||
|
||||
Create `next-seo.config` file (e.g. in the root of your project) and add default meta tags values you want to be set up for your pages. For example:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
openGraph: {
|
||||
type: 'website',
|
||||
locale: 'en_IE',
|
||||
url: 'https://www.my.portaljs.app/',
|
||||
siteName: 'MyPortalJSApp',
|
||||
},
|
||||
twitter: {
|
||||
handle: '@handle',
|
||||
site: '@site',
|
||||
cardType: 'summary_large_image',
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Then, in your custom Next.js App, add the following:
|
||||
|
||||
```tsx
|
||||
// /pages/_app.tsx
|
||||
import { DefaultSeo } from "next-seo";
|
||||
|
||||
// import your default seo configuration
|
||||
import SEO from '../next-seo.config';
|
||||
|
||||
|
||||
export default function MyApp({ Component, pageProps }) {
|
||||
// ... your code
|
||||
return (
|
||||
<>
|
||||
<DefaultSeo {...SEO} />
|
||||
<Component {...pageProps} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
>[!info]
|
||||
>To learn more on default SEO configuration with `next-seo`, see [this docs section](https://github.com/garmeeh/next-seo#default-seo-configuration).
|
||||
|
||||
## Per-page SEO configuration
|
||||
|
||||
To add page specific meta tag values:
|
||||
|
||||
```tsx
|
||||
import { NextSeo } from 'next-seo';
|
||||
|
||||
export default function Page() (
|
||||
// ...
|
||||
<>
|
||||
<NextSeo
|
||||
title="My Portal JS page"
|
||||
description="A short description."
|
||||
/>
|
||||
<p>My Portal JS page</p>
|
||||
</>
|
||||
);
|
||||
```
|
||||
|
||||
>[!info]
|
||||
> To learn more on per-page SEO configuration with `next-seo`, see [this docs section](https://github.com/garmeeh/next-seo#add-seo-to-page)
|
||||
94
site/content/howto/sitemap.md
Normal file
94
site/content/howto/sitemap.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# How to build a sitemap?
|
||||
|
||||
## Setup
|
||||
|
||||
Install the following packages:
|
||||
|
||||
```sh
|
||||
npm i globby
|
||||
npm i -D prettier
|
||||
```
|
||||
|
||||
## Add sitemap script
|
||||
|
||||
>[!info]
|
||||
>The following example assumes files list for dynamic Next.js routes is imported from the database created with [MarkdownDB](https://github.com/datopian/markdowndb) package. You need to adjust it to your specific use case.
|
||||
|
||||
Add the following script to e.g. `/scripts/sitemap.mjs` and adjust it to work with your app:
|
||||
|
||||
```js
|
||||
// /scripts/sitemap.mjs
|
||||
import { writeFileSync } from "fs";
|
||||
import { globby } from "globby";
|
||||
import prettier from "prettier";
|
||||
|
||||
// Change this to import data from your content layer (if needed)
|
||||
import clientPromise from "../lib/mddb.mjs";
|
||||
|
||||
export default async function sitemap() {
|
||||
const prettierConfig = await prettier.resolveConfig("path-to-your-prettier-config");
|
||||
|
||||
// Change this to create a list of page paths
|
||||
const mddb = await clientPromise;
|
||||
const allFiles = await mddb.getFiles({ extensions: ["mdx", "md"] });
|
||||
const contentPages = allFiles
|
||||
.filter((x) => !x.metadata?.isDraft)
|
||||
.map((x) => `/${x.url_path}`);
|
||||
const pages = await globby([
|
||||
"pages/*.(js|tsx)",
|
||||
"!pages/_*.(js|tsx)",
|
||||
"!pages/api",
|
||||
"!pages/404.(js|tsx)",
|
||||
"!pages/**/\\[\\[*\\]\\].(js|tsx)", // pages/[[...slug]].tsx
|
||||
]);
|
||||
const allPages = pages.concat(contentPages);
|
||||
// end
|
||||
|
||||
// Replace this with your site domain
|
||||
const siteDomain = "your-site-domain";
|
||||
|
||||
const sitemap = `
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${allPages
|
||||
.map((page) => {
|
||||
const path = page
|
||||
.replace("pages/", "/")
|
||||
.replace("public/", "/")
|
||||
.replace(/\.js|.tsx|.mdx|.md[^\/.]+$/, "")
|
||||
.replace("/feed.xml", "");
|
||||
const route = path === "/index" ? "" : path;
|
||||
return `
|
||||
<url>
|
||||
<loc>${siteDomain}${route}</loc>
|
||||
</url>
|
||||
`;
|
||||
})
|
||||
.join("")}
|
||||
</urlset>
|
||||
`;
|
||||
|
||||
const formatted = prettier.format(sitemap, {
|
||||
...prettierConfig,
|
||||
parser: "html",
|
||||
});
|
||||
|
||||
if (siteUrl) {
|
||||
writeFileSync("public/sitemap.xml", formatted);
|
||||
console.log("Sitemap generated...");
|
||||
}
|
||||
}
|
||||
|
||||
await sitemap();
|
||||
process.exit();
|
||||
```
|
||||
|
||||
## Execute script before each build
|
||||
|
||||
Add this to the scripts section in your `package.json` to regenerate the sitemap before each build.
|
||||
|
||||
```json
|
||||
|
||||
"prebuild": "node ./scripts/sitemap.mjs",
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user