Skip to content

Commit 7466e28

Browse files
authored
Add og:title, og:description to preview page (#25)
* preview 페이지에서 입력한 title, description이 og에 적용되도록 변경 * Layout 위치 변경 및 title, description 기본값 변경
1 parent a0e7f49 commit 7466e28

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

components/Layout.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import Head from 'next/head';
44
import Header from 'components/Header';
55
import Footer from 'components/Footer';
6+
import Adfit from 'components/Adfit';
67

78
type Props = {
89
children: React.ReactNode;
@@ -23,6 +24,7 @@ function Layout({ children }: Props) {
2324
<Header />
2425
<main className="container grow flex flex-col items-center gap-y-8">
2526
{children}
27+
<Adfit />
2628
</main>
2729
<Footer />
2830
</div>

pages/_app.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import '../styles/globals.css';
22
import type { AppProps } from 'next/app';
33

4+
import Layout from 'components/Layout';
5+
46
function MyApp({ Component, pageProps }: AppProps) {
5-
return <Component {...pageProps} />;
7+
return (
8+
<Layout>
9+
<Component {...pageProps} />
10+
</Layout>
11+
);
612
}
713

814
export default MyApp;

pages/index.tsx

+13-16
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ function Home() {
3535

3636
return (
3737
<FormProvider>
38-
<Layout>
39-
<OgTags />
40-
<p>SVG showing the Moon Phase for today.</p>
41-
<Hits />
42-
<a>
43-
{/* eslint-disable-next-line @next/next/no-img-element */}
44-
<img src={svgUrl} alt="moon.svg" />
45-
</a>
46-
<MoonForm onChange={handleFormChange} />
47-
<CopyModal.Button id="copy-modal" />
48-
<CopyModal.Modal
49-
id="copy-modal"
50-
text={`https://moon-svg.minung.dev${svgUrl}`}
51-
/>
52-
<Adfit />
53-
</Layout>
38+
<OgTags />
39+
<p>SVG showing the Moon Phase for today.</p>
40+
<Hits />
41+
<a>
42+
{/* eslint-disable-next-line @next/next/no-img-element */}
43+
<img src={svgUrl} alt="moon.svg" />
44+
</a>
45+
<MoonForm onChange={handleFormChange} />
46+
<CopyModal.Button id="copy-modal" />
47+
<CopyModal.Modal
48+
id="copy-modal"
49+
text={`https://moon-svg.minung.dev${svgUrl}`}
50+
/>
5451
</FormProvider>
5552
);
5653
}

pages/preview.tsx

+21-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type Props = {
1717
function Preview({ query }: Props) {
1818
const [data, setData] = useState<FormValues>({
1919
...query,
20-
title: query.title || '기본값',
21-
description: query.description || '기본값',
20+
title: query.title,
21+
description: query.description,
2222
});
2323

2424
const queryString = objectToQueryString({
@@ -63,29 +63,34 @@ function Preview({ query }: Props) {
6363

6464
return (
6565
<FormProvider defaultValues={defaultValues}>
66-
<Layout>
67-
<OgTags
68-
url={`https://moon-svg.minung.dev/preview${queryString}`}
69-
image={`https://moon-svg.minung.dev/moon.png${queryString}`}
70-
/>
71-
<p>Share Moon&apos;s Phases with your friends!</p>
72-
<LinkPreviewCard
73-
image={`https://moon-svg.minung.dev/moon.png${queryString}`}
74-
title={data.title!}
75-
description={data.description!}
76-
/>
77-
<MoonForm keys={PREVIEW_FORM_KEYS} onChange={handleFormChange} />
78-
</Layout>
66+
<OgTags
67+
url={`https://moon-svg.minung.dev/preview${queryString}`}
68+
image={`https://moon-svg.minung.dev/moon.png${queryString}`}
69+
title={data.title}
70+
description={data.description}
71+
/>
72+
<p>Share Moon&apos;s Phases with your friends!</p>
73+
<LinkPreviewCard
74+
image={`https://moon-svg.minung.dev/moon.png${queryString}`}
75+
title={data.title!}
76+
description={data.description!}
77+
/>
78+
<MoonForm keys={PREVIEW_FORM_KEYS} onChange={handleFormChange} />
7979
</FormProvider>
8080
);
8181
}
8282

8383
export default Preview;
8484

8585
export const getServerSideProps: GetServerSideProps = async (context) => {
86+
const dateString = new Date().toLocaleDateString();
8687
return {
8788
props: {
88-
query: context.query,
89+
query: {
90+
title: 'Moon phase',
91+
description: `Moon phase on ${dateString}`,
92+
...context.query,
93+
},
8994
},
9095
};
9196
};

0 commit comments

Comments
 (0)