Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration hompage's next.js code to 13+ version #122

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b1fc17f
chore: react, next, eslint version update
DongjaJ Mar 1, 2024
5abe480
chore: migrate next/image from next/image to next/legacy/image
DongjaJ Mar 1, 2024
4a707e9
chore: migrate next/image component from next/lagacy/image to next/image
DongjaJ Mar 1, 2024
9b858fa
chore: add lagacyBehaivor Props to Link component
DongjaJ Mar 1, 2024
d44192f
chore: remove lagacybehaivor
DongjaJ Mar 1, 2024
9ec4851
fix: make RootLayout
DongjaJ Mar 18, 2024
4f24ad7
fix: mainpage
DongjaJ Mar 18, 2024
efcf455
fix: add use client
DongjaJ Mar 18, 2024
6bafcf6
fix: router migration
DongjaJ Mar 18, 2024
14ca024
fix: community page migration
DongjaJ Mar 18, 2024
d1ac08c
fix: products page migration
DongjaJ Mar 18, 2024
4a764ff
feat: style.css import
DongjaJ Mar 27, 2024
8db1944
fix: example page migration
DongjaJ Mar 30, 2024
2128a7f
fix: example/calendar page migration
DongjaJ Mar 30, 2024
ad053a0
fix: example/codemirror page migration
DongjaJ Mar 30, 2024
aa252d7
fix: all example page migration
DongjaJ Mar 30, 2024
b61ff60
fix: 404 page migration
DongjaJ Mar 30, 2024
5473d96
fix: add 'use client'
DongjaJ Apr 10, 2024
9deb7e8
chore: webpack svg setting
DongjaJ Apr 10, 2024
b4af4b5
fix: docspage migration
DongjaJ Apr 10, 2024
b115819
fix: add 'use client'
DongjaJ Apr 10, 2024
817a6ed
refactor: rename ThemeInitializer component
DongjaJ Apr 10, 2024
ee70496
chore: next version 14.0 update
DongjaJ Apr 10, 2024
5b3aced
refactor: delete unused value
DongjaJ Apr 10, 2024
0ed974c
chore: nextjs downgrade(13.5)
DongjaJ Apr 10, 2024
f5bf7bf
chore: output: export option next.config.js
DongjaJ Apr 10, 2024
27d8aee
fix: remove output property and update env property in next.config.js
DongjaJ Apr 11, 2024
aad3123
fix: rollback output option
DongjaJ Apr 11, 2024
311253f
chore: next, next-image-export-optimizer version update
DongjaJ Apr 11, 2024
d1d14e5
chore: delete next export command (because over next14 that command i…
DongjaJ Apr 11, 2024
f6f4df5
chore: github action and node version update
DongjaJ Apr 11, 2024
4228c99
chore: add transplilePackages option in next.config.js
DongjaJ Apr 11, 2024
4ac5832
fix: remove dynamic params and add mdx config
DongjaJ Apr 15, 2024
4f87604
chore: prism-react-renderer version update
DongjaJ Apr 15, 2024
d4ba414
fix: use client add and remove
DongjaJ Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/_components/ThemeInitializer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client';

import { type ThemeOption, useTheme } from '@/hooks/useTheme';
import { useEffect } from 'react';

function ThemeInitializer() {
const { setTheme } = useTheme();
useEffect(() => {
const themeOption = (window.localStorage.getItem('theme') || 'system') as ThemeOption;
setTheme(themeOption);
}, [setTheme]);

return null;
}

export default ThemeInitializer;
2 changes: 2 additions & 0 deletions pages/community.tsx → app/community/community-page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import type { NextPage } from 'next';
import Head from 'next/head';
import { Button, Icon, Layout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/community/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CommunityPage from './community-page';

export default async function Page() {
return <CommunityPage />;
}
147 changes: 147 additions & 0 deletions app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { getSlugs, getDocsFromSlug, getDocsMetaFromSlug, getDocsOrderList } from '@/utils/mdxUtils';
import type { MDXComponents } from 'mdx/types';
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeToc, { HtmlElementNode, ListItemNode } from '@jsdevtools/rehype-toc';
import rehypeImageMeta from '@/utils/rehypeImageMeta';
import rehypeWrapContents from '@/utils/rehypeWrapContents';
import rehypeVariables from '@/utils/rehypeVariables';
import { Button, Icon, CodeBlock, CodeBlockHeader, Image } from '@/components';
import { CustomLink, CustomCodeBlock, Breadcrumb, Caption, ImageWrap, Alert, Blockquote } from '@/components/docs';
import SlugPage from './slug-page';
import { compileMDX } from 'next-mdx-remote/rsc';

type Props = {
params: {
slug?: string[];
};
};

const components: MDXComponents = {
a: CustomLink,
h3: (props) => <h3 className="heading" {...props} />,
h4: (props) => <h4 className="heading" {...props} />,
h5: (props) => <h5 className="heading" {...props} />,
h6: (props) => <h6 className="heading" {...props} />,
Button,
Icon,
pre: (props) => <CustomCodeBlock {...props} />,
blockquote: (props) => <Blockquote {...props} />,
img: ({ src, alt, title, width, height }) => (
<Image src={src!} alt={alt || ''} title={title} width={width as number} height={height as number} />
),
Image,
ImageWrap,
Breadcrumb,
Caption,
Alert,
CodeBlock,
CodeBlockHeader,
};

export default async function DocsPage({ params }: Props) {
const slug = params.slug?.join('/') ?? 'index';

const { content } = getDocsFromSlug(slug);
const mdxSource = await compileMDX({
source: content,
options: {
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeImageMeta,
[
rehypeVariables,
{
variables: [
{ pattern: 'YORKIE_VERSION', value: process.env.NEXT_PUBLIC_YORKIE_VERSION },
{ pattern: 'YORKIE_JS_VERSION', value: process.env.NEXT_PUBLIC_YORKIE_JS_VERSION },
{ pattern: 'YORKIE_IOS_VERSION', value: process.env.NEXT_PUBLIC_YORKIE_IOS_VERSION },
{ pattern: 'YORKIE_ANDROID_VERSION', value: process.env.NEXT_PUBLIC_YORKIE_ANDROID_VERSION },
{ pattern: 'DASHBOARD_PATH', value: process.env.NEXT_PUBLIC_DASHBOARD_PATH },
{ pattern: 'API_ADDR', value: process.env.NEXT_PUBLIC_API_ADDR },
{ pattern: 'API_HOST', value: process.env.NEXT_PUBLIC_API_HOST },
{ pattern: 'API_PORT', value: process.env.NEXT_PUBLIC_API_PORT },
],
},
],
rehypeSlug,
[
rehypeAutolinkHeadings,
{
test: ['h3', 'h4', 'h5', 'h6'],
behavior: 'wrap',
},
],
[
rehypeToc,
{
position: 'afterend',
headings: ['h3', 'h4', 'h5', 'h6'],
customizeTOC: (toc: HtmlElementNode) => {
const children = toc.children || [];
const contents = (children[0] as any)?.children?.length;
if (!contents) return false;

toc.tagName = 'div';
toc.properties.className = 'pagination';
const wrapper = {
type: 'element',
tagName: 'div',
properties: { className: 'pagination_inner' },
children: [
{
type: 'element',
tagName: 'strong',
properties: { className: 'pagination_title' },
children: [{ type: 'text', value: 'On this page' }],
},
...children,
],
};
toc.children = [wrapper];
},
customizeTOCItem: (tocItem: ListItemNode, heading: HtmlElementNode) => {
tocItem.properties['data-heading'] = heading.properties.id;
},
},
],
rehypeWrapContents,
],
},
parseFrontmatter: true,
},
components,
});

const navList = getDocsOrderList('/docs');

return <SlugPage navList={navList} source={mdxSource.content} />;
}

