Skip to content

Commit

Permalink
feat: implement docusaurus for MetaMask
Browse files Browse the repository at this point in the history
  • Loading branch information
ziad-saab committed Dec 14, 2022
0 parents commit 050557a
Show file tree
Hide file tree
Showing 33 changed files with 12,658 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"extends": [
"plugin:@docusaurus/recommended",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"@docusaurus",
"react",
"@typescript-eslint",
"eslint-plugin-unused-imports"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"jsx-quotes": [
"error",
"prefer-double"
],
"semi": [
"error",
"always"
],
"react/react-in-jsx-scope": 0,
"object-curly-spacing": ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"object-shorthand": ["error", "properties"]
}
}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"eslint.format.enable": true,
"eslint.packageManager": "yarn",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.codeActionsOnSave.mode": "all",
"editor.tabSize": 2,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifier": "non-relative"
}
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# MetaMask Docs

This is the MetaMask documentation repo. It's built on [Docusaurus](https://docusaurus.io/), a static site generator purpose-built for technical documentation.

## Features

Our instance of Docusaurus uses multiple of its powerful features, including:

* [Multi-instance](https://docusaurus.io/docs/docs-multi-instance): we have two instances of docs, one for the API & SDK, and one for Snaps
* [Versioning](https://docusaurus.io/docs/versioning): the Snaps documentation is exposed in two versions, "current" and "next". This allows us to send developers to either of these two versions based on whether they're using a nightly build of Flask, or the officially published extension
* [MDX](https://docusaurus.io/docs/markdown-features/react#importing-markdown)
* [Custom Sidebars](https://docusaurus.io/docs/sidebar): normally sidebars are auto-generated based on the docs directory structure. Having a custom sidebar allows us to define the order and inclusion of documentation items, with any hierarchy we want. The current proposed hierarchy is here: https://docs.google.com/spreadsheets/d/1fr1qnP830Zrdbzq0rPvoTVQsYBwL2Sq-wEJjL4tGfM8/edit

## MDX

### Tabs
Tabs are documented here: https://docusaurus.io/docs/markdown-features/tabs

#### Markdown in Tabs
One thing that's not documented is how to properly do Markdown inside tabs. For example, to properly embed a list inside a tab item, one has to skip lines around the JSX tags, and un-indent the list. Otherwise, the 4 spaces will be mistaken as the start of a pre-formatted block:

```jsx
<Tabs>
<TabItem value="apple" label="Apple" default>

- This is a markdown apple 🍎
- This is **meow**


</TabItem> {/* notice **two** skipped lines above*/}
<TabItem value="orange" label="Orange">
This is an orange 🍊
</TabItem>
<TabItem value="banana" label="Banana">
This is a banana 🍌
</TabItem>
</Tabs>
```
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Integrate with MetaMask (API & SDK)
93 changes: 93 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const codeTheme = require("prism-react-renderer/themes/dracula");

/** @type {import('@docusaurus/types').Config} */
const config = {
title: "MetaMask Docs",
// tagline: '',
url: "https://your-docusaurus-test-site.com",
baseUrl: "/",
onBrokenLinks: "throw",
onBrokenMarkdownLinks: "warn",
favicon: "img/metamask-fox.svg",

// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: "facebook", // Usually your GitHub org/user name.
projectName: "docusaurus", // Usually your repo name.

// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang. For example, if your site is Chinese, you may want
// to replace "en" with "zh-Hans".
i18n: {
defaultLocale: "en",
locales: ["en"],
},

presets: [
[
"classic",
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
path: "docs",
sidebarCollapsible: false,
},
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
}),
],
],
plugins: [
[
"content-docs",
/** @type {import('@docusaurus/plugin-content-docs').PluginOptions} */
({
id: "snaps",
path: "snaps",
routeBasePath: "snaps",
sidebarPath: require.resolve("./snaps-sidebars.js"),
sidebarCollapsible: false,
versions: {
production: {
label: "Current",
badge: false,
},
},
}),
],
],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
navbar: {
title: "MetaMask Docs",
logo: {
alt: "My Site Logo",
src: "img/metamask-fox.svg",
},
items: [
{
type: "doc",
docId: "index",
label: "SDK & API",
},
{
type: "doc",
docId: "index",
docsPluginId: "snaps",
label: "Snaps",
},
],
},
footer: {},
prism: {
theme: codeTheme,
},
}),
};

module.exports = config;
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "mm-docs-v-2",
"version": "0.0.0",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
},
"dependencies": {
"@docusaurus/core": "2.2.0",
"@docusaurus/preset-classic": "2.2.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@docusaurus/eslint-plugin": "^2.2.0",
"@docusaurus/module-type-aliases": "2.2.0",
"@tsconfig/docusaurus": "^1.0.5",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"eslint": "^8.26.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-unused-imports": "^2.0.0",
"typescript": "^4.7.4"
},
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"engines": {
"node": ">=16.14"
}
}
8 changes: 8 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-check

/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
docsSidebar: [{type: 'autogenerated', dirName: '.'}],
};

module.exports = sidebars;
44 changes: 44 additions & 0 deletions snaps-sidebars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Creating a sidebar enables you to:
- create an ordered group of docs
- render a sidebar for each doc of that group
- provide next/previous navigation
The sidebars can be generated from the filesystem, or explicitly defined here.
Create as many sidebars as you want.
*/

// @ts-check

/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
// By default, Docusaurus generates a sidebar from the docs folder structure
// snapsSidebar: [{type: 'autogenerated', dirName: '.'}],

// But you can create a sidebar manually
snapsSidebar: [
'index',
{
type: "category",
label: "How To",
link: { type: "generated-index" },
items: [
"how-to/guide",
"how-to/patching-dependencies",
]
},
{
type: "category",
label: "Reference",
link: { type: "generated-index" },
items: [
"reference/rpc-api",
"reference/permissions",
"reference/exports"
]
}
]
};

module.exports = sidebars;
Loading

0 comments on commit 050557a

Please sign in to comment.