diff --git a/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx b/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx index c4af249..ccc4f08 100644 --- a/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx +++ b/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx @@ -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; diff --git a/src/app/(routes)/(website)/layout.tsx b/src/app/(routes)/(website)/layout.tsx index db12887..a400698 100644 --- a/src/app/(routes)/(website)/layout.tsx +++ b/src/app/(routes)/(website)/layout.tsx @@ -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({
^ diff --git a/src/app/(routes)/(website)/page.tsx b/src/app/(routes)/(website)/page.tsx index 6136036..965ab35 100644 --- a/src/app/(routes)/(website)/page.tsx +++ b/src/app/(routes)/(website)/page.tsx @@ -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()); diff --git a/src/app/(routes)/(website)/projects/page.tsx b/src/app/(routes)/(website)/projects/page.tsx index 96e4a7f..08b43f4 100644 --- a/src/app/(routes)/(website)/projects/page.tsx +++ b/src/app/(routes)/(website)/projects/page.tsx @@ -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
Projects
; diff --git a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx index 686e6ec..3ed9fb6 100644 --- a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx +++ b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx @@ -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 { + 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 { + 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), + ); return (
-
+

{params.categorySlug.replaceAll(/%20|-|_/g, " ")}

{categoryData.category.description}

+
+
+

+ Total Posts: +

+ + {categoryData.meta.total} + +
+
    @@ -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 -
  • -

    +

    {categoryData.category.name} - - {categoryData.meta.total} -

@@ -92,17 +127,6 @@ export default async function SingleCategory({ {post.author.name}
- {/*
-

- IN -

- - {post.category.name} - -
*/}
res.json()); return ( diff --git a/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx b/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx index 42634d7..184096a 100644 --- a/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx +++ b/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx @@ -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 diff --git a/src/app/(routes)/blog/layout.tsx b/src/app/(routes)/blog/layout.tsx index f8b4581..bf1221f 100644 --- a/src/app/(routes)/blog/layout.tsx +++ b/src/app/(routes)/blog/layout.tsx @@ -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({ diff --git a/src/app/(routes)/blog/posts/[postSlug]/page.tsx b/src/app/(routes)/blog/posts/[postSlug]/page.tsx index 5a5b9bb..aeb6e99 100644 --- a/src/app/(routes)/blog/posts/[postSlug]/page.tsx +++ b/src/app/(routes)/blog/posts/[postSlug]/page.tsx @@ -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 { + 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 { + 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 (
@@ -164,157 +179,14 @@ export default async function SinglePost({ params }: PostSlugPagepropsType) { in grids defining the number of posts and styling the look.
  • - Feature Box: Use the Feature - Box add-on to display the features of products on your website. + Media Carousel: Create a + media carousel and showcase your media files beautifully.
  • - Accordion: Need any collapse - text content on your site? Use WP Page Builder’s Accordion - add-on and modify the style the way you want. + Testimonials: WP Page Builder + comes with an add-on to display client testimonials.
  • -
    -
    - {"post -
    -
    - {"post -
    -
    -

    - “ WP Page Builder offers a lot of ready-to-use design blocks to - make your site development process a lot faster and easier “ -

    -
    -
    - {"user - - parsa aghayi - -

    - Follow me - - @parsaaghayi - - . -

    -
    -
    -
    - -
    -
    - socials-vertical icons -

    - {postData.post.likes} -

    -
    -
    - socials-vertical icons -

    - {postData.post.views} -

    -
    -
    -
    - -
    -
    -

    - You might also like... -

    - {/* - more - */} -
    -
    - {postData.related_posts.map( - (relatedPost: PostType, key: number) => { - if (key < 2) { - return ( -
    - {`${relatedPost.title} -
    -
    -

    - BY -

    - - {relatedPost.author.name} - -
    -
    -

    - IN -

    - - {relatedPost.category.name} - -
    -
    - - {relatedPost.title} - -

    - {relatedPost.excerpt} -

    -
    - ); - } - }, - )}
    diff --git a/src/app/lib/functions/dictionaries.ts b/src/app/lib/functions/dictionaries.ts index 6f2d888..028625c 100644 --- a/src/app/lib/functions/dictionaries.ts +++ b/src/app/lib/functions/dictionaries.ts @@ -1,19 +1,17 @@ +import { Dictionary } from "@/app/types/types"; import "server-only"; -const dictionaries: { [key: string]: () => Promise } = { - en: () => - import("../dictionaries/en.json").then((module) => module.default), - fa: () => - import("../dictionaries/fa.json").then((module) => module.default), +const dictionaries: { [key: string]: () => Promise } = { + 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 => { - const loadDictionary = dictionaries[locale]; - if (loadDictionary) { - return loadDictionary(); - } - throw new Error(`No dictionary found for locale: ${locale}`); - }; - + locale: keyof typeof dictionaries, +): Promise => { + const loadDictionary = dictionaries[locale]; + if (loadDictionary) { + return loadDictionary(); + } + throw new Error(`No dictionary found for locale: ${locale}`); +}; diff --git a/src/app/types/types.ts b/src/app/types/types.ts index 03b6505..f7aab76 100644 --- a/src/app/types/types.ts +++ b/src/app/types/types.ts @@ -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; + }; + }; +}; diff --git a/tsconfig.json b/tsconfig.json index 5b3758b..ccfde92 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "target": "es2017", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,