Skip to content

Commit

Permalink
Merge pull request #19 from WTFAcademy/dev
Browse files Browse the repository at this point in the history
fix doc plugin match prop and update doc
  • Loading branch information
chongqiangchen authored Apr 18, 2023
2 parents 9e5a3d7 + ec18ff9 commit 18ecc08
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-pears-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solive-docusaurus-theme-code": patch
---

fix match props error
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
'class-methods-use-this': 'off',
radix: 'off',
'guard-for-in': 'off',
'max-len': ['error', { code: 150 }],
'max-len': ['error', { code: 250 }],

// TypeScript 相关
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/relesae.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
paths-ignore:
- 'apps/**'

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand Down
32 changes: 29 additions & 3 deletions apps/demo/craco.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cracoAlias = require("craco-alias");
const nodeExternals = require('webpack-node-externals');
const webpack = require("webpack");

module.exports = {
style: {
Expand All @@ -21,8 +21,34 @@ module.exports = {
],
webpack: {
configure: (webpackConfig, { env, paths }) => {
webpackConfig.externalsPresets = {node: true};
webpackConfig.externals = [nodeExternals()];
// eslint-disable-next-line no-param-reassign
webpackConfig.resolve.fallback = {
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"zlib": require.resolve("browserify-zlib"),
"stream": require.resolve("stream-browserify"),
"events": require.resolve("events/"),
"crypto": require.resolve("crypto-browserify"),
"assert": require.resolve("assert/"),
"buffer": require.resolve("buffer/"),
"util": require.resolve("util/"),
"path": require.resolve("path-browserify"),
"tty": require.resolve("tty-browserify"),
"os": require.resolve("os-browserify/browser"),
"punycode": require.resolve("punycode/"),
"fs": false,
"url": require.resolve("url/"),
"net": require.resolve("net-browserify"),
"child_process": false,
async_hooks: false,
rawBody: false,
};

webpackConfig.plugins.push(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"]
})
);
return webpackConfig;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: Docusaurus 插件
title: 引导
hide_title: true
slug: /docusaurus-plugins
---


## Docusaurus 插件

> 你可以使用 `solive-docusaurus-theme-code` 插件快速集成一个轻量级Solidity Editor嵌入你的文档.
> 你可以使用 `solive-docusaurus-theme-code` 插件快速集成一个轻量级Solidity Editor嵌入你的文档. (完善中)
### 安装

Expand All @@ -27,22 +29,22 @@ module.exports = {
### 快速使用

1. 你需要注意在代码块标记solive,和配置solive的属性:
```md
```solidity solive height=300px
````md
```solidity solive height=500px
// your code
```\
```
```
````

2. 你可以在代码块中配置solive相关属性 `height`(具体参考[属性表](/docs/solive-props)):
```md
2. 你可以在代码块中配置solive相关属性 `height`(具体参考[属性表](/docs/docusaurus-plugins/props)):
````md
```solidity solive height=300px
// your code
```\
```
```
````

3. 配置代码块文件名(可多文件):
```md
```solidity solive height=300px
````md
```solidity solive height=500px
/**
* @filename Storage.sol
*/
Expand All @@ -54,12 +56,12 @@ module.exports = {
*/

// your code
```\
```
```
````

3. 完整的代码块示例:
````md
```solidity solive height=300px
```solidity solive height=500px
/**
* @filename Storage.sol
*/
Expand Down Expand Up @@ -94,12 +96,12 @@ contract Storage {
return number;
}
}
```\
```
````

### 展示结果:

```solidity solive height=300px
```solidity solive height=500px
/**
* @filename Storage.sol
*/
Expand Down
21 changes: 21 additions & 0 deletions apps/doc/docs/expansion/docusaurus-plugins/props.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: 属性
slug: /docusaurus-plugins/props
hide_title: true
---

## 属性

> 注意:考虑对参数匹配的准确性和文档UI适应性,部分Solive的属性默认值有所变动,并增加和变动一些新的属性
| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| width | string | 90% | 容器宽度 |
| height | string | 500px | 容器高度 |
| consoleOpen | boolean | true | 是否显示控制台 |
| consoleTriggerControl | boolean | false | 是否显示控制台触发按钮 |
| consoleDefaultVisible | boolean | false | 控制台默认是否可见 |
| deployOpen | boolean | true | 是否显示部署 |
| deployDefaultVisible | boolean | false | 部署默认是否可见 |
| fileNavOpen | boolean | true | 是否显示文件导航栏 |
| fileNavDefaultVisible | boolean | false | 文件导航栏默认是否可见 |
38 changes: 32 additions & 6 deletions apps/doc/docs/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,42 @@ pnpm install solive-core

```js
// 使用craco配置:
const nodeExternals = require('webpack-node-externals');
const webpack = require("webpack");

module.exports = {
// ...
webpack: {
configure: (webpackConfig, { env, paths }) => {
webpackConfig.externalsPresets = {node: true};
webpackConfig.externals = [nodeExternals()];
return webpackConfig;
}
configure: (webpackConfig, { env, paths }) => {
// eslint-disable-next-line no-param-reassign
webpackConfig.resolve.fallback = {
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"zlib": require.resolve("browserify-zlib"),
"stream": require.resolve("stream-browserify"),
"events": require.resolve("events/"),
"crypto": require.resolve("crypto-browserify"),
"assert": require.resolve("assert/"),
"buffer": require.resolve("buffer/"),
"util": require.resolve("util/"),
"path": require.resolve("path-browserify"),
"tty": require.resolve("tty-browserify"),
"os": require.resolve("os-browserify/browser"),
"punycode": require.resolve("punycode/"),
"fs": false,
"url": require.resolve("url/"),
"net": require.resolve("net-browserify"),
"child_process": false,
async_hooks: false,
rawBody: false,
};

webpackConfig.plugins.push(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"]
})
);
return webpackConfig;
}
}
};

Expand Down
15 changes: 9 additions & 6 deletions packages/docusaurus-plugin/src/theme/utils/match-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ export const coerceValue = (value: string, type: TPropType) => {
};

export const matchProps = (metaString: string, propsInfo: TPropsInfo): TResultProps => {
const dynamicRex = /(?<key>[^=]+)="(?<value>[^"]*)"/g;
const props: any = {};
const dynamicRex = /(?<key>[^=\s]+)=(?:"(?<value1>[^"]*)"|'(?<value2>[^']*)'|(?<value3>[^\s]*))/g;
const props: TResultProps = {};
let match;
// eslint-disable-next-line no-cond-assign
while ((match = dynamicRex.exec(metaString)) !== null) {
const { key, value } = match.groups as any;
const keyName = key.trim();
if (propsInfo[keyName]) {
props[keyName] = coerceValue(value, propsInfo[keyName].type);
const { groups } = match;
if (groups) {
const key = groups.key.trim();
const value = groups.value1 || groups.value2 || groups.value3;
if (propsInfo[key]) {
props[key] = value;
}
}
}

Expand Down

2 comments on commit 18ecc08

@vercel
Copy link

@vercel vercel bot commented on 18ecc08 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 18ecc08 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solive-doc – ./

solive-doc.vercel.app
solive-doc-wtfacademy.vercel.app
solive-doc-git-main-wtfacademy.vercel.app

Please sign in to comment.