Skip to content

Commit d051752

Browse files
committed
feat(antdsite): add theme.
1 parent 22ae1a0 commit d051752

54 files changed

Lines changed: 272 additions & 232 deletions

Some content is hidden

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

packages/antdsite/index.js

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1 @@
1-
/* eslint no-console:0 */
2-
function camelCase(name) {
3-
return (
4-
name.charAt(0).toUpperCase() +
5-
name.slice(1).replace(/-(\w)/g, (m, n) => {
6-
return n.toUpperCase();
7-
})
8-
);
9-
}
10-
11-
// Just import style for https://github.com/ant-design/ant-design/issues/3745
12-
const req = require.context('./components', true, /^\.\/[^_][\w-]+\/style\/index\.tsx?$/);
13-
14-
req.keys().forEach(mod => {
15-
let v = req(mod);
16-
if (v && v.default) {
17-
v = v.default;
18-
}
19-
const match = mod.match(/^\.\/([^_][\w-]+)\/index\.tsx?$/);
20-
if (match && match[1]) {
21-
if (match[1] === 'message' || match[1] === 'notification') {
22-
// message & notification should not be capitalized
23-
exports[match[1]] = v;
24-
} else {
25-
exports[camelCase(match[1])] = v;
26-
}
27-
}
28-
});
29-
30-
module.exports = require('./components');
1+
export { PageContext } from './templates/PageContext';

packages/antdsite/lib/gatsby/createPages.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const path = require('path');
1313
function isHome(frontmatter, slug) {
1414
return (
1515
frontmatter.home === true &&
16-
((themeConfig.locales && Object.keys(themeConfig.locales).indexOf(slug) !== -1) || slug === '/')
16+
((themeConfig.locales && Object.keys(themeConfig.locales).indexOf(slug) !== -1) ||
17+
slug === webConfig.base)
1718
);
1819
}
1920

@@ -27,8 +28,7 @@ module.exports = async ({ graphql, actions }) => {
2728
const { createPage, createRedirect } = actions;
2829
// Used to detect and prevent duplicate redirects
2930

30-
const docsTemplate = resolve(__dirname, '../../src/templates/docs.tsx');
31-
const indexTemplate = resolve(__dirname, '../../src/templates/home.tsx');
31+
const template = resolve(__dirname, '../../src/templates/index.tsx');
3232

3333
// Redirect /index.html to root.
3434
createRedirect({
@@ -70,37 +70,32 @@ module.exports = async ({ graphql, actions }) => {
7070
edges.forEach(edge => {
7171
const { fields, frontmatter } = edge.node;
7272
const { slug } = fields;
73-
if (!isHome(frontmatter, slug)) {
74-
if (frontmatter.home === true) {
75-
redirects[resolveDirPath(slug)] = slug;
76-
redirects[resolveDirPath(slug, true)] = slug;
77-
}
73+
let isWebsiteHome = false;
74+
75+
if (isHome(frontmatter, slug)) {
76+
isWebsiteHome = true;
77+
}
7878

79-
const createArticlePage = path => {
80-
return createPage({
81-
path,
82-
component: docsTemplate,
83-
context: {
84-
webConfig,
85-
slug,
86-
maxTocDeep: frontmatter.maxTocDeep || webConfig.themeConfig.maxTocDeep,
87-
},
88-
});
89-
};
90-
91-
// Register primary URL.
92-
createArticlePage(slug);
93-
} else {
94-
createPage({
95-
path: slug,
96-
component: indexTemplate,
79+
if (frontmatter.home === true && !isWebsiteHome) {
80+
redirects[resolveDirPath(slug)] = slug;
81+
redirects[resolveDirPath(slug, true)] = slug;
82+
}
83+
84+
const createArticlePage = path => {
85+
return createPage({
86+
path,
87+
component: template,
9788
context: {
89+
isWebsiteHome,
9890
webConfig,
9991
slug,
100-
maxTocDeep: webConfig.themeConfig.maxTocDeep,
92+
maxTocDeep: frontmatter.maxTocDeep || webConfig.themeConfig.maxTocDeep,
10193
},
10294
});
103-
}
95+
};
96+
97+
// Register primary URL.
98+
createArticlePage(slug);
10499
});
105100

106101
Object.keys(redirects).map(path => {

packages/antdsite/lib/gatsby/onCreateWebpackConfig.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = ({ stage, actions, loaders, getConfig }) => {
1+
const { resolveLayouts } = require('../util');
2+
3+
module.exports = ({ stage, actions, loaders }) => {
4+
resolveLayouts(actions);
25
if (stage === 'develop') {
36
actions.setWebpackConfig({
47
module: {

packages/antdsite/lib/util.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const path = require('path');
22
const defaultConfig = require(path.resolve(__dirname, '../__default__/default-config'));
33
const chalk = require('chalk');
4+
const fs = require('fs');
5+
6+
const configName = '.antdsite/config.js';
7+
const themeName = '.antdsite/theme';
48

5-
const configName = '.antdsite.js';
69
let userConfig;
710

811
module.exports.getUserConfig = () => {
@@ -92,3 +95,35 @@ function validateConfig(config) {
9295
}
9396
}
9497
}
98+
99+
function componentExist(path) {
100+
return (
101+
fs.existsSync(path + '.js') ||
102+
fs.existsSync(path + '.jsx') ||
103+
fs.existsSync(path + '.ts') ||
104+
fs.existsSync(path + '.tsx')
105+
);
106+
}
107+
108+
function getLayoutPath(layoutName) {
109+
const userDefinedLayout = path.resolve(process.cwd(), `${themeName}/layout/${layoutName}`);
110+
if (componentExist(userDefinedLayout)) {
111+
return userDefinedLayout;
112+
} else {
113+
return path.resolve(__dirname, `../src/default-theme/layout/${layoutName}.tsx`);
114+
}
115+
}
116+
117+
module.exports.resolveLayouts = function(actions) {
118+
const allLayouts = ['layout', 'header', 'home', 'footer', 'main-content'];
119+
allLayouts.forEach(layout => {
120+
const layoutPath = getLayoutPath(layout);
121+
actions.setWebpackConfig({
122+
resolve: {
123+
alias: {
124+
[`antdsite-${layout}`]: layoutPath,
125+
},
126+
},
127+
});
128+
});
129+
};

packages/antdsite/src/components/content/BrowserFrame.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)