first article

This commit is contained in:
Johannes
2023-08-11 08:52:26 +02:00
parent b96fbf06d9
commit 2815ab2175
4 changed files with 153 additions and 56 deletions
+1
View File
@@ -28,6 +28,7 @@
"next": "13.4.12",
"next-plausible": "^3.10.1",
"next-sitemap": "^4.1.8",
"node-fetch": "^3.3.2",
"prism-react-renderer": "^2.0.6",
"prismjs": "^1.29.0",
"react": "18.2.0",
+68 -15
View File
@@ -1,35 +1,88 @@
export async function getStaticPaths() {
const response = await fetch("http://localhost:1337/api/learn-articles?populate=");
const articles = await response.json();
import fetch from 'node-fetch';
import MetaInformation from "../../components/shared/MetaInformation";
if (!Array.isArray(articles.data)) {
console.error("Expected articles.data to be an array but got:", articles.data);
return { paths: [], fallback: true };
type ArticleAttributes = {
createdAt: string;
updatedAt: string;
publishedAt: string;
Article: {
id: number;
slug: string;
author: string;
};
Metadata?: {
metaTitle: string;
metaDescription: string;
metaSection: string;
tag1: string;
tag2: string;
tag3: string;
};
};
type Article = {
id: number;
attributes: ArticleAttributes;
};
type APIResponse = {
data: Article[];
};
export async function getStaticPaths() {
const response = await fetch("http://127.0.0.1:1337/api/learn-articles?populate=*");
const articles: APIResponse = await response.json();
console.log(response);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
console.log("articles.data", JSON.stringify(articles.data, null, 2));
console.log("articles", articles);
const paths = articles.data.map((article) => ({
params: { slug: article.attributes.slug },
params: { slug: article.attributes.Article.slug },
}));
return { paths, fallback: true };
}
export async function getStaticProps({ params }) {
const article = await fetch(`http://localhost:1337/api/learn-articles?slug=${params.slug}`)
.then((response) => response.json())
.then((data) => data[0]);
const res = await fetch(`http://127.0.0.1:1337/api/learn-articles?populate=*`);
if (!res.ok) {
throw new Error("Something went wrong");
}
const resData: APIResponse = await res.json();
const articles = resData.data;
// find article by slug attribute
const article = articles.find((a) => a.attributes.Article.slug === params.slug);
console.log("article", article);
return { props: { article } };
}
export default function ArticlePage({ article }) {
if (!article) return <div>Loading...</div>; // Render a loading state if data hasn't been fetched yet
if (!article) return <div>Loading...</div>;
return (
<div>
<h1>{article.title}</h1>
<p>By {article.author}</p>
{/* Render the rest of the article data here */}
<MetaInformation
title={article.attributes.Metadata.metaTitle}
description={article.attributes.Metadata.metaDescription}
publishedTime={article.attributes.publishedAt}
authors={undefined}
section={article.attributes.Metadata.metaSection}
tags={[
article.attributes.Metadata.tag1,
article.attributes.Metadata.tag2,
article.attributes.Metadata.tag3,
article.attributes.Metadata.tag3,
article.attributes.Metadata.tag3,
]}
/>
<pre>{JSON.stringify(article, null, 2)}</pre>
</div>
);
}
+1 -12
View File
@@ -1,3 +1,4 @@
import fetch from 'node-fetch';
import MetaInformation from "../../components/shared/MetaInformation";
export async function getStaticPaths() {
@@ -22,22 +23,10 @@ export async function getStaticProps({ params }) {
const resData = await res.json();
const articles = resData.data;
// find article by slug attribute
console.log("articles", articles);
const article = articles.find((a) => a.attributes.article[0].slug === params.slug);
return { props: { article } };
}
export const meta = {
title: "5 Open Source Survey and Form Tools maintained in 2023",
description:
"Most open source projects get abandoned after a while. But these 5 open source survey tools are still alive and kicking in 2023.",
date: "2023-04-12",
publishedTime: "2023-04-12T12:00:00",
authors: ["Johannes"],
section: "Open Source Surveys",
tags: ["Open Source Surveys", "Formbricks", "Typeform", "SurveyJS", "Typebot", "OpnForm", "LimeSurvey"],
};
export default function ArticlePage({ article }) {
if (!article) return <div>Loading...</div>; // Render a loading state if data hasn't been fetched yet
+83 -29
View File
@@ -1,4 +1,4 @@
lockfileVersion: '6.1'
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
@@ -19,7 +19,7 @@ importers:
version: 3.12.7
turbo:
specifier: latest
version: 1.10.3
version: 1.10.12
apps/demo:
dependencies:
@@ -96,6 +96,9 @@ importers:
next-sitemap:
specifier: ^4.1.8
version: 4.1.8(next@13.4.12)
node-fetch:
specifier: ^3.3.2
version: 3.3.2
prism-react-renderer:
specifier: ^2.0.6
version: 2.0.6(react@18.2.0)
@@ -352,7 +355,7 @@ importers:
version: 8.10.0(eslint@8.46.0)
eslint-config-turbo:
specifier: latest
version: 1.10.3(eslint@8.46.0)
version: 1.10.12(eslint@8.46.0)
eslint-plugin-react:
specifier: 7.33.1
version: 7.33.1(eslint@8.46.0)
@@ -6617,6 +6620,7 @@ packages:
/anymatch@2.0.0:
resolution: {integrity: sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw==}
requiresBuild: true
dependencies:
micromatch: 3.1.10
normalize-path: 2.1.1
@@ -6835,6 +6839,7 @@ packages:
/async-each@1.0.3:
resolution: {integrity: sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==}
requiresBuild: true
dev: true
optional: true
@@ -7154,6 +7159,7 @@ packages:
/binary-extensions@1.13.1:
resolution: {integrity: sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==}
engines: {node: '>=0.10.0'}
requiresBuild: true
dev: true
optional: true
@@ -7754,6 +7760,7 @@ packages:
/chokidar@2.1.8:
resolution: {integrity: sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg==}
deprecated: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
requiresBuild: true
dependencies:
anymatch: 2.0.0
async-each: 1.0.3
@@ -8852,6 +8859,11 @@ packages:
assert-plus: 1.0.0
dev: true
/data-uri-to-buffer@4.0.1:
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
engines: {node: '>= 12'}
dev: false
/data-urls@1.1.0:
resolution: {integrity: sha512-YTWYI9se1P55u58gL5GkQHW4P6VJBJ5iBT+B5a7i2Tjadhv52paJG0qHX4A0OR6/t52odI64KP2YvFpkDOi3eQ==}
dependencies:
@@ -9837,13 +9849,13 @@ packages:
eslint: 8.46.0
dev: true
/eslint-config-turbo@1.10.3(eslint@8.46.0):
resolution: {integrity: sha512-ggzPfTJfMsMS383oZ4zfTP1zQvyMyiigOQJRUnLt1nqII6SKkTzdKZdwmXRDHU24KFwUfEFtT6c8vnm2VhL0uQ==}
/eslint-config-turbo@1.10.12(eslint@8.46.0):
resolution: {integrity: sha512-z3jfh+D7UGYlzMWGh+Kqz++hf8LOE96q3o5R8X4HTjmxaBWlLAWG+0Ounr38h+JLR2TJno0hU9zfzoPNkR9BdA==}
peerDependencies:
eslint: '>6.6.0'
dependencies:
eslint: 8.46.0
eslint-plugin-turbo: 1.10.3(eslint@8.46.0)
eslint-plugin-turbo: 1.10.12(eslint@8.46.0)
dev: true
/eslint-import-resolver-node@0.3.6:
@@ -10031,11 +10043,12 @@ packages:
semver: 6.3.1
string.prototype.matchall: 4.0.8
/eslint-plugin-turbo@1.10.3(eslint@8.46.0):
resolution: {integrity: sha512-g3Mnnk7el1FqxHfqbE/MayLvCsYjA/vKmAnUj66kV4AlM7p/EZqdt42NMcMSKtDVEm0w+utQkkzWG2Xsa0Pd/g==}
/eslint-plugin-turbo@1.10.12(eslint@8.46.0):
resolution: {integrity: sha512-uNbdj+ohZaYo4tFJ6dStRXu2FZigwulR1b3URPXe0Q8YaE7thuekKNP+54CHtZPH9Zey9dmDx5btAQl9mfzGOw==}
peerDependencies:
eslint: '>6.6.0'
dependencies:
dotenv: 16.0.3
eslint: 8.46.0
dev: true
@@ -10457,6 +10470,14 @@ packages:
bser: 2.1.1
dev: true
/fetch-blob@3.2.0:
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
engines: {node: ^12.20 || >= 14.13}
dependencies:
node-domexception: 1.0.0
web-streams-polyfill: 3.2.1
dev: false
/fflate@0.4.8:
resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==}
dev: false
@@ -10678,6 +10699,13 @@ packages:
combined-stream: 1.0.8
mime-types: 2.1.35
/formdata-polyfill@4.0.10:
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
engines: {node: '>=12.20.0'}
dependencies:
fetch-blob: 3.2.0
dev: false
/forwarded@0.2.0:
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
engines: {node: '>= 0.6'}
@@ -10938,6 +10966,7 @@ packages:
/glob-parent@3.1.0:
resolution: {integrity: sha512-E8Ak/2+dZY6fnzlR7+ueWvhsH1SjHr4jjss4YS/h4py44jY9MhK/VFdaZJAWDz6BbL21KeteKxFSFpq8OS5gVA==}
requiresBuild: true
dependencies:
is-glob: 3.1.0
path-dirname: 1.0.2
@@ -11801,6 +11830,7 @@ packages:
/is-binary-path@1.0.1:
resolution: {integrity: sha512-9fRVlXc0uCxEDj1nQzaWONSpbTfx0FmJfzHF7pwlI8DkWGoHBBea4Pg5Ky0ojwwxQmnSifgbKkI06Qv0Ljgj+Q==}
engines: {node: '>=0.10.0'}
requiresBuild: true
dependencies:
binary-extensions: 1.13.1
dev: true
@@ -11956,6 +11986,7 @@ packages:
/is-glob@3.1.0:
resolution: {integrity: sha512-UFpDDrPgM6qpnFNI+rh/p3bUaq9hKLZN8bMUWzxmcnZVS3omf4IPK+BrewlnWjO1WmUsMYuSjKh4UJuV4+Lqmw==}
engines: {node: '>=0.10.0'}
requiresBuild: true
dependencies:
is-extglob: 2.1.1
dev: true
@@ -12219,7 +12250,7 @@ packages:
/isomorphic-fetch@3.0.0:
resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==}
dependencies:
node-fetch: 2.6.7
node-fetch: 2.6.12
whatwg-fetch: 3.6.2
transitivePeerDependencies:
- encoding
@@ -14765,6 +14796,11 @@ packages:
resolution: {integrity: sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA==}
dev: false
/node-domexception@1.0.0:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'}
dev: false
/node-fetch@2.6.12:
resolution: {integrity: sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==}
engines: {node: 4.x || >=6.0.0}
@@ -14788,6 +14824,15 @@ packages:
whatwg-url: 5.0.0
dev: true
/node-fetch@3.3.2:
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
data-uri-to-buffer: 4.0.1
fetch-blob: 3.2.0
formdata-polyfill: 4.0.10
dev: false
/node-forge@1.3.1:
resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==}
engines: {node: '>= 6.13.0'}
@@ -14849,6 +14894,7 @@ packages:
/normalize-path@2.1.1:
resolution: {integrity: sha512-3pKJwH184Xo/lnH6oyP1q2pMd7HcypqqmRs91/6/i2CGtWwIKGCkOOMTm/zXbgTEWHw1uNpNi/igc3ePOYHb6w==}
engines: {node: '>=0.10.0'}
requiresBuild: true
dependencies:
remove-trailing-separator: 1.1.0
dev: true
@@ -15396,6 +15442,7 @@ packages:
/path-dirname@1.0.2:
resolution: {integrity: sha512-ALzNPpyNq9AqXMBjeymIjFDAkAFH06mHJH/cSBHAgU0s4vfpBn6b2nf8tiRLvagKD8RbTpq2FKTBg7cl9l3c7Q==}
requiresBuild: true
dev: true
optional: true
@@ -17553,6 +17600,7 @@ packages:
/readdirp@2.2.1:
resolution: {integrity: sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==}
engines: {node: '>=0.10'}
requiresBuild: true
dependencies:
graceful-fs: 4.2.10
micromatch: 3.1.10
@@ -17731,6 +17779,7 @@ packages:
/remove-trailing-separator@1.1.0:
resolution: {integrity: sha512-/hS+Y0u3aOfIETiaiirUFwDBDzmXPvO+jAfKTitUngIPzdKc6Z0LoFjM/CK5PL4C+eKwHohlHAb6H0VFfmmUsw==}
requiresBuild: true
dev: true
optional: true
@@ -19810,65 +19859,65 @@ packages:
dependencies:
safe-buffer: 5.2.1
/turbo-darwin-64@1.10.3:
resolution: {integrity: sha512-IIB9IomJGyD3EdpSscm7Ip1xVWtYb7D0x7oH3vad3gjFcjHJzDz9xZ/iw/qItFEW+wGFcLSRPd+1BNnuLM8AsA==}
/turbo-darwin-64@1.10.12:
resolution: {integrity: sha512-vmDfGVPl5/aFenAbOj3eOx3ePNcWVUyZwYr7taRl0ZBbmv2TzjRiFotO4vrKCiTVnbqjQqAFQWY2ugbqCI1kOQ==}
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/turbo-darwin-arm64@1.10.3:
resolution: {integrity: sha512-SBNmOZU9YEB0eyNIxeeQ+Wi0Ufd+nprEVp41rgUSRXEIpXjsDjyBnKnF+sQQj3+FLb4yyi/yZQckB+55qXWEsw==}
/turbo-darwin-arm64@1.10.12:
resolution: {integrity: sha512-3JliEESLNX2s7g54SOBqqkqJ7UhcOGkS0ywMr5SNuvF6kWVTbuUq7uBU/sVbGq8RwvK1ONlhPvJne5MUqBCTCQ==}
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/turbo-linux-64@1.10.3:
resolution: {integrity: sha512-kvAisGKE7xHJdyMxZLvg53zvHxjqPK1UVj4757PQqtx9dnjYHSc8epmivE6niPgDHon5YqImzArCjVZJYpIGHQ==}
/turbo-linux-64@1.10.12:
resolution: {integrity: sha512-siYhgeX0DidIfHSgCR95b8xPee9enKSOjCzx7EjTLmPqPaCiVebRYvbOIYdQWRqiaKh9yfhUtFmtMOMScUf1gg==}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/turbo-linux-arm64@1.10.3:
resolution: {integrity: sha512-Qgaqln0IYRgyL0SowJOi+PNxejv1I2xhzXOI+D+z4YHbgSx87ox1IsALYBlK8VRVYY8VCXl+PN12r1ioV09j7A==}
/turbo-linux-arm64@1.10.12:
resolution: {integrity: sha512-K/ZhvD9l4SslclaMkTiIrnfcACgos79YcAo4kwc8bnMQaKuUeRpM15sxLpZp3xDjDg8EY93vsKyjaOhdFG2UbA==}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/turbo-windows-64@1.10.3:
resolution: {integrity: sha512-rbH9wManURNN8mBnN/ZdkpUuTvyVVEMiUwFUX4GVE5qmV15iHtZfDLUSGGCP2UFBazHcpNHG1OJzgc55GFFrUw==}
/turbo-windows-64@1.10.12:
resolution: {integrity: sha512-7FSgSwvktWDNOqV65l9AbZwcoueAILeE4L7JvjauNASAjjbuzXGCEq5uN8AQU3U5BOFj4TdXrVmO2dX+lLu8Zg==}
cpu: [x64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/turbo-windows-arm64@1.10.3:
resolution: {integrity: sha512-ThlkqxhcGZX39CaTjsHqJnqVe+WImjX13pmjnpChz6q5HHbeRxaJSFzgrHIOt0sUUVx90W/WrNRyoIt/aafniw==}
/turbo-windows-arm64@1.10.12:
resolution: {integrity: sha512-gCNXF52dwom1HLY9ry/cneBPOKTBHhzpqhMylcyvJP0vp9zeMQQkt6yjYv+6QdnmELC92CtKNp2FsNZo+z0pyw==}
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/turbo@1.10.3:
resolution: {integrity: sha512-U4gKCWcKgLcCjQd4Pl8KJdfEKumpyWbzRu75A6FCj6Ctea1PIm58W6Ltw1QXKqHrl2pF9e1raAskf/h6dlrPCA==}
/turbo@1.10.12:
resolution: {integrity: sha512-WM3+jTfQWnB9W208pmP4oeehZcC6JQNlydb/ZHMRrhmQa+htGhWLCzd6Q9rLe0MwZLPpSPFV2/bN5egCLyoKjQ==}
hasBin: true
requiresBuild: true
optionalDependencies:
turbo-darwin-64: 1.10.3
turbo-darwin-arm64: 1.10.3
turbo-linux-64: 1.10.3
turbo-linux-arm64: 1.10.3
turbo-windows-64: 1.10.3
turbo-windows-arm64: 1.10.3
turbo-darwin-64: 1.10.12
turbo-darwin-arm64: 1.10.12
turbo-linux-64: 1.10.12
turbo-linux-arm64: 1.10.12
turbo-windows-64: 1.10.12
turbo-windows-arm64: 1.10.12
dev: true
/tween-functions@1.2.0:
@@ -20588,6 +20637,11 @@ packages:
defaults: 1.0.4
dev: true
/web-streams-polyfill@3.2.1:
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
engines: {node: '>= 8'}
dev: false
/webidl-conversions@3.0.1:
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}