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

feat(docs): Gatsby への移行 #1384

Merged
merged 46 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
91cd0dc
Move assets
MikuroXina Sep 1, 2024
1176a27
Setup gatsby
MikuroXina Sep 1, 2024
c62f9a6
Move pages into posts
MikuroXina Sep 1, 2024
fdb6c52
Disable lint-staged
MikuroXina Sep 1, 2024
74fe2c7
Migrate and move posts
MikuroXina Sep 1, 2024
e01784f
Add css import type
MikuroXina Sep 1, 2024
94e9d0c
Remove next deps and add gatsby deps
MikuroXina Sep 1, 2024
269f81a
Update css import
MikuroXina Sep 1, 2024
7a1e4f0
Replace config with mjs due to ESM
MikuroXina Sep 1, 2024
5d04431
Remove next linter
MikuroXina Sep 1, 2024
11bcb7a
Implement tabs
MikuroXina Sep 1, 2024
5c4b1cc
Recover top index page
MikuroXina Sep 1, 2024
2cae1bc
Apply Layout for all pages
MikuroXina Sep 1, 2024
981380b
Add blockquote style
MikuroXina Sep 1, 2024
8890f0f
Add title in frontmatter
MikuroXina Sep 2, 2024
fefd53a
Move pages for create pages programmatically
MikuroXina Sep 2, 2024
17b6161
Remove exporting Layout
MikuroXina Sep 2, 2024
bc22a5a
Fix import path
MikuroXina Sep 2, 2024
23880bc
Implement page creation
MikuroXina Sep 2, 2024
0d534a7
Setup side bar
MikuroXina Sep 2, 2024
2fa232a
Add children links
MikuroXina Sep 2, 2024
b785439
Style table and border and beautify article
MikuroXina Sep 2, 2024
60fce4d
Add table of contents
MikuroXina Sep 2, 2024
48b402e
Fix scrolling behavior of skip link
MikuroXina Sep 2, 2024
f670e95
Fix jsx warning
MikuroXina Sep 2, 2024
b0b91b6
Remove search-bar
MikuroXina Sep 2, 2024
ea6cecb
Fix react warnings
MikuroXina Sep 2, 2024
bee87fb
Fix styles import error
MikuroXina Sep 2, 2024
f6244f5
Style code block
MikuroXina Sep 2, 2024
77d3ea7
Fix to forward props
MikuroXina Sep 2, 2024
07b2420
Refresh lock file
MikuroXina Sep 2, 2024
fae8e00
Align main content
MikuroXina Sep 3, 2024
afd7153
Style sidebar links
MikuroXina Sep 3, 2024
a601ee3
Use material design color system to support dark theme
MikuroXina Sep 3, 2024
5582900
Make icon rounded
MikuroXina Sep 3, 2024
1301817
Fix children page data
MikuroXina Sep 3, 2024
513cc60
Add padding to list item
MikuroXina Sep 3, 2024
c17d67a
Add navigation for commands
MikuroXina Sep 3, 2024
e56a158
Fix siblings data
MikuroXina Sep 3, 2024
8c35688
Write features index
MikuroXina Sep 3, 2024
910f3a1
Replace padding with margin
MikuroXina Sep 3, 2024
f9fdab5
Fix lint error
MikuroXina Sep 3, 2024
53443d1
Install eslint mdx plugin
MikuroXina Sep 3, 2024
0e3307a
Specify react version as detect
MikuroXina Sep 3, 2024
9474cdc
Fix lint errors
MikuroXina Sep 3, 2024
1d5f7a8
Fix wrong link
MikuroXina Sep 3, 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
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "8.57.0",
"eslint-config-next": "14.2.7",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-markdown": "^5.0.0",
Expand Down
11 changes: 9 additions & 2 deletions packages/docs/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
env:
browser: true
node: true
es2021: true
extends:
- 'next/core-web-vitals'
- 'prettier'
- plugin:mdx/recommended
- 'eslint:recommended'
- 'plugin:mdx/recommended'
- 'plugin:@typescript-eslint/recommended'
- 'plugin:react/recommended'
- 'plugin:mdx/recommended'
plugins:
- '@typescript-eslint'
- 'react'
rules:
'max-params': 'error'
settings:
'mdx/code-blocks': true
react:
version: 'detect'
root: true
3 changes: 3 additions & 0 deletions packages/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# gatsby built
.cache
public/
15 changes: 0 additions & 15 deletions packages/docs/.lintstagedrc.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/docs/.lintstagedrc.json

