Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 328037c

Browse files
Merge pull request #53 from frontendweb3/fix-tag-issue
Fix tag issue
2 parents f9bbe37 + 278200d commit 328037c

File tree

5 files changed

+61
-47
lines changed

5 files changed

+61
-47
lines changed

examples/demo-section-blog/theme.config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const themeConfig = {
22
settings: {
33
title: "My title",
44
description: "my descript is here ",
5+
SiteURL:"https://officialrajdeepsingh.dev",
56
defaultSEO: {
67
title: "default SEO title is here",
78
titleTemplate: '%s | Section Blog Theme',

packages/section-blog-theme/components/Layouts/Read.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Article } from "@/components/Article/Article";
2-
import * as React from "react";
2+
import { useState, useEffect } from "react";
33
import type { PageOpts } from "nextra";
44
import dayjs from "dayjs";
55
import { Button } from "@/components/ui/button";
@@ -10,8 +10,10 @@ import Link from "next/link";
1010
import { Seo } from "@/components/Seo/Seo";
1111
import { slugify } from "@/utility/slugify";
1212
import { TypeSectionBlogTheme } from "@/src/types";
13+
import type {ReactNode} from "react";
1314

14-
export function Read({ pageOpts, themeConfig, children }: { pageOpts: PageOpts; themeConfig: TypeSectionBlogTheme; children: React.ReactNode; }) {
15+
export function Read({ pageOpts, themeConfig, children }: { pageOpts: PageOpts; themeConfig: TypeSectionBlogTheme; children: ReactNode; }) {
16+
const [domain, setDomain] = useState<string>()
1517

1618
const { frontMatter } = pageOpts;
1719

@@ -24,17 +26,21 @@ export function Read({ pageOpts, themeConfig, children }: { pageOpts: PageOpts;
2426
let getSite = settings?.SiteURL
2527

2628
let getAuthorURL = frontMatter?.author?.url
27-
28-
let getTagURL = Next_URL(getSite) + "tags/" + getTag
2929

30-
let getRwebURL = Next_URL(getSite) + (pageOpts.route.replace("/",""))
31-
30+
useEffect(function () {
31+
let getDomain = window.location.origin as string
32+
setDomain(getDomain)
33+
}, [])
34+
35+
let getTagURL = Next_URL(getSite) + "tags/" + getTag
36+
37+
let getRwebURL = domain + "/" + (pageOpts.route.replace("/", ""))
38+
3239
return (
3340
<>
3441

3542
<Seo pageOpts={pageOpts} themeConfig={themeConfig} />
3643

37-
3844
<div className="px-3 sm:px-0 mx-auto my-6 print:block prose prose-pre:bg-primary-foreground prose-zinc sm:prose-sm md:prose-base lg:prose-lg xl:prose-xl 2xl:prose-2xl dark:prose-invert">
3945

4046
<section className="not-prose flex flex-row justify-between items-center">
@@ -65,11 +71,11 @@ export function Read({ pageOpts, themeConfig, children }: { pageOpts: PageOpts;
6571
title={getDate}
6672
>
6773
{getDate}
68-
</time><Link href={getTagURL} className="capitalize ml-2 hover:text-gray-600"> {frontMatter.tags[0]} </Link>
74+
</time><Link href={getTagURL} className="capitalize ml-2 hover:text-gray-600"> {getTag} </Link>
6975
</div>
7076

7177
<div className="hidden sm:flex flex-row print:block">
72-
78+
7379
<RWebShare
7480
data={{
7581
text: frontMatter.description,
@@ -78,9 +84,9 @@ export function Read({ pageOpts, themeConfig, children }: { pageOpts: PageOpts;
7884
}}
7985
onClick={() => console.log("shared successfully!")}
8086
>
81-
87+
8288
<Button aria-label="Share a Post" variant="ghost" size="icon">
83-
89+
8490
<Share2Icon className="h-4 w-4" />
8591

8692
</Button>
Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import type { PageOpts, ThemeConfig } from "nextra";
2-
import { useRouter } from "next/router";
1+
import type { PageOpts } from "nextra";
32
import { useTagContent } from "@/utility/useTagContent"
43
import { ArticleCard } from "@/components/Card/Card";
54
import dayjs from "dayjs";
65
import { Article } from "@/components/Article/Article";
76
import { Error404 } from "./404";
87
import { TypeSectionBlogTheme } from "@/src/types"
8+
import type {ReactNode} from "react";
9+
import { useRouter } from 'next/router'
910

10-
export function Tag({ pageOpts, themeConfig, children }: { pageOpts: PageOpts; themeConfig: TypeSectionBlogTheme; children: React.ReactNode; }) {
11+
12+
export function Tag({ pageOpts, themeConfig, children }: { pageOpts: PageOpts; themeConfig: TypeSectionBlogTheme; children: ReactNode; }) {
1113

1214
const { DateFormat } = themeConfig;
1315

@@ -16,33 +18,36 @@ export function Tag({ pageOpts, themeConfig, children }: { pageOpts: PageOpts; t
1618
let tagSlug = router.query && router.query.tag && typeof router.query.tag === "string" ? router.query.tag : router?.query?.tag as string
1719

1820
const { posts } = useTagContent(pageOpts, tagSlug)
19-
20-
if ( posts === undefined || posts.length === 0) {
21-
return (<Error404 /> )
21+
22+
if (posts === undefined || posts.length === 0) {
23+
return (<Error404 />)
2224
}
2325
return (
2426
<>
2527
<Article>{children}</Article>
26-
<div className="mx-auto my-24 divide-y divide-slate-700 grid-cols-1 grid max-w-[724px] lg:max-w-[1024px] gap-4">
27-
{posts?.map(
28-
(post) => {
29-
30-
let getDate = dayjs(post.frontMatter.date).format(DateFormat? DateFormat : "MMM DD, YYYY");
31-
32-
return (
33-
<ArticleCard
34-
key={post.frontMatter.date + post.frontMatter.title}
35-
title={post.frontMatter.title}
36-
description={post.frontMatter.description}
37-
tag={post.frontMatter.tags}
38-
date={getDate}
39-
URL={post.route}
40-
author={post.frontMatter?.author}
41-
/>
42-
);
43-
},
44-
)}
45-
</div>
28+
29+
<section className="py-8 px-4 mx-auto max-w-screen-xl lg:py-16 lg:px-6">
30+
<div className="grid gap-8 lg:grid-cols-2">
31+
{posts?.map(
32+
(post) => {
33+
34+
let getDate = dayjs(post.frontMatter.date).format(DateFormat ? DateFormat : "MMM DD, YYYY");
35+
36+
return (
37+
<ArticleCard
38+
key={post.frontMatter.date + post.frontMatter.title}
39+
title={post.frontMatter.title}
40+
description={post.frontMatter.description}
41+
tag={post.frontMatter.tags}
42+
date={getDate}
43+
URL={post.route}
44+
author={post.frontMatter?.author}
45+
/>
46+
);
47+
},
48+
)}
49+
</div>
50+
</section>
4651
</>
4752
);
4853
}

packages/section-blog-theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "section-blog-theme",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"main": "dist/index.js",
55
"types": "dist/types.d.mts",
66
"keywords": [
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11

22
export function Next_URL(Site: string | undefined): string {
33

4-
let getPort = process.env.PORT || 3000
4+
if (process.env.NODE_ENV === 'development') {
5+
return "/"
6+
}
7+
8+
if (process.env.NODE_ENV === 'production' && Site) {
59

6-
let getDomain = `http://localhost:${getPort}`
10+
return Site
711

8-
if (process.env.NODE_ENV === 'development' || getPort) {
9-
return getDomain + "/"
1012
} else {
11-
if (Site) {
12-
return Site
13-
} else {
14-
return getDomain + "/"
15-
}
13+
14+
throw new Error("Please add your production URL in theme.config.tsx file.")
15+
1616
}
17+
18+
1719
}

0 commit comments

Comments
 (0)