This commit is contained in:
Benjamin Toby 2024-10-01 16:17:51 +01:00
parent a6a3b8056d
commit a3732103bf
3 changed files with 69 additions and 62 deletions

View File

@ -1,5 +1,5 @@
# Set Node.js version
FROM node:bookworm
FROM node:alpine
RUN mkdir /app
@ -8,8 +8,8 @@ WORKDIR /app
# Copy package.json and package-lock.json
RUN apt update
RUN apt install nano -y
RUN apk update
RUN apk add nano
RUN touch /root/.bashrc
RUN echo 'alias ll="ls -laF"' > /root/.bashrc

View File

@ -56,20 +56,24 @@ export default async function BlogIndex({
}: {
params: any;
}) {
//* Data fetching
const post = await getPost({ single: single });
try {
//* Data fetching
const post = await getPost({ single: single });
if (!post) {
if (!post) {
return redirect("/blog");
}
//* Main Function Return
/////////////////////////////////////////////
return (
<React.Fragment>
<Main post={post} />
</React.Fragment>
);
/** ********************************************** */
} catch (error) {
return redirect("/blog");
}
//* Main Function Return
/////////////////////////////////////////////
return (
<React.Fragment>
<Main post={post} />
</React.Fragment>
);
/** ********************************************** */
}

View File

@ -4,8 +4,7 @@
import React from "react";
import { Metadata } from "next";
const datasquirel = require("datasquirel");
import { headers, cookies } from "next/headers";
import { redirect } from "next/navigation";
/////////////////////////////////////////////
//* Metadata
@ -26,52 +25,56 @@ export const revalidate = 3600;
* ==============================================================================
*/
export default async function BlogIndex() {
//* Data fetching
/////////////////////////////////////////////
const postsResponse = await datasquirel.get({
key: process.env.DATASQUIREL_API_KEY,
db: process.env.DB_NAME,
query: "select title,slug,excerpt,date_created from blog_posts limit 10",
});
try {
//* Data fetching
/////////////////////////////////////////////
const postsResponse = await datasquirel.get({
key: process.env.DATASQUIREL_API_KEY,
db: process.env.DB_NAME,
query: "select title,slug,excerpt,date_created from blog_posts limit 10",
});
const posts = postsResponse?.success ? postsResponse.payload : [];
const posts = postsResponse?.success ? postsResponse.payload : [];
//* Main Function Return
/////////////////////////////////////////////
return (
<React.Fragment>
<div className="flex flex-col items-start max-w-6xl w-full">
<h1 className="mb-8">My Blog</h1>
<div className="flex flex-col items-start w-full gap-4">
{posts.map(
(
post: {
slug: string;
title: string;
excerpt: string;
date_created: string;
},
index: number
) => (
<a
key={index}
href={`/blog/${post.slug}`}
className="flex flex-col items-start gap-2 w-full hover:bg-blue-600 border border-solid border-white/20 p-8 transition-all bg-primary/10"
>
<h2 className="m-0">{post.title}</h2>
<span className="opacity-80">
{post.excerpt}
</span>
<span className="text-sm opacity-50">
{post.date_created.substring(0, 24)}
</span>
</a>
)
)}
//* Main Function Return
/////////////////////////////////////////////
return (
<React.Fragment>
<div className="flex flex-col items-start max-w-6xl w-full">
<h1 className="mb-8">My Blog</h1>
<div className="flex flex-col items-start w-full gap-4">
{posts.map(
(
post: {
slug: string;
title: string;
excerpt: string;
date_created: string;
},
index: number
) => (
<a
key={index}
href={`/blog/${post.slug}`}
className="flex flex-col items-start gap-2 w-full hover:bg-blue-600 border border-solid border-white/20 p-8 transition-all bg-primary/10"
>
<h2 className="m-0">{post.title}</h2>
<span className="opacity-80">
{post.excerpt}
</span>
<span className="text-sm opacity-50">
{post.date_created.substring(0, 24)}
</span>
</a>
)
)}
</div>
</div>
</div>
</React.Fragment>
);
</React.Fragment>
);
/** ********************************************** */
/** ********************************************** */
} catch (error) {
return redirect("/");
}
}