export async function generateMetadata({ params }: Props) {
const slug = params.slug?.join('/') ?? 'index';
const { meta } = getDocsFromSlug(slug);

return {
...meta,
};
}

export const dynamicParams = false;

export const generateStaticParams = () => {
const params = getSlugs()
.filter((slug) => {
if (process.env.NODE_ENV === 'development') return true;

const { phase } = getDocsMetaFromSlug(slug);
return phase !== 'development';
})
.map((slug) => ({
slug: slug === 'index' ? [''] : slug.split('/'),
}));

return params;
};
72 changes: 72 additions & 0 deletions app/docs/[[...slug]]/slug-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use client';

import { useState, useEffect, useCallback } from 'react';
import Head from 'next/head';
import { type DocsOrderList } from '@/utils/mdxUtils';
import { Layout, Navigator } from '@/components';

export default function DocsPage({ source, navList }: { source: React.ReactElement; navList: DocsOrderList }) {
const [activeId, setActiveId] = useState<string>('');
const [headings, setHeadings] = useState<Array<Element>>([]);
const [headingTops, setHeadingTops] = useState<Array<{ id: string; top: number }>>([]);

const updateHeadingPositions = useCallback(() => {
const scrollTop = document.documentElement.scrollTop;
const headingTops = [...headings].map((heading) => {
const top = heading.getBoundingClientRect().top + scrollTop;
return {
id: heading.id,
top,
};
});
setHeadingTops(headingTops);
}, [headings]);

useEffect(() => {
setHeadings(Array.from(document.querySelectorAll('.documentation_page .heading')));
}, [source]);

useEffect(() => {
if (headings.length === 0) return;

const setActiveTOCLink = () => {
const scrollTop = document.documentElement.scrollTop;
const yOffset = 150;

const currentHeading =
scrollTop < 10
? headingTops.find((headingTop) => {
return scrollTop >= headingTop.top - yOffset;
})
: [...headingTops].reverse().find((headingTop) => {
return scrollTop >= headingTop.top - yOffset;
});

setActiveId(currentHeading?.id || '');
};

window.addEventListener('scroll', setActiveTOCLink);
setActiveTOCLink();
return () => {
window.removeEventListener('scroll', setActiveTOCLink);
};
}, [headings, headingTops]);

useEffect(() => {
updateHeadingPositions();
document.querySelector(`.toc-item.is_active`)?.classList.remove('is_active');
document.querySelector(`[data-heading="${activeId}"]`)?.classList.add('is_active');
}, [activeId, updateHeadingPositions]);

return (
<Layout className="documentation_page">
<Head>
<title>Documentation · Yorkie</title>
</Head>
<div className="content">
<Navigator navList={navList} />
<section className="section">{source}</section>
</div>
</Layout>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/calendar/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CalendarPage from './calendar-page';

export default async function Page() {
return <CalendarPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/codemirror/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CodeMirrorPage from './codemirror-page';

export default async function Page() {
return <CodeMirrorPage />;
}
2 changes: 2 additions & 0 deletions pages/examples/index.tsx → app/examples/example-page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { Button, Icon, Layout } from '@/components';
import { ExampleThumbnailImage } from '@/components/exampleView';
import ExampleBannerSVG from '@/public/assets/images/banner/img_example_banner.svg';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout, CodeBlock } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/kanban/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import KanbanPage from './kanban-page';

export default async function Page() {
return <KanbanPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useState } from 'react';
import type { NextPage } from 'next';
import Head from 'next/head';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/multi-cursor/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MultiCursorPage from './multi-cursor-page';

export default async function Page() {
return <MultiCursorPage />;
}
5 changes: 5 additions & 0 deletions app/examples/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ExamplesPage from './example-page';

export default async function Page() {
return <ExamplesPage />;
}
5 changes: 5 additions & 0 deletions app/examples/profile-stack/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ProfileStackPage from './profile-stack-page';

export default async function Page() {
return <ProfileStackPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/quill/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QuillPage from './quill-page';

export default async function Page() {
return <QuillPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/simultaneous-cursors/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SimultaneousCursorsPage from './simultaneous-cursors-page';

export default async function Page() {
return <SimultaneousCursorsPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/tldraw/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import TldrawPage from './tldraw-page';

export default async function Page() {
return <TldrawPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
Expand Down
5 changes: 5 additions & 0 deletions app/examples/todomvc/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import TodomvcPage from './todomvc-page';

export default async function Page() {
return <TodomvcPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { ExampleLayout } from '@/components';
import {
BasicExampleView,
Expand Down
5 changes: 5 additions & 0 deletions app/examples/webtoons/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import WebtoonsPage from './webtoons-page';

export default async function Page() {
return <WebtoonsPage />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useState } from 'react';
import type { NextPage } from 'next';
import Head from 'next/head';
Expand Down
2 changes: 2 additions & 0 deletions pages/index.tsx → app/home-page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useState, useEffect } from 'react';
import classNames from 'classnames';
import type { NextPage } from 'next';
Expand Down
Loading
Loading