mirror of
https://github.com/kou029w/_.git
synced 2025-01-31 06:18:07 +00:00
Add 'next/' from commit '19b6c91e86e4f86870096802cb8f3122531013b0'
git-subtree-dir: next git-subtree-mainline:5d936d154e
git-subtree-split:19b6c91e86
This commit is contained in:
commit
90bb5008c5
21 changed files with 7089 additions and 0 deletions
16
next/.github/workflows/build.yml
vendored
Normal file
16
next/.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
name: build
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
main:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- id: yarn_cache
|
||||||
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ steps.yarn_cache.outputs.dir }}
|
||||||
|
key: yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: yarn-
|
||||||
|
- run: yarn
|
||||||
|
- run: yarn build
|
25
next/.github/workflows/docs.yml
vendored
Normal file
25
next/.github/workflows/docs.yml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
name: github-pages
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
jobs:
|
||||||
|
main:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
EMAIL: octocat@github.com
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- run: echo "::set-env name=YARN_CACHE_DIR::$(yarn cache dir)"
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ env.YARN_CACHE_DIR }}
|
||||||
|
key: yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: yarn-
|
||||||
|
- run: yarn
|
||||||
|
- run: git -c user.name="$(whoami)" subtree add --prefix docs origin gh-pages
|
||||||
|
- run: NEXT_PUBLIC_BASE_PATH=/${GITHUB_REPOSITORY#*/} yarn doc
|
||||||
|
- run: git add -f docs
|
||||||
|
- run: git -c user.name="$(whoami)" commit -m github-pages
|
||||||
|
- run: git remote add github "https://github:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
|
||||||
|
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
- run: git subtree push --prefix docs github gh-pages
|
3
next/.gitignore
vendored
Normal file
3
next/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/node_modules/
|
||||||
|
/.next/
|
||||||
|
/docs/
|
2
next/next-env.d.ts
vendored
Normal file
2
next/next-env.d.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/// <reference types="next" />
|
||||||
|
/// <reference types="next/types/global" />
|
6
next/next.config.js
Normal file
6
next/next.config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = require("@next/mdx")({
|
||||||
|
extension: /\.mdx?$/,
|
||||||
|
})({
|
||||||
|
pageExtensions: ["ts", "tsx", "md", "mdx"],
|
||||||
|
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "",
|
||||||
|
});
|
28
next/package.json
Normal file
28
next/package.json
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"name": "next-example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"author": "Kohei Watanabe <kou029w@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@material-ui/core": "~4",
|
||||||
|
"@material-ui/icons": "~4",
|
||||||
|
"@material-ui/styles": "~4",
|
||||||
|
"@mdx-js/loader": "~2.0.0-next",
|
||||||
|
"@next/mdx": "~9",
|
||||||
|
"next": "~9",
|
||||||
|
"react": "~16",
|
||||||
|
"react-dom": "~16"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "~12",
|
||||||
|
"npm-run-all": "~4",
|
||||||
|
"typescript": "~3.9.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"doc": "run-s build doc:export",
|
||||||
|
"doc:export": "next export -o docs",
|
||||||
|
"build": "next build",
|
||||||
|
"dev": "next"
|
||||||
|
}
|
||||||
|
}
|
14
next/pages/_app.tsx
Normal file
14
next/pages/_app.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import React from "react";
|
||||||
|
import App from "next/app";
|
||||||
|
import MainTheme from "../styles/MainTheme";
|
||||||
|
|
||||||
|
export default class extends App {
|
||||||
|
render() {
|
||||||
|
const { Component, pageProps } = this.props;
|
||||||
|
return (
|
||||||
|
<MainTheme>
|
||||||
|
<Component {...pageProps} />
|
||||||
|
</MainTheme>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
41
next/pages/_document.tsx
Normal file
41
next/pages/_document.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import React from "react";
|
||||||
|
import Document, {
|
||||||
|
DocumentContext,
|
||||||
|
DocumentInitialProps,
|
||||||
|
Html,
|
||||||
|
Head,
|
||||||
|
Main,
|
||||||
|
NextScript,
|
||||||
|
} from "next/document";
|
||||||
|
import { ServerStyleSheets } from "@material-ui/styles";
|
||||||
|
import { theme } from "../styles/MainTheme";
|
||||||
|
export default class extends Document {
|
||||||
|
static getInitialProps = async (ctx: DocumentContext) => {
|
||||||
|
const sheets = new ServerStyleSheets();
|
||||||
|
const originalRenderPage = ctx.renderPage;
|
||||||
|
ctx.renderPage = () =>
|
||||||
|
originalRenderPage({
|
||||||
|
enhanceApp: (App) => (props) => sheets.collect(<App {...props} />),
|
||||||
|
});
|
||||||
|
const initialProps = await Document.getInitialProps(ctx);
|
||||||
|
return {
|
||||||
|
...initialProps,
|
||||||
|
styles: [initialProps.styles, sheets.getStyleElement()],
|
||||||
|
} as DocumentInitialProps;
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Html lang="ja" dir="ltr">
|
||||||
|
<Head>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<meta name="theme-color" content={theme.palette.primary.main} />
|
||||||
|
</Head>
|
||||||
|
<body>
|
||||||
|
<Main />
|
||||||
|
<NextScript />
|
||||||
|
</body>
|
||||||
|
</Html>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
11
next/pages/about.md
Normal file
11
next/pages/about.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# About
|
||||||
|
|
||||||
|
Next.js、MDX、Material-UI の組み合わせで作ってみたサンプルページ。
|
||||||
|
|
||||||
|
## ソースコード
|
||||||
|
|
||||||
|
[https://github.com/kou029w/next-example](https://github.com/kou029w/next-example)
|
||||||
|
|
||||||
|
## ライセンス
|
||||||
|
|
||||||
|
MIT
|
4
next/pages/api/headers.ts
Normal file
4
next/pages/api/headers.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
export const handler = (req: NextApiRequest, res: NextApiResponse) =>
|
||||||
|
res.json(req.headers);
|
||||||
|
export default handler;
|
4
next/pages/api/query/[path].ts
Normal file
4
next/pages/api/query/[path].ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
export const handler = (req: NextApiRequest, res: NextApiResponse) =>
|
||||||
|
res.json(req.query);
|
||||||
|
export default handler;
|
6
next/pages/index.md
Normal file
6
next/pages/index.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import Todo from "./todo"
|
||||||
|
|
||||||
|
# Hello Next.js
|
||||||
|
|
||||||
|
- [About](/about)
|
||||||
|
- [ToDo List](/todo)
|
14
next/pages/query/[path].tsx
Normal file
14
next/pages/query/[path].tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
|
export function getStaticPaths() {
|
||||||
|
return { paths: [{ params: { path: "test" } }], fallback: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStaticProps({ params }: { params: unknown }) {
|
||||||
|
return { props: params };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ({ path }: { path: string }) {
|
||||||
|
const { query } = useRouter();
|
||||||
|
return <pre>{JSON.stringify({ path, ...query }, null, " ")}</pre>;
|
||||||
|
}
|
78
next/pages/todo.tsx
Normal file
78
next/pages/todo.tsx
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import React, { FormEvent } from "react";
|
||||||
|
import { MDXContext } from "@mdx-js/react";
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
id: number;
|
||||||
|
todo: Map<number, string>;
|
||||||
|
};
|
||||||
|
type Action =
|
||||||
|
| {
|
||||||
|
type: "add";
|
||||||
|
body: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "delete";
|
||||||
|
key: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialState: State = {
|
||||||
|
id: 0,
|
||||||
|
todo: new Map(),
|
||||||
|
};
|
||||||
|
|
||||||
|
function reducer(state: State, action: Action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case "add":
|
||||||
|
state.todo.set(state.id, action.body);
|
||||||
|
return { ...state, id: state.id + 1 };
|
||||||
|
case "delete":
|
||||||
|
state.todo.delete(action.key);
|
||||||
|
return { ...state };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const { components } = React.useContext(MDXContext);
|
||||||
|
const [state, dispatch] = React.useReducer(reducer, initialState);
|
||||||
|
const onSubmit = React.useCallback(
|
||||||
|
(event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const body =
|
||||||
|
new FormData(event.currentTarget as HTMLFormElement)
|
||||||
|
.get("body")
|
||||||
|
?.toString() || "";
|
||||||
|
if (body.length === 0) return;
|
||||||
|
dispatch({
|
||||||
|
type: "add",
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
const H1 = components?.h1 ?? "h1";
|
||||||
|
const Ul = components?.ul ?? "ul";
|
||||||
|
const Li = components?.li ?? "li";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<H1>ToDo List</H1>
|
||||||
|
<form onSubmit={onSubmit}>
|
||||||
|
<input type="text" key={state.id} name="body" autoFocus />
|
||||||
|
<input type="submit" name="submit" value="+" />
|
||||||
|
</form>
|
||||||
|
<Ul>
|
||||||
|
{[...state.todo].map(([key, body]) => (
|
||||||
|
<Li key={key}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name={`${key}-checkbox`}
|
||||||
|
onChange={() => dispatch({ type: "delete", key })}
|
||||||
|
/>
|
||||||
|
{body}
|
||||||
|
</Li>
|
||||||
|
))}
|
||||||
|
</Ul>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
0
next/public/.nojekyll
Normal file
0
next/public/.nojekyll
Normal file
5
next/renovate.json
Normal file
5
next/renovate.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"extends": ["config:base"],
|
||||||
|
"rangeStrategy": "update-lockfile",
|
||||||
|
"automerge": true
|
||||||
|
}
|
8
next/routes.ts
Normal file
8
next/routes.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { createElement } from "react";
|
||||||
|
import { Home, Info } from "@material-ui/icons";
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{ pathname: "/", icon: createElement(Home) },
|
||||||
|
{ pathname: "/about", icon: createElement(Info) },
|
||||||
|
];
|
||||||
|
export default routes;
|
74
next/styles/MainTheme.tsx
Normal file
74
next/styles/MainTheme.tsx
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
import React, { ReactElement } from "react";
|
||||||
|
import { ThemeProvider } from "@material-ui/styles";
|
||||||
|
import { createMuiTheme } from "@material-ui/core/styles";
|
||||||
|
import { orange, teal } from "@material-ui/core/colors";
|
||||||
|
import Typography from "@material-ui/core/Typography";
|
||||||
|
import MuiLink from "@material-ui/core/Link";
|
||||||
|
import Box from "@material-ui/core/Box";
|
||||||
|
import Container from "@material-ui/core/Container";
|
||||||
|
import { MDXProvider, ComponentDictionary } from "@mdx-js/react";
|
||||||
|
import Head from "next/head";
|
||||||
|
import Link from "next/link";
|
||||||
|
import TopAppBar from "./TopAppBar";
|
||||||
|
|
||||||
|
const isValidURL = (url: string) => {
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const theme = createMuiTheme({
|
||||||
|
palette: {
|
||||||
|
primary: {
|
||||||
|
main: orange[900],
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
main: teal[400],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typography: {
|
||||||
|
fontFamily: "sans-serif",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const components: ComponentDictionary = {
|
||||||
|
h1: (props) => (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{props.children}</title>
|
||||||
|
</Head>
|
||||||
|
<Typography component="h1" variant="h3" {...props} />
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
h2: (props) => <Typography component="h2" variant="h4" {...props} />,
|
||||||
|
h3: (props) => <Typography component="h3" variant="h5" {...props} />,
|
||||||
|
h4: (props) => <Typography component="h4" variant="h6" {...props} />,
|
||||||
|
h5: (props) => <Typography component="h5" variant="h6" {...props} />,
|
||||||
|
h6: (props) => <Typography variant="h6" {...props} />,
|
||||||
|
a: ({ href, ...props }: { href: string }) => {
|
||||||
|
const url = [process.env.NEXT_PUBLIC_BASE_PATH, href].join("");
|
||||||
|
return isValidURL(href) ? (
|
||||||
|
<MuiLink variant="body1" color="secondary" href={href} {...props} />
|
||||||
|
) : (
|
||||||
|
<Link href={href}>
|
||||||
|
<MuiLink variant="body1" color="secondary" href={url} {...props} />
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
p: (props) => <Typography component="p" variant="body1" {...props} />,
|
||||||
|
};
|
||||||
|
|
||||||
|
const MainTheme = (props: { children: ReactElement }) => (
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<MDXProvider components={components}>
|
||||||
|
<TopAppBar />
|
||||||
|
<Box paddingTop={6}>
|
||||||
|
<Container>{props.children}</Container>
|
||||||
|
</Box>
|
||||||
|
</MDXProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
export default MainTheme;
|
53
next/styles/TopAppBar.tsx
Normal file
53
next/styles/TopAppBar.tsx
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
import React from "react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import Link from "next/link";
|
||||||
|
import AppBar from "@material-ui/core/AppBar";
|
||||||
|
import Tabs from "@material-ui/core/Tabs";
|
||||||
|
import Tab from "@material-ui/core/Tab";
|
||||||
|
import routes from "../routes";
|
||||||
|
|
||||||
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
|
||||||
|
|
||||||
|
const TopAppBar = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const currentPathname = React.useMemo(
|
||||||
|
() =>
|
||||||
|
router.pathname.startsWith(basePath)
|
||||||
|
? router.pathname.slice(basePath.length)
|
||||||
|
: router.pathname,
|
||||||
|
[router.pathname]
|
||||||
|
);
|
||||||
|
const tabPathname = React.useMemo(
|
||||||
|
() =>
|
||||||
|
routes.reduce(
|
||||||
|
(prev, { pathname }) =>
|
||||||
|
pathname === currentPathname ? pathname : prev,
|
||||||
|
"/"
|
||||||
|
),
|
||||||
|
[currentPathname]
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<AppBar color="default">
|
||||||
|
<Tabs
|
||||||
|
value={tabPathname}
|
||||||
|
variant="fullWidth"
|
||||||
|
indicatorColor="primary"
|
||||||
|
textColor="primary"
|
||||||
|
>
|
||||||
|
{routes.map(({ pathname, icon }, index) => (
|
||||||
|
<Tab
|
||||||
|
key={index}
|
||||||
|
value={pathname}
|
||||||
|
icon={icon}
|
||||||
|
component={React.forwardRef<HTMLAnchorElement, {}>((props, ref) => (
|
||||||
|
<Link href={pathname}>
|
||||||
|
<a ref={ref} href={[basePath, pathname].join("")} {...props} />
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tabs>
|
||||||
|
</AppBar>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default TopAppBar;
|
26
next/tsconfig.json
Normal file
26
next/tsconfig.json
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"downlevelIteration": true
|
||||||
|
},
|
||||||
|
"exclude": ["node_modules"],
|
||||||
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
|
||||||
|
}
|
6671
next/yarn.lock
Normal file
6671
next/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue