-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start migrating to nextjs app router (#1976)
- Loading branch information
Showing
19 changed files
with
218 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
export function DocSearch() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import { useState, useEffect } from 'react'; | ||
import Link from 'next/link'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
type InstallSpace = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import { Fragment, useReducer } from 'react'; | ||
|
||
import { InterfaceDef, CallSigDef } from './Defs'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { DocHeader } from '../../../../DocHeader'; | ||
import { ImmutableConsole } from '../../../../ImmutableConsole'; | ||
import { getSidebarLinks } from '../../../../getSidebarLinks'; | ||
import { getTypeDefs } from '../../../../static/getTypeDefs'; | ||
import { getVersions } from '../../../../static/getVersions'; | ||
import { TypeDocumentation } from '../../../../TypeDocumentation'; | ||
import { getVersionFromParams } from '../../../getVersionFromParams'; | ||
|
||
export async function generateStaticParams() { | ||
return getVersions() | ||
.map(version => | ||
Object.values(getTypeDefs(version).types).map(def => ({ | ||
version, | ||
type: def.label, | ||
})) | ||
) | ||
.flat(); | ||
} | ||
|
||
type Params = { | ||
version: string; | ||
type: string; | ||
}; | ||
|
||
type Props = { | ||
params: Params; | ||
}; | ||
|
||
export async function generateMetadata({ params }: Props) { | ||
const version = getVersionFromParams(params); | ||
const defs = getTypeDefs(version); | ||
const def = Object.values(defs.types).find(d => d.label === params.type); | ||
|
||
if (!def) { | ||
throw new Error('404'); | ||
} | ||
|
||
return { | ||
title: `${def.qualifiedName} — Immutable.js`, | ||
}; | ||
} | ||
|
||
export default function TypeDocPage({ | ||
// versions, | ||
// version, | ||
// def, | ||
// sidebarLinks, | ||
params, | ||
}: Props) { | ||
const versions = getVersions(); | ||
const version = getVersionFromParams(params); | ||
const defs = getTypeDefs(version); | ||
|
||
const def = Object.values(defs.types).find(d => d.label === params.type); | ||
|
||
if (!def) { | ||
throw new Error('404'); | ||
} | ||
|
||
const sidebarLinks = getSidebarLinks(defs); | ||
return ( | ||
<div> | ||
<ImmutableConsole version={version} /> | ||
<DocHeader versions={versions} currentVersion={version} /> | ||
<div className="pageBody"> | ||
<div className="contents"> | ||
<TypeDocumentation def={def} sidebarLinks={sidebarLinks} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
62 changes: 19 additions & 43 deletions
62
website/src/pages/docs/[version]/index.tsx → website/src/app/docs/[version]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Metadata } from 'next'; | ||
import { getVersions } from '../../static/getVersions'; | ||
import RedirectExistingDocs from './redirect-client'; | ||
import { ImmutableConsole } from '../../ImmutableConsole'; | ||
import { DocHeader } from '../../DocHeader'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'Documentation — Immutable.js', | ||
}; | ||
|
||
export default function Page() { | ||
const versions = getVersions(); | ||
|
||
const latestVersion = versions[0]; | ||
|
||
if (!latestVersion) { | ||
throw new Error('No versions'); | ||
} | ||
|
||
return ( | ||
<div> | ||
<ImmutableConsole version={latestVersion} /> | ||
<DocHeader versions={versions} currentVersion={latestVersion} /> | ||
<div className="pageBody"> | ||
<div className="contents"> | ||
<RedirectExistingDocs version={latestVersion} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
type Props = { | ||
version: string; | ||
}; | ||
|
||
export default function RedirectExistingDocs({ version }: Props) { | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
const [, type, member] = window.location.hash?.split('/') || []; | ||
let route = `/docs/${version}`; | ||
if (type) { | ||
route += `/${type}`; | ||
} | ||
if (member) { | ||
route += `#${member}`; | ||
} | ||
router.replace(route); | ||
}, [version, router]); | ||
|
||
return <div className="contents">Redirecting...</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getVersionFromParams(params: { version: string }): string { | ||
return params.version.replace('%40', '@'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Metadata } from 'next'; | ||
import React from 'react'; | ||
import '../../styles/globals.css'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'Immutable.js', | ||
icons: { | ||
icon: '/favicon.png', | ||
}, | ||
}; | ||
|
||
export default function RootLayout({ | ||
// Layouts must accept a children prop. | ||
// This will be populated with nested layouts or pages | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,27 @@ | ||
import fs from 'fs'; | ||
import Head from 'next/head'; | ||
|
||
import { Header } from '../Header'; | ||
import { MarkdownContent } from '../MarkdownContent'; | ||
import { ImmutableConsole } from '../ImmutableConsole'; | ||
import { MarkdownContent } from '../MarkdownContent'; | ||
import { genMarkdownDoc } from '../static/genMarkdownDoc'; | ||
import { getVersions } from '../static/getVersions'; | ||
|
||
type Props = { | ||
versions: Array<string>; | ||
readme: string; | ||
}; | ||
|
||
export async function getStaticProps(): Promise<{ props: Props }> { | ||
const versions = getVersions(); | ||
export default async function Page() { | ||
const versions = await getVersions(); | ||
const readme = genMarkdownDoc( | ||
versions[0], | ||
fs.readFileSync(`../README.md`, 'utf8') | ||
); | ||
return { props: { versions, readme } }; | ||
} | ||
|
||
export default function Home({ versions, readme }: Props) { | ||
return ( | ||
<div> | ||
<Head> | ||
<title>Immutable.js</title> | ||
</Head> | ||
<> | ||
<ImmutableConsole version={versions[0]} /> | ||
<Header versions={versions} /> | ||
|
||
<div className="pageBody"> | ||
<div className="contents"> | ||
<MarkdownContent contents={readme} /> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { TypeDefs } from './TypeDefs'; | ||
import { SidebarLinks } from './Sidebar'; | ||
|
||
export function getSidebarLinks(defs: TypeDefs): SidebarLinks { | ||
return Object.values(defs.types).map(({ label, url }) => ({ label, url })); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.