This file was deleted.

51 changes: 51 additions & 0 deletions packages/docs/gatsby-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @ts-check
// NOTE: this file must be a `.mjs` file due to that `remark-gfm` supports only ES Modules and the limitations of `gatsby-config`: https://www.gatsbyjs.com/docs/how-to/custom-configuration/es-modules/#current-limitations
import { dirname } from 'path';
import remarkGfm from 'remark-gfm';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

/**
* @type {import('gatsby').GatsbyConfig}
*/
const config = {
siteMetadata: {
title: 'OreOreBot2 Documents',
siteUrl: 'https://haracho.approvers.dev/'
},
graphqlTypegen: true,
plugins: [
{
resolve: 'gatsby-plugin-manifest',
options: {
icon: 'assets/haracho.png'
}
},
{
resolve: 'gatsby-plugin-mdx',
options: {
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-autolink-headers',
options: {
offsetY: '78'
}
}
],
mdxOptions: {
remarkPlugins: [remarkGfm]
}
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'pages',
path: `${__dirname}/pages`
}
}
]
};

export default config;
101 changes: 101 additions & 0 deletions packages/docs/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import type { GatsbyNode } from 'gatsby';
import path from 'node:path';

import { Page } from './src/types';

export const createPages: GatsbyNode['createPages'] = async (api) => {
// get mdx pages
type Content = {
url: string;
title: string;
items?: Content[];
};
const res = await api.graphql<{
allMdx: {
nodes: {
body: string;
tableOfContents: {
items?: Content[];
};
parent: {
dir: string;
relativePath: string;
absolutePath: string;
};
frontmatter: {
title: string;
};
}[];
};
}>(`
{
allMdx {
nodes {
body
tableOfContents
parent {
... on File {
dir
relativePath
absolutePath
}
}
frontmatter {
title
}
}
}
}
`);
if (res.errors) {
api.reporter.panicOnBuild('querying mdx pages failed');
return;
}

const pages = res.data?.allMdx.nodes!.map(
({
body,
parent: { dir, relativePath, absolutePath },
frontmatter: { title },
tableOfContents
}): Page => ({
body,
dir,
uri: '/' + relativePath.replace(/(index)?\.mdx$/, ''),
absolutePath,
title,
headings: tableOfContents.items
})
);

// group pages by its directory
const childrenByPath: Record<string, Page[]> = {};
for (const page of pages) {
const superPath = page.absolutePath.endsWith('/index.mdx')
? path.dirname(page.dir)
: page.dir;
if (!childrenByPath[superPath]) {
childrenByPath[superPath] = [];
}
childrenByPath[superPath].push(page);
}

const componentPath = path.resolve('src/templates/entry.jsx');
for (const page of pages) {
const { body, dir, uri, absolutePath, title, headings } = page;

const siblings = childrenByPath[path.dirname(dir)] ?? [];
const children = childrenByPath[dir] ?? [];
api.actions.createPage({
path: uri,
component: `${componentPath}?__contentFilePath=${absolutePath}`,
context: {
body,
title,
siblings,
children,
headings
}
});
}
};
19 changes: 0 additions & 19 deletions packages/docs/next.config.js

This file was deleted.

