Skip to content

Commit e416f1c

Browse files
committed
feat: Support markdown load img & add getting started.
1 parent 2e56247 commit e416f1c

File tree

54 files changed

+737
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+737
-543
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"====>": "<====",
66
"lib:build:type": "lerna exec --scope @uiw/react-native -- tsbb types",
77
"lib:build": "lerna exec --scope @uiw/react-native -- tsbb build",
8+
"lib:watch": "lerna exec --scope @uiw/react-native -- tsbb watch",
9+
"lib:watch:type": "lerna exec --scope @uiw/react-native -- tsbb types --watch",
810
"build": "npm run lib:build && npm run lib:build:type",
911
"start": "lerna exec --scope website -- npm run start",
1012
"doc": "lerna exec --scope website -- npm run build",

website/.kktrc.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export default (conf: Configuration, env: 'development' | 'production', options:
2020
VERSION: JSON.stringify(pkg.version),
2121
}),
2222
);
23-
if (env === 'production') {
24-
conf.output = { ...conf.output, publicPath: './' };
25-
}
23+
conf.output = { ...conf.output, publicPath: './' };
2624
return conf;
2725
};

website/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "website",
33
"version": "2.0.2",
44
"description": "Documentation site for React Native UIW.",
5-
"homepage": "https://uiwjs.github.io/react-native-uiw",
65
"private": true,
76
"scripts": {
87
"start": "kkt start",

website/src/assets/gitee.svg

Lines changed: 3 additions & 0 deletions
Loading

website/src/assets/github.svg

Lines changed: 4 additions & 0 deletions
Loading

website/src/component/Container/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
1010

1111
export default function Container(props: ContainerProps) {
1212
const { data, children, path } = props;
13-
console.log(props, path, path === '/home')
1413
return (
1514
<Fragment>
1615
<Header showBorder={path !== '/home'}/>

website/src/component/Contributors/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function AvatarList(props: { path: string}) {
3636
const fetchurl = `https://proapi.azurewebsites.net/doc/getAvatarList?filename=${path.replace(/^\//, '')}&owner=uiwjs&repo=react-native-uiw`;
3737
const res = useFetch<Response>(fetchurl);
3838
if (!res.response) {
39-
return <span className={styles.avatar}>Loading...</span>;
39+
return <span className={styles.avatar} />;
4040
}
4141
return (
4242
<span className={styles.avatar}>

website/src/component/Footer/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import styles from './index.module.less';
2-
import logo from '../../assets/logo-dark.svg';
2+
import { ReactComponent as Logo } from '../../assets/logo-dark.svg';
3+
import { ReactComponent as Github } from '../../assets/github.svg';
4+
import { ReactComponent as Gitee } from '../../assets/gitee.svg';
35

46
const data = [
57
{
@@ -129,17 +131,13 @@ export default function Footer(props: FooterProps) {
129131
<section>
130132
<div className={styles.icons}>
131133
<a href="https://uiwjs.github.io/react-native-uiw/" target="__blank">
132-
<img src={logo} alt="uiw logo" style={{ height: 27 }}/>
134+
<Logo height="27" width="27" />
133135
</a>
134136
<a href="https://github.com/uiwjs/react-native-uiw" target="__blank">
135-
<svg width="20px" height="20px" viewBox="0 0 20 20" role="img">
136-
<path d="M10 0C4.475 0 0 4.475 0 10a9.994 9.994 0 006.838 9.488c.5.087.687-.213.687-.476 0-.237-.013-1.024-.013-1.862-2.512.463-3.162-.612-3.362-1.175-.113-.287-.6-1.175-1.025-1.412-.35-.188-.85-.65-.013-.663.788-.013 1.35.725 1.538 1.025.9 1.512 2.337 1.087 2.912.825.088-.65.35-1.088.638-1.338-2.225-.25-4.55-1.112-4.55-4.937 0-1.088.387-1.987 1.025-2.688-.1-.25-.45-1.274.1-2.65 0 0 .837-.262 2.75 1.026a9.28 9.28 0 012.5-.338c.85 0 1.7.112 2.5.337 1.912-1.3 2.75-1.024 2.75-1.024.55 1.375.2 2.4.1 2.65.637.7 1.025 1.587 1.025 2.687 0 3.838-2.337 4.688-4.562 4.938.362.312.675.912.675 1.85 0 1.337-.013 2.412-.013 2.75 0 .262.188.574.688.474A10.016 10.016 0 0020 10c0-5.525-4.475-10-10-10z" />
137-
</svg>
137+
<Github />
138138
</a>
139139
<a href="https://gitee.com/uiw/react-native-uiw" target="__blank">
140-
<svg viewBox="0 0 1024 1024" width="20" height="20">
141-
<path d="M512 1024C229.2224 1024 0 794.7776 0 512S229.2224 0 512 0s512 229.2224 512 512-229.2224 512-512 512z m259.1488-568.8832H480.4096a25.2928 25.2928 0 0 0-25.2928 25.2928l-0.0256 63.2064c0 13.952 11.3152 25.2928 25.2672 25.2928h177.024c13.9776 0 25.2928 11.3152 25.2928 25.2672v12.6464a75.8528 75.8528 0 0 1-75.8528 75.8528H366.592a25.2928 25.2928 0 0 1-25.2672-25.2928v-240.1792a75.8528 75.8528 0 0 1 75.8272-75.8528h353.9456a25.2928 25.2928 0 0 0 25.2672-25.2928l0.0768-63.2064a25.2928 25.2928 0 0 0-25.2672-25.2928H417.152a189.6192 189.6192 0 0 0-189.6192 189.6448v353.9456c0 13.9776 11.3152 25.2928 25.2928 25.2928h372.9408a170.6496 170.6496 0 0 0 170.6496-170.6496v-145.408a25.2928 25.2928 0 0 0-25.2928-25.2672z" fill="#C71D23" />
142-
</svg>
140+
<Gitee />
143141
</a>
144142
</div>
145143
<div className={styles.icons}>

website/src/component/Header/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
21
import { Link, NavLink } from 'react-router-dom';
32
import pkg from '@uiw/react-native/package.json';
43
import styles from './index.module.less';
5-
import logo from '../../assets/logo-dark.svg';
4+
import { ReactComponent } from '../../assets/logo-dark.svg';
65

76
type HeaderProps = {
87
showBorder?: boolean;
@@ -17,7 +16,7 @@ export default function Header(props: HeaderProps) {
1716
<header className={styles.warpper} style={{ ...(showBorder ? {} : { borderBottom: 0, boxShadow: 'initial' })}}>
1817
<div className={styles.inner}>
1918
<Link to="/" className={styles.logo}>
20-
<img src={logo} alt="uiw logo" />
19+
<ReactComponent height="38" width="38" />
2120
<span className={styles.title} style={{ display: 'flex' }}>
2221
<span>
2322
React Native UIW
Lines changed: 90 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,106 @@
1-
import React, { Fragment, useState } from 'react';
1+
import React, { Component, Fragment } from 'react';
22
import MarkdownPreview from '@uiw/react-markdown-preview';
33
// @ts-ignore
44
import rehypeAttr from 'rehype-attr';
5-
import { useEffect } from 'react';
65
import Contributors from '../Contributors';
76
import Footer from '../Footer';
87
import styles from './index.module.less';
98

10-
export interface MarkdownProps extends React.HTMLAttributes<HTMLDivElement> {
9+
interface MarkdownProps extends React.HTMLAttributes<HTMLDivElement> {
1110
path?: string;
1211
renderPage?: () => Promise<string>;
1312
}
1413

15-
export default function Markdown(props: MarkdownProps) {
16-
const { renderPage, path, style } = props;
17-
const [mdStr, setMdStr] = useState('');
18-
const [message, setMessage] = useState('');
19-
useEffect(() => {
20-
if (renderPage) {
21-
setMessage('')
22-
renderPage()
23-
.then((str) => {
24-
setMdStr(str);
25-
})
26-
.catch(() => {
27-
setMessage('页面加载失败!请刷新页面')
28-
});
14+
interface MarkdownState {
15+
markdown: string;
16+
message?: string;
17+
}
18+
19+
// utilitary function to create a dictionary of packaged files
20+
// based on the output of require.context()
21+
// https://forum.ionicframework.com/t/react-app-loading-lots-of-markdown-html-fragments-with-images/188072/3
22+
export const importAll = (r: any, cache: {[key: string]: string}) => r.keys().forEach((key: string) => cache[key] = r(key));
23+
// const imageFiles: {[key: string]: string} = {};
24+
// importAll((require as any).context('../..', true, /\.(png|gif|jpg)$/), imageFiles);
25+
26+
export default class Markdown extends Component<MarkdownProps, MarkdownState> {
27+
path?: string;
28+
imageFiles: { [key: string]: string; } = {};
29+
getMarkdown?: () => Promise<string>;
30+
constructor(props: MarkdownProps) {
31+
super(props);
32+
this.state = {
33+
markdown: ''
34+
}
35+
if (this.getMarkdown) {
36+
this.getMarkdown = this.getMarkdown.bind(this);
37+
}
38+
}
39+
async componentDidMount() {
40+
this.importAll();
41+
this.setState({ markdown: '' });
42+
if (this.getMarkdown) {
43+
try {
44+
const markdown = await this.getMarkdown();
45+
this.setState({ markdown });
46+
} catch (error) {
47+
this.setState({ markdown: '页面加载失败!请刷新页面' });
48+
}
49+
}
50+
}
51+
importAll() {
52+
importAll((require as any).context('../..', true, /\.(png|gif|jpg)$/), this.imageFiles);
53+
}
54+
transformImageUri(uri: string) {
55+
if (this.imageFiles[uri]) {
56+
return (this.imageFiles[uri] as any).default || this.imageFiles[uri]
57+
}
58+
return uri;
59+
}
60+
render() {
61+
const {style} = this.props;
62+
if (this.state.message) {
63+
return (
64+
<div className={styles.warpper} style={style}>
65+
{this.state.message}
66+
<Contributors path={this.path}/>
67+
</div>
68+
);
2969
}
30-
// eslint-disable-next-line react-hooks/exhaustive-deps
31-
}, []);
32-
if (message) {
3370
return (
34-
<div className={styles.warpper} style={style}>
35-
{message}
36-
<Contributors path={path}/>
37-
</div>
71+
<Fragment>
72+
<div className={styles.warpper} style={style}>
73+
<MarkdownPreview
74+
source={this.state.markdown}
75+
rehypePlugins={[[rehypeAttr as any, { properties: 'attr' }]]}
76+
transformImageUri={this.transformImageUri.bind(this)}
77+
components={{
78+
/**
79+
* bgWhite 设置代码预览背景白色,否则为格子背景。
80+
* noCode 不显示代码编辑器。
81+
* noPreview 不显示代码预览效果。
82+
* noScroll 预览区域不显示滚动条。
83+
* codePen 显示 Codepen 按钮,要特别注意 包导入的问题,实例中的 import 主要用于 Codepen 使用。
84+
*/
85+
code: ({
86+
inline,
87+
node,
88+
noPreview,
89+
noScroll,
90+
bgWhite,
91+
noCode,
92+
codePen,
93+
codeSandbox,
94+
...props
95+
}) => {
96+
return <code {...props} />;
97+
},
98+
}}
99+
/>
100+
<Contributors path={this.path}/>
101+
</div>
102+
<Footer placement="left" />
103+
</Fragment>
38104
);
39105
}
40-
return (
41-
<Fragment>
42-
<div className={styles.warpper} style={style}>
43-
<MarkdownPreview
44-
source={mdStr}
45-
// className={styles.markdown}
46-
rehypePlugins={[[rehypeAttr as any, { properties: 'attr' }]]}
47-
components={{
48-
/**
49-
* bgWhite 设置代码预览背景白色,否则为格子背景。
50-
* noCode 不显示代码编辑器。
51-
* noPreview 不显示代码预览效果。
52-
* noScroll 预览区域不显示滚动条。
53-
* codePen 显示 Codepen 按钮,要特别注意 包导入的问题,实例中的 import 主要用于 Codepen 使用。
54-
*/
55-
code: ({
56-
inline,
57-
node,
58-
noPreview,
59-
noScroll,
60-
bgWhite,
61-
noCode,
62-
codePen,
63-
codeSandbox,
64-
...props
65-
}) => {
66-
return <code {...props} />;
67-
},
68-
}}
69-
/>
70-
<Contributors path={path}/>
71-
</div>
72-
<Footer placement="left" />
73-
</Fragment>
74-
)
75106
}

0 commit comments

Comments
 (0)