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 all 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
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
uses: ./.github/actions/detect-package-manager
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: '20'
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages@v2
Expand All @@ -42,10 +42,8 @@ jobs:
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Optimize all static images after the Next.js static export
run: ${{ steps.detect-package-manager.outputs.runner }} next-image-export-optimizer
run: ${{ steps.detect-package-manager.outputs.runner }} next-image-export-optimizer
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Deploy Next.js site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -20,7 +20,7 @@ permissions:

# Allow one concurrent deployment
concurrency:
group: "pages"
group: 'pages'
cancel-in-progress: true

jobs:
Expand All @@ -29,14 +29,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
uses: ./.github/actions/detect-package-manager
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: '20'
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages@v2
Expand All @@ -60,10 +60,8 @@ jobs:
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Optimize all static images after the Next.js static export
run: ${{ steps.detect-package-manager.outputs.runner }} next-image-export-optimizer
run: ${{ steps.detect-package-manager.outputs.runner }} next-image-export-optimizer
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
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 />;
}
149 changes: 149 additions & 0 deletions app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
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 { MDXRemote } 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 navList = getDocsOrderList('/docs');

return (
<SlugPage navList={navList} content={content}>
{/* @ts-expect-error Async Server Component */}
<MDXRemote
source={content}
components={components}
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,
}}
/>
</SlugPage>
);
}

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

return {
...meta,
};
}

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;
};
27 changes: 27 additions & 0 deletions app/docs/[[...slug]]/slug-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Head from 'next/head';
import { type DocsOrderList } from '@/utils/mdxUtils';
import { Layout, Navigator } from '@/components';
import ScrollPositionIndicator from '../_components/ScrollPositionIndicator';

export default function DocsPage({
content,
navList,
children,
}: {
content: string;
navList: DocsOrderList;
children: React.ReactNode;
}) {
return (
<Layout className="documentation_page">
<Head>
<title>Documentation · Yorkie</title>
</Head>
<ScrollPositionIndicator content={content} />
<div className="content">
<Navigator navList={navList} />
<section className="section">{children}</section>
</div>
</Layout>
);
}
59 changes: 59 additions & 0 deletions app/docs/_components/ScrollPositionIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';

import { useState, useEffect, useCallback } from 'react';

export default function ScrollPositionIndicator({ content }: { content: string }) {
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')));
}, [content]);

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 null;
}
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 />;
}
Loading
Loading