metadata added to pages

This commit is contained in:
parsa aghaei committed 2024-10-19 14:02:39 +03:30
1 parent 013f49be1e
commit bd1dbe42f9
12 files changed
+214 -213

No files matched your search

@@ -3,7 +3,7 @@
import { setCookie } from "cookies-next";
import { LocaleCookieType } from "@/app/types/types";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useState } from "react";
interface SelectLanguageProps {
selectedLocale: LocaleCookieType | undefined;
+12 -2
View File
@@ -3,8 +3,18 @@ import Header from "./components/header/header";
import Footer from "./components/footer/footer";
export const metadata: Metadata = {
title: "parsa aghayi",
title: {
template: "%s | parsa aghayi",
default: "parsa aghayi",
},
description: "parsa aghayi personal website",
openGraph: {
title: {
template: "%s | parsa aghayi",
default: "parsa aghayi",
},
description: "parsa aghayi personal website",
},
};
export default function RootLayout({
@@ -24,7 +34,7 @@ export default function RootLayout({
<div className="absolute start-0 top-0 opacity-0" id="here-is-top"></div>
<a
href="/#here-is-top"
className="pt-10 scroll-to-top fixed end-5 flex h-[50px] w-[50px] items-center justify-center rounded-full border-2 bg-[#fd6f00] p-5 text-center text-[25px] font-[800] text-white hover:border-[#f3a66b] sm:bottom-[100px] sm:end-10"
className="scroll-to-top fixed end-5 flex h-[50px] w-[50px] items-center justify-center rounded-full border-2 bg-[#fd6f00] p-5 pt-10 text-center text-[25px] font-[800] text-white hover:border-[#f3a66b] sm:bottom-[100px] sm:end-10"
id="back-to-top"
>
^
+13
View File
@@ -6,6 +6,19 @@ import Services from "./components/services/services";
import MyProjects from "./components/projects/projects";
import { getDictionary } from "@/app/lib/functions/dictionaries";
import { getDefaultLocale } from "@/app/lib/functions/utils";
import { Metadata } from "next";
export const metadata: Metadata = {
title: "parsa aghayi's personal website",
description:
"Hi, I am parsa aghayi. Frontend & Backend Developer and here is my personal website to know me and contact me if you want! ;)",
openGraph: {
title: "parsa aghayi's personal website openGraph title",
description:
"Hi, I am parsa aghayi. Frontend & Backend Developer and here is my personal website to know me and contact me if you want! ;) openGraph description",
images: ["/images/profile.png"],
},
};
export default async function Home() {
const dict = await getDictionary(getDefaultLocale());
+9 -1
View File
@@ -1,4 +1,12 @@
import React from "react";
import { Metadata } from "next";
export const metadata: Metadata = {
title: "projects",
openGraph: {
title: "parsa aghayi personal website openGraph projects page title",
description: "parsa aghayi personal website openGraph projects description",
},
};
export default function Projects() {
return <div>Projects</div>;
@@ -1,35 +1,73 @@
import { CategoryDataType, categorySlugPropsType } from "@/app/types/types";
import { Metadata } from "next";
import Image from "next/image";
import Link from "next/link";
import { redirect } from "next/navigation";
import NoDataFounded from "../../components/no-data-founded/noDataFounded";
import Pagination from "../../components/pagination/pagination";
async function fetchCategoryData(
categorySlug: string,
searchParams: URLSearchParams,
): Promise<CategoryDataType> {
const res = await fetch(
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories/${categorySlug}/posts?per_page=${searchParams.get("per_page") || process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.get("page") ? `&page=${searchParams.get("page")}` : ""}`,
);
if (res.status === 404) {
redirect("/blog/404");
}
return res.json();
}
export async function generateMetadata({
params,
}: categorySlugPropsType): Promise<Metadata> {
const categoryData: CategoryDataType = await fetchCategoryData(
params.categorySlug,
new URLSearchParams(),
);
return {
title: categoryData.category.name,
description: categoryData.category.short_description,
openGraph: {
title: categoryData.category.name,
description: categoryData.category.short_description,
images: [categoryData.category.image],
},
};
}
export default async function SingleCategory({
params,
searchParams,
}: categorySlugPropsType) {
const categoryData: CategoryDataType = await fetch(
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories/${params.categorySlug}/posts?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
{
cache: "no-store",
},
).then((res) => {
if (res.status == 404) {
redirect("/blog/404");
}
return res.json();
});
const categoryData: CategoryDataType = await fetchCategoryData(
params.categorySlug,
new URLSearchParams(searchParams as Record<string, string>),
);
return (
<div className="flex w-full max-w-[1280px] flex-wrap justify-center sm:my-10">
<div className="flex w-full max-w-[90%] flex-col gap-5">
<div className="mt-5 flex w-full max-w-[90%] flex-col gap-5">
<h1 className="text-[36px] font-[700] capitalize text-blog-text-default">
{params.categorySlug.replaceAll(/%20|-|_/g, " ")}
</h1>
<p className="text-[18px] font-[600] text-blog-text-default">
{categoryData.category.description}
</p>
<div className="flex w-full flex-wrap gap-2">
<div className="flex gap-2">
<p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]">
Total Posts:
</p>
<span className="text-[14px] font-[400] text-blog-text-default md:text-[16px]">
{categoryData.meta.total}
</span>
</div>
</div>
</div>
<div className="my-10 flex w-full max-w-[90%] flex-wrap justify-center gap-5">
<ul className="my-10 flex w-full flex-wrap gap-2">
@@ -49,18 +87,15 @@ export default async function SingleCategory({
href={"/blog/categories"}
className="text-[12px] font-[400] capitalize text-blog-text-passive hover:underline"
>
categories
Categories
</Link>
<span className="mt-[-2px] -rotate-45 scale-[3] select-none text-[12px] font-[400] text-blog-text-passive">
-
</span>
</li>
<li className="flex items-center gap-2">
<p className="relative text-[12px] font-[600] capitalize text-blog-text-default">
<p className="text-[12px] font-[600] capitalize text-blog-text-default">
{categoryData.category.name}
<span className="absolute -end-5 -top-2 flex h-5 w-5 items-center justify-center rounded-full bg-blog-red">
{categoryData.meta.total}
</span>
</p>
</li>
</ul>
@@ -92,17 +127,6 @@ export default async function SingleCategory({
{post.author.name}
</Link>
</div>
{/* <div className="whit flex gap-2">
<p className="text-[16px] font-[600] text-blog-text-passive">
IN
</p>
<Link
className="text-[16px] font-[400] text-blog-text-default hover:underline"
href={`/blog/categories/${post.category.slug}`}
>
{post.category.name}
</Link>
</div> */}
</div>
<Link
className="w-full text-start text-[24px] font-[600] text-blog-text-default hover:underline"
+7 -3
View File
@@ -7,13 +7,17 @@ import Image from "next/image";
import Link from "next/link";
import Pagination from "../components/pagination/pagination";
import NoDataFounded from "../components/no-data-founded/noDataFounded";
import { Metadata } from "next";
export const metadata: Metadata = {
title: "All Categories List",
description:
"Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.",
};
export default async function Categories({ searchParams }: categoryPropsType) {
const CategoriesData: CategoriesListType = await fetch(
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_CATEGORIES_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
{
cache: "no-store",
},
).then((res) => res.json());
return (
@@ -7,6 +7,16 @@ import Image from "next/image";
import Link from "next/link";
import NoDataFounded from "../../components/no-data-founded/noDataFounded";
import Pagination from "../../components/pagination/pagination";
import { Metadata } from "next";
export const metadata: Metadata = {
title: "",
description: "",
openGraph: {
title: "",
description: "",
},
};
export default async function FilteredPosts({
params,
@@ -17,9 +27,29 @@ export default async function FilteredPosts({
switch (params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()) {
case "new":
filteredPostApiUrl = "/posts?sort_field=published_at&sort_direction=desc";
metadata.title = "All New Posts List";
metadata.description =
"New Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.";
metadata.openGraph
? (metadata.openGraph.title = "All New Posts List")
: "";
metadata.openGraph
? (metadata.openGraph.description =
"New Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.")
: "";
break;
case "popular":
filteredPostApiUrl = "/posts?sort_field=views&sort_direction=desc";
metadata.title = "All Popular Posts List";
metadata.description =
"Popular Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.";
metadata.openGraph
? (metadata.openGraph.title = "All Popular Posts List")
: "";
metadata.openGraph
? (metadata.openGraph.description =
"Popular Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.")
: "";
break;
default:
// code block
+12 -1
View File
@@ -3,8 +3,19 @@ import Header from "./components/header/header";
import Footer from "./components/footer/footer";
export const metadata: Metadata = {
title: "parsa aghayi",
title: {
template: "%s | parsa aghayi's blog",
default: "parsa aghayi's blog",
},
description: "parsa aghayi personal blog",
openGraph: {
title: {
template: "%s | parsa aghayi's blog",
default: "parsa aghayi's blog",
},
description: "parsa aghayi personal blog",
images: ["/images/favicons/blog-icon.png"],
},
};
export default function RootLayout({
+35 -163
View File
@@ -1,24 +1,39 @@
import {
PostSlugPagePostType,
PostSlugPagepropsType,
PostType,
} from "@/app/types/types";
import { PostSlugPagePostType, PostSlugPagepropsType } from "@/app/types/types";
import { Metadata } from "next";
import Image from "next/image";
import Link from "next/link";
import { redirect } from "next/navigation";
export default async function SinglePost({ params }: PostSlugPagepropsType) {
const postData: PostSlugPagePostType = await fetch(
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/posts/${params.postSlug}`,
{
cache: "no-store",
async function fetchPostData(postSlug: string): Promise<PostSlugPagePostType> {
const res = await fetch(
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/posts/${postSlug}`,
);
if (res.status === 404) {
redirect("/blog/404");
}
return res.json();
}
export async function generateMetadata({
params,
}: PostSlugPagepropsType): Promise<Metadata> {
const post: PostSlugPagePostType = await fetchPostData(params.postSlug);
return {
title: post.post.title,
description: post.post.excerpt,
openGraph: {
title: post.post.title,
description: post.post.excerpt,
images: [post.post.featured_image],
},
).then((res) => {
if (res.status == 404) {
redirect("/blog/404");
}
return res.json();
});
};
}
export default async function SinglePost({ params }: PostSlugPagepropsType) {
const postData: PostSlugPagePostType = await fetchPostData(params.postSlug);
return (
<div className="flex w-full max-w-[1280px] flex-wrap justify-center sm:my-10">
@@ -164,157 +179,14 @@ export default async function SinglePost({ params }: PostSlugPagepropsType) {
in grids defining the number of posts and styling the look.
</li>
<li className="ms-5 text-[20px] font-[400] text-blog-text-default">
<span className="font-bold">Feature Box:</span> Use the Feature
Box add-on to display the features of products on your website.
<span className="font-bold">Media Carousel:</span> Create a
media carousel and showcase your media files beautifully.
</li>
<li className="ms-5 text-[20px] font-[400] text-blog-text-default">
<span className="font-bold">Accordion:</span> Need any collapse
text content on your site? Use WP Page Builder’s Accordion
add-on and modify the style the way you want.
<span className="font-bold">Testimonials:</span> WP Page Builder
comes with an add-on to display client testimonials.
</li>
</ul>
<div className="my-10 flex w-full justify-between">
<div className="w-[48%]">
<img
className="w-full"
src={"/images/blog/posts/post/3.png"}
alt={"post image 3"}
/>
</div>
<div className="w-[48%]">
<img
className="w-full"
src={"/images/blog/posts/post/4.png"}
alt={"post image 4"}
/>
</div>
</div>
<p className="my-10 text-center text-[24px] font-[400] text-blog-purple">
“ WP Page Builder offers a lot of ready-to-use design blocks to
make your site development process a lot faster and easier “
</p>
<div className="flex w-full justify-center">
<div className="flex flex-col items-center">
<Image
src={"/images/blog/users/1.png"}
alt={"user 1 image"}
width={80}
height={80}
className="mb-2 rounded-full"
/>
<Link
href={"/"}
className="text-center text-[18px] font-[400] capitalize text-blog-text-default hover:underline"
>
parsa aghayi
</Link>
<p className="text-[16px] font-[400] text-blog-text-default">
Follow me
<Link
href={"/"}
className="ms-1 text-[16px] font-[400] text-blog-blue"
>
@parsaaghayi
</Link>
.
</p>
</div>
</div>
</div>
<div className="sticky top-[150px] flex flex-col items-end gap-5">
<div className="flex cursor-pointer flex-col gap-1">
<Image
src={"/images/blog/icons/like.svg"}
width={35}
height={35}
alt="socials-vertical icons"
/>
<p className="whitespace-nowrap text-center text-[14px] font-[600] text-blog-text-default">
{postData.post.likes}
</p>
</div>
<div className="flex cursor-pointer flex-col gap-1">
<Image
src={"/images/blog/icons/eye.svg"}
width={35}
height={35}
alt="socials-vertical icons"
/>
<p className="whitespace-nowrap text-center text-[14px] font-[600] text-blog-text-default">
{postData.post.views}
</p>
</div>
</div>
</div>
<div className="my-10 mt-20 flex w-full flex-wrap gap-10">
<div className="flex w-full items-center justify-between">
<p className="text-[22px] font-[600] text-blog-text-default">
You might also like...
</p>
{/* <Link
href={"#"}
className="text-[22px] font-[600] capitalize text-blog-text-passive hover:underline"
>
more
</Link> */}
</div>
<div className="flex w-full flex-wrap justify-between gap-5">
{postData.related_posts.map(
(relatedPost: PostType, key: number) => {
if (key < 2) {
return (
<div
key={relatedPost.id}
className="flex w-full flex-col items-center justify-start gap-1 sm:w-[45%]"
>
<Image
className="mb-3 rounded-md"
src={relatedPost.featured_image}
alt={`${relatedPost.title} post featured image`}
loading="lazy"
width={600}
height={500}
/>
<div className="mb-2 flex w-full flex-wrap gap-2">
<div className="flex gap-2">
<p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]">
BY
</p>
<Link
href={"/"}
className="whitespace-nowrap text-[14px] font-[400] capitalize text-blog-text-default hover:underline md:text-[16px]"
>
{relatedPost.author.name}
</Link>
</div>
<div className="whit flex gap-2">
<p className="text-[16px] font-[600] text-blog-text-passive">
IN
</p>
<Link
className="text-[16px] font-[400] text-blog-text-default hover:underline"
href={`/blog/categories/${relatedPost.category.slug}`}
>
{relatedPost.category.name}
</Link>
</div>
</div>
<Link
href={`/blog/posts/${relatedPost.slug}`}
className="w-full text-start text-[24px] font-[600] text-blog-text-default hover:underline"
>
{relatedPost.title}
</Link>
<p className="w-full text-start text-[16px] font-[400] text-blog-text-default">
{relatedPost.excerpt}
</p>
</div>
);
}
},
)}
</div>
</div>
</div>
+12 -14
View File
@@ -1,19 +1,17 @@
import { Dictionary } from "@/app/types/types";
import "server-only";
const dictionaries: { [key: string]: () => Promise<any> } = {
en: () =>
import("../dictionaries/en.json").then((module) => module.default),
fa: () =>
import("../dictionaries/fa.json").then((module) => module.default),
const dictionaries: { [key: string]: () => Promise<Dictionary> } = {
en: () => import("../dictionaries/en.json").then((module) => module.default),
fa: () => import("../dictionaries/fa.json").then((module) => module.default),
};
export const getDictionary = async (
locale: keyof typeof dictionaries,
): Promise<any> => {
const loadDictionary = dictionaries[locale];
if (loadDictionary) {
return loadDictionary();
}
throw new Error(`No dictionary found for locale: ${locale}`);
};
locale: keyof typeof dictionaries,
): Promise<Dictionary> => {
const loadDictionary = dictionaries[locale];
if (loadDictionary) {
return loadDictionary();
}
throw new Error(`No dictionary found for locale: ${locale}`);
};
+30
View File
@@ -117,3 +117,33 @@ export type FilteredPostsDataType = {
};
export type LocaleCookieType = { name: string; value: string };
export type Dictionary = {
homePage: {
top: {
greating: string;
name: string;
profession: string;
roll: string;
descriptionAboutMe: string;
};
services: {
title: string;
description: string;
};
projects: {
title: string;
description: string;
};
testimonials: {
title: string;
description: string;
};
contact: {
slogan: string;
description: string;
button: string;
placeholder: string;
};
};
};
+1
View File
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,