32 changes: 20 additions & 12 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{
"name": "@oreorebot2/docs",
"version": "1.0.0",
"main": "index.js",
"private": true,
"repository": "https://github.com/approvers/OreOreBot2",
"author": "approvers <[email protected]>",
"description": "新生はらちょドキュメントサイト",
"license": "MIT",
"scripts": {
"dev": "next dev",
"build": "next build",
"lint": "next lint",
"format": "prettier --write \"./src/**/*.{js,ts,jsx,tsx,md,mdx}\"",
"lint-staged": "lint-staged"
"dev": "gatsby develop",
"build": "gatsby build",
"lint": "eslint --ignore-path .gitignore \"./{src,pages}/**/*.{js,ts,jsx,tsx,md,mdx}\"",
"format": "prettier --write \"./{src,pages}/**/*.{js,ts,jsx,tsx,md,mdx}\""
},
"dependencies": {
"next": "^14.0.0",
"nextra": "^2.2.14",
"nextra-theme-docs": "^2.2.14",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"@mdx-js/mdx": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"gatsby": "^5.13.7",
"gatsby-omni-font-loader": "^2.0.2",
"gatsby-plugin-manifest": "^5.13.1",
"gatsby-plugin-mdx": "^5.13.1",
"gatsby-remark-autolink-headers": "^6.13.1",
"gatsby-source-filesystem": "^5.13.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"remark-gfm": "^3.0.0"
},
"devDependencies": {
"@types/react": "18.2.60"
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint-plugin-mdx": "^3.1.5",
"eslint-plugin-react": "^7.35.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: 'EmojiSeq に新しい言葉を追加する'
---

# EmojiSeq に新しい言葉を追加する

このページでは、**ある特定の言葉に対して、予め設定していたリアクションを返す機能 EmojiSeq** に新しいパターンを追加する方法について紹介します。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: '開発ガイド'
---

# 開発ガイド

新生はらちょ 開発ガイドへようこそ
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Callout } from 'nextra-theme-docs';
---
title: '新しいミームを追加する'
---

# 新しいミームを追加する

Expand Down Expand Up @@ -50,11 +52,8 @@ export const n: MemeTemplate<never, never> = {
- `['hoge']` - `!hoge` というコマンドで実行できます。
- `['hoge', 'fuga']` - `!hoge``!fuga` というコマンドで実行できます。

<Callout type="warning">

他のミームとは重複しないようにしてください。

</Callout>
> [!WARNING]
> 他のミームとは重複しないようにしてください。
#### `MemeTemplate.description`

Expand All @@ -70,11 +69,8 @@ export const n: MemeTemplate<never, never> = {
};
```

<Callout type="info">

引数で変わるところを `` で表現するとわかりやすいです。

</Callout>
> [!TIP]
> 引数で変わるところを `` で表現するとわかりやすいです。
#### `MemeTemplate.flagsKeys`

Expand All @@ -84,13 +80,16 @@ export const n: MemeTemplate<never, never> = {
const takopiFlags = ['f'] as const;
const takopiOptions = ['c'] as const;
export const takopi: MemeTemplate<
typeof takopiFlags[number],
typeof takopiOptions[number]
(typeof takopiFlags)[number],
(typeof takopiOptions)[number]
> = {
commandNames: ['takopi'],
description:
'「〜、出して」\n`-f` で教員と自分の名前の位置を反対にします。\n`-c <教員の名前> <出すもの>`で教員の名前も変更可能です。',
flagsKeys: takopiFlags,
optionsKeys: takopiOptions
// ...
};
```

#### `MemeTemplate.optionsKeys`
Expand All @@ -101,14 +100,16 @@ export const takopi: MemeTemplate<
const takopiFlags = ['f'] as const;
const takopiOptions = ['c'] as const;
export const takopi: MemeTemplate<
typeof takopiFlags[number],
typeof takopiOptions[number]
(typeof takopiFlags)[number],
(typeof takopiOptions)[number]
> = {
commandNames: ['takopi'],
description:
'「〜、出して」\n`-f` で教員と自分の名前の位置を反対にします。\n`-c <教員の名前> <出すもの>`で教員の名前も変更可能です。',
flagsKeys: takopiFlags,
optionsKeys: takopiOptions,
optionsKeys: takopiOptions
// ...
};
```

#### `MemeTemplate.errorMessage`
Expand All @@ -121,7 +122,9 @@ export const n: MemeTemplate<never, never> = {
description: '〜Nった',
flagsKeys: [],
optionsKeys: [],
errorMessage: 'このままだと <@521958252280545280> みたいに留年しちゃう....',
errorMessage: 'このままだと <@521958252280545280> みたいに留年しちゃう....'
// ...
};
```

### ミームを登録する
Expand Down
Loading