Skip to content

Commit 3f5fc82

Browse files
committed
update
1 parent a33ef3a commit 3f5fc82

File tree

8 files changed

+66
-31
lines changed

8 files changed

+66
-31
lines changed

src/app/[locale]/(frontend)/(home)/page.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { StyleMain } from "@/components/frontend/page/style/main";
33
import { appConfig, LocaleType } from "@/config";
44
import { getComponentMarkdown } from "@/i18n";
5+
import { getOrigin } from "@/lib/utils";
56
import { Metadata } from "next";
67
import { getTranslations } from "next-intl/server";
78
import { headers } from 'next/headers';
@@ -25,11 +26,8 @@ export default async function Home({
2526
params: { locale: string; };
2627
}>) {
2728
const headersList = headers();
28-
const host = headersList.get('host') || appConfig.appDomain;
29-
30-
const protocol = ['localhost','127.0.0.1'].includes(host.split(":")[0] )? 'http' : 'https';
31-
const origin = `${protocol}://${host}`;
32-
29+
const origin = getOrigin({headers: headersList});
30+
const url = new URL(headersList.get('x-request-url')!);
3331
// Load by key: public/data/generated/components-markdown.json
3432
const markdownContents = {
3533
block1: await getComponentMarkdown({
@@ -41,7 +39,7 @@ export default async function Home({
4139

4240
return (
4341
<div className="px-8 flex">
44-
<StyleMain style="all" markdownContents={markdownContents} />
42+
<StyleMain style="all" markdownContents={markdownContents} text={url.searchParams.get("text")} />
4543
</div>
4644
);
4745
}

src/app/[locale]/(frontend)/[style]/page.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StyleMain } from "@/components/frontend/page/style/main";
33
import { Crumb } from "@/components/frontend/shared/crumb";
44
import { LocaleType } from "@/config";
55
import { getComponentMarkdown } from "@/i18n";
6-
import { origin } from "@/lib/utils";
6+
import { getOrigin } from "@/lib/utils";
77
import { styleMetadata } from "@/metadata";
88
import { StyleKey } from "@/slugs";
99
import { CrumbItem } from "@/types";
@@ -19,16 +19,18 @@ export default async function Style({
1919
params: { locale: LocaleType; style: StyleKey; };
2020
}>) {
2121
const { locale, style } = params;
22-
22+
const headersList = headers();
23+
const origin = getOrigin({headers: headersList});
24+
2325
// Load by key: public/data/generated/components-markdown.json
2426
const markdownContents = {
2527
block1: await getComponentMarkdown({
2628
locale,
2729
componentPathName: `style/${style}/block1`,
28-
origin: origin({headers: headers()})
30+
origin
2931
})
30-
}
31-
32+
}
33+
const url = new URL(headersList.get('x-request-url')!);
3234
const items: CrumbItem[] = [
3335
{
3436
name: style,
@@ -40,7 +42,7 @@ export default async function Style({
4042
return (
4143
<div className="px-8">
4244
<Crumb items={items} className="" params={params} />
43-
<StyleMain markdownContents={markdownContents} style={style}/>
45+
<StyleMain markdownContents={markdownContents} style={style} text={url.searchParams.get("text")} />
4446
</div>
4547
);
4648
}

src/components/frontend/page/style/fonts.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export const Fonts = ({
3131
const transformAndAdjust = (text: string) => {
3232
return Array.from(text).map(char => {
3333
let newChar = chars[char] || char;
34+
3435
if(style === "underline"){
35-
if(underline) newChar = addUnderline({char: newChar, fontKey});
36+
if(underline) newChar = addUnderline({char: newChar, fontKey});
3637
if(strikethrough) newChar = addStrikethrough({char: newChar, fontKey});
3738
if(doubleUnderline) newChar = addDoubleUnderline({char: newChar, oldChar: char, fontKey});
3839
if(wavyUnderline) newChar = addWavyUnderline({char: newChar, oldChar: char, fontKey});
@@ -61,12 +62,12 @@ export const Fonts = ({
6162
className="data-[underline='true']:font-extrabold data-[underline='true']:bg-primary/25 underline underline-offset-3 rounded-lg dark:border-white/10">
6263
{"U"}
6364
</Button>
64-
<Button aria-label="Double Underline" size="icon" data-doubleUnderline={doubleUnderline} variant="outline" onClick={()=> setDoubleUnderline(!doubleUnderline) }
65-
className="data-[doubleUnderline='true']:font-extrabold data-[doubleUnderline='true']:bg-primary/25 rounded-lg dark:border-white/10">
65+
<Button aria-label="Double Underline" size="icon" data-double-underline={doubleUnderline} variant="outline" onClick={()=> setDoubleUnderline(!doubleUnderline) }
66+
className="data-[doubleu-underline='true']:font-extrabold data-[double-underline='true']:bg-primary/25 rounded-lg dark:border-white/10">
6667
{"U" + '\u0333'}
6768
</Button>
68-
<Button aria-label="WavyUnderline" size="icon" data-wavyUnderline={wavyUnderline} variant="outline" onClick={()=> setWavyUnderline(!wavyUnderline) }
69-
className="data-[wavyUnderline='true']:font-extrabold data-[wavyUnderline='true']:bg-primary/25 rounded-lg dark:border-white/10">
69+
<Button aria-label="Wavy nderline" size="icon" data-wavy-underline={wavyUnderline} variant="outline" onClick={()=> setWavyUnderline(!wavyUnderline) }
70+
className="data-[wavy-underline='true']:font-extrabold data-[wavy-underline='true']:bg-primary/25 rounded-lg dark:border-white/10">
7071
{"U" + '\u0330'}
7172
</Button>
7273
<Button aria-label="Strikethrough" size="icon" data-strikethrough={strikethrough} variant="outline" onClick={()=> setStrikethrough(!strikethrough) }

src/components/frontend/page/style/main.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22

33
import { Markdown } from "@/components/shared/markdown";
44
import { Textarea } from "@/components/ui/textarea";
5+
import { usePathname } from "@/lib/i18n";
56
import { cn } from "@/lib/utils";
67
import { styleFonts, StyleKey } from "@/slugs";
78
import { fontKeys } from "@/transforms";
9+
import { useSearchParams } from "next/navigation";
810
import { useState } from "react";
911
import { Fonts } from "./fonts";
1012
import { Sidebar } from "./sidebar";
1113

1214
export function StyleMain({
1315
markdownContents,
14-
style = "all"
16+
style = "all",
17+
text = "Hello my old friend",
1518
}: Readonly<{
1619
markdownContents: Record<string, string | undefined>;
17-
style: StyleKey,
18-
20+
style: StyleKey;
21+
text?: string | null;
1922
}>) {
2023
const { block1, block2 } = markdownContents;
21-
const [content, setContent] = useState<string>("Hello my old friend");
24+
const [content, setContent] = useState<string>(text ? text : "");
25+
const pathname = usePathname();
26+
const search = useSearchParams().toString();
2227

28+
console.log("text", text)
29+
console.log("search", search)
30+
2331
const onChange=(e: React.ChangeEvent<HTMLTextAreaElement>)=>{
2432
setContent(e.target.value);
2533
}

src/components/frontend/page/style/sidebar.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import { Link } from "@/lib/i18n";
22
import { styleFonts, StyleKey } from "@/slugs";
33
import { ALargeSmallIcon, BoldIcon, FeatherIcon, ItalicIcon, StarsIcon, UnderlineIcon } from "lucide-react";
44
import { useTranslations } from "next-intl";
5+
import { useSearchParams } from "next/navigation";
56
import { ClassNameValue } from "tailwind-merge";
67

7-
export const Sidebar =( )=>{
8+
export const Sidebar =( )=>{
9+
let search = useSearchParams().toString();
10+
if(search) search = `?${search}`;
11+
812
const t = useTranslations();
913
const linkCls: ClassNameValue = "border w-full h-12 flex rounded-lg items-center gap-3 px-5 font-semibold mb-5";
1014

@@ -52,19 +56,19 @@ export const Sidebar =( )=>{
5256
default:
5357
return null;
5458
}
55-
}
59+
}
5660

5761
return(
5862
<>
5963
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-1 gap-x-3 md:flex-row">
60-
<Link href="/" className={linkCls}>
64+
<Link href={`/${search}`} className={linkCls}>
6165
<span>{t('frontend.style.sidebar.all')}</span>
6266
</Link>
6367
{ Object.entries(styleFonts).map(([slug]) =>{
6468
const name = i18nName(slug as StyleKey);
6569
if(!name) return;
6670
return(
67-
<Link href={`/${slug}`} key={slug} className={linkCls}>
71+
<Link href={`/${slug}${search}`} key={slug} className={linkCls}>
6872
<NavIcon slug={slug as StyleKey} />
6973
<span className="text-sm">{name}</span>
7074
</Link>

src/components/frontend/shared/nav-bar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import { Button } from "@/components/ui/button";
44
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
55
import { Link } from "@/lib/i18n";
6-
import { useTranslations } from "next-intl";
76

87
import { appConfig } from "@/config";
98
import {
109
Menu
1110
} from "lucide-react";
1211
import Image from "next/image";
1312
export function NavBar() {
14-
const t = useTranslations();
13+
1514
const memu = [
1615
{
1716
name: appConfig.appName,

src/lib/utils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const canonicalLink = (domain: string, pathname: string) => {
1111
return `${isProduction ? "https" : "http"}://${domain}${pathname}`;
1212
}
1313

14-
export const origin = ({ headers }: { headers: Headers }) => {
14+
export const getOrigin = ({ headers }: { headers: Headers }) => {
1515
const host = headers.get('host') || appConfig.appDomain;
1616

1717
const protocol = ['localhost', '127.0.0.1'].includes(host.split(":")[0]) ? 'http' : 'https';
@@ -26,12 +26,26 @@ type appendChar = {
2626

2727
export const addUnderline = ({ char, fontKey }: appendChar) => {
2828
switch (fontKey) {
29+
case "smallCaps":
30+
case "boldScript":
31+
case "boldFraktur":
2932
case "superscript":
33+
case "doubleStruck":
34+
case "serifBoldItalic":
35+
case "serifBold":
36+
case "serifItalic":
37+
case "sansSerif":
38+
case "sansItalic":
39+
case "sansBoldItalic":
40+
case "sansBold":
41+
case "monospace":
42+
case "inverted":
43+
case "mirrored":
3044
case "script":
3145
case "subscript":
32-
return char + '\u035f';
46+
return char + '\u0332';
3347
default:
34-
return char;
48+
return char + '\u0332';
3549
}
3650
}
3751
export const addDoubleUnderline = ({ char, oldChar, fontKey }: appendChar) => {

src/middleware.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import createMiddleware from "next-intl/middleware";
33
import { NextRequest } from "next/server";
44

55
export default async function middleware(req: NextRequest) {
6+
const reqHeaders = new Headers(req.headers);
7+
reqHeaders.set('x-request-url', req.url);
8+
9+
// Create a new request with updated headers
10+
const modifiedRequest = new NextRequest(req.url, {
11+
headers: reqHeaders,
12+
method: req.method,
13+
body: req.body
14+
});
615
const intlMiddleware = createMiddleware({
716
locales: appConfig.i18n.locales,
817
defaultLocale: appConfig.i18n.defaultLocale,
@@ -11,7 +20,7 @@ export default async function middleware(req: NextRequest) {
1120
alternateLinks: true
1221
});
1322

14-
return intlMiddleware(req);
23+
return intlMiddleware(modifiedRequest);
1524
}
1625

1726
export const config = {

0 commit comments

Comments
 (0)