Browse Source

chore: support watch for markdown

pull/1093/head
Benjy Cui 9 years ago
parent
commit
b33b91a166
  1. 3
      package.json
  2. 16
      scripts/build-common.js
  3. 3
      site/component/utils.js
  4. 8
      site/entry/index.jsx
  5. 34
      site/entry/utils.js

3
package.json

@ -71,6 +71,7 @@
"warning": "~2.1.0"
},
"devDependencies": {
"antd-md-loader": "0.1.0-beta",
"atool-build": "^0.5.0",
"babel-cli": "^6.2.0",
"babel-core": "^6.2.1",
@ -106,8 +107,8 @@
"lesshint-antd": "^1.2.1",
"lodash": "^4.1.0",
"mark-twain": "^0.2.0-beta.4",
"nico-jsx": "~0.8.2",
"mkdirp": "~0.5.1",
"nico-jsx": "~0.8.2",
"postcss-loader": "^0.8.0",
"pre-commit": "1.x",
"querystring": "^0.2.0",

16
scripts/build-common.js

@ -40,18 +40,12 @@ const parse = function parse(fileName) {
};
module.exports = function buildCommon(inputDir, outputFile) {
const mds = utils.findMDFile(inputDir, true);
const parsed = sortByOrder(R.map(parse, mds));
const result = {
menuItems: getMenuItems(parsed),
pagesData: parsed,
};
let content = 'module.exports = {';
mds.forEach((md) => {
content += `\n '${md}': require('antd-md!../../${md}'),`;
});
content += '\n};';
const content = 'const React = require(\'react\');\n' +
'const ReactDOM = require(\'react-dom\');\n' +
'const _antd = require(\'../../\');\n' +
'const BrowserDemo = require(\'../../site/component/BrowserDemo\');\n' +
'module.exports = ' +
utils.stringify(result, null, 2) + ';';
fs.writeFile(outputFile, content);
};

3
site/component/utils.js

@ -1,4 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import hljs from 'highlight.js';
import antd, { Menu } from '../../';
@ -14,7 +15,7 @@ export function objectToComponent(object, index) {
}
if (typeof object === 'function') {
return object(React, antd);
return object(React, ReactDOM, antd, antd);
}
if (typeof object === 'string') {

8
site/entry/index.jsx

@ -36,16 +36,16 @@ const demosListChildren = componentDocsList.map((componentDoc) => {
return <Route path={key} component={ComponentDocWrapper} key={key} />;
});
const Practice = utils.generateContainer('practice', practice.menuItems);
const Practice = utils.generateContainer('practice', practice);
const practiceChildren = utils.generateChildren(practice);
const Pattern = utils.generateContainer('pattern', pattern.menuItems);
const Pattern = utils.generateContainer('pattern', pattern);
const patternChildren = utils.generateChildren(pattern);
const Spec = utils.generateContainer('spec', spec.menuItems);
const Spec = utils.generateContainer('spec', spec);
const specChildren = utils.generateChildren(spec);
const Resource = utils.generateContainer('resource', resource.menuItems);
const Resource = utils.generateContainer('resource', resource);
const resourceChildren = utils.generateChildren(resource);
ReactDOM.render(

34
site/entry/utils.js

@ -8,7 +8,28 @@ function dashed(name) {
return name.toLowerCase().trim().replace(/\s+/g, '-');
}
export function generateContainer(category, menuItems) {
function getMenuItems(data) {
const menuMeta = Object.keys(data)
.map((key) => data[key])
.map((file) => file.meta);
const menuItems = {};
menuMeta.sort((a, b) => {
return parseInt(a.order, 10) - parseInt(b.order, 10);
}).forEach((meta) => {
const category = meta.category || 'topLevel';
if (!menuItems[category]) {
menuItems[category] = [];
}
menuItems[category].push(meta);
});
return menuItems;
}
export function generateContainer(category, data) {
const menuItems = getMenuItems(data);
return (props) => {
return (
<MainContent {...props}
@ -17,9 +38,16 @@ export function generateContainer(category, menuItems) {
};
}
export function generateChildren({ pagesData, menuItems }) {
function getPagesData(data) {
return Object.keys(data)
.map((key) => data[key]);
}
export function generateChildren(data) {
const pagesData = getPagesData(data);
const menuItems = getMenuItems(data);
const children = pagesData.map((pageData, index) => {
const Wrapper = pageData.demos === null ?
const Wrapper = !pageData.meta.hasDemos ?
() => <Article content={pageData} /> :
() => <ComponentDoc doc={pageData} demos={pageData.demos} />;
return (

Loading…
Cancel
Save