Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize Content and Routing Structure #1153

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 54 additions & 45 deletions antwar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
output: 'build',
title: 'webpack',
keywords: ['webpack', 'javascript', 'web development', 'programming'],

pageTitle: function(config, pageTitle) {
var siteName = config.name;

Expand All @@ -22,12 +23,15 @@ module.exports = {

return siteName + ' - ' + pageTitle;
},

plugins: [
prevnextPlugin()
],

layout: function() {
return require('./components/site/site.jsx').default
},

paths: {
'/': root(
function() {
Expand All @@ -39,14 +43,6 @@ module.exports = {
}
),

'get-started': {
redirects: {
'': '/guides/get-started',
'install-webpack': '/guides/installation',
'why-webpack': '/guides/why-webpack',
}
},

concepts: section(
'Concepts',
function() {
Expand All @@ -73,67 +69,61 @@ module.exports = {
}
),

development: section(
'Development',
documentation: section(
'Documentation',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/development',
true,
'json-loader!yaml-frontmatter-loader!./content/documentation',
false,
/^\.\/.*\.md$/
);
}
),

configuration: section(
'Configuration',
'documentation/api': section(
'API',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/configuration',
'json-loader!yaml-frontmatter-loader!./content/documentation/api',
false,
/^\.\/.*\.md$/
);
}, {
'external-configs': 'javascript-alternatives'
'passing-a-config': 'configuration-types'
}
),

api: section(
'API',
// This would be better as a nested (third level) directory
// Consider fixing somehow and moving to redirects?
'documentation/api/plugins': section(
'API | Plugins',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/api',
'json-loader!yaml-frontmatter-loader!./content/documentation/api/plugins',
false,
/^\.\/.*\.md$/
);
}, {
'passing-a-config': 'configuration-types'
}
),

'api/plugins': section(
'API',
'documentation/configuration': section(
'Configuration',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/api/plugins',
'json-loader!yaml-frontmatter-loader!./content/documentation/configuration',
false,
/^\.\/.*\.md$/
);
}, {
'external-configs': 'javascript-alternatives'
}
),

pluginsapi: {
redirects: {
'': '/api/plugins',
'compiler': '/api/plugins/compiler',
'template': '/api/plugins/template'
}
},

loaders: section(
'documentation/loaders': section(
'Loaders',
function() {
const content = require.context(
'json-loader!yaml-frontmatter-loader!./content/loaders',
'json-loader!yaml-frontmatter-loader!./content/documentation/loaders',
false,
/^\.\/.*\.md$/
);
Expand All @@ -146,11 +136,11 @@ module.exports = {
}
),

plugins: section(
'documentation/plugins': section(
'Plugins',
function() {
const content = require.context(
'json-loader!yaml-frontmatter-loader!./content/plugins',
'json-loader!yaml-frontmatter-loader!./content/documentation/plugins',
false,
/^\.\/.*\.md$/
);
Expand All @@ -163,6 +153,18 @@ module.exports = {
}
),

// Maybe move to support/development?
'documentation/development': section(
'Development',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/documentation/development',
true,
/^\.\/.*\.md$/
);
}
),

support: section(
'Support',
function() {
Expand All @@ -180,23 +182,30 @@ module.exports = {
}
},

'vote/feedback': {
organization: {
path() {
return require('./components/vote/list.jsx').default
return require('./components/organization/organization.jsx').default
}
},

'vote/moneyDistribution': {
path() {
return require('./components/vote/list.jsx').default

// Redirects: Everything below is just redirects from old sections

'get-started': {
redirects: {
'': '/guides/get-started',
'install-webpack': '/guides/installation',
'why-webpack': '/guides/why-webpack',
}
},

organization: {
path() {
return require('./components/organization/organization.jsx').default
pluginsapi: {
redirects: {
'': '/api/plugins',
'compiler': '/api/plugins/compiler',
'template': '/api/plugins/template'
}
}
},
}
};

Expand Down
33 changes: 33 additions & 0 deletions components/navigation/navigation-links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"title": "Concepts",
"url": "concepts"
},
{
"title": "Guides",
"url": "guides"
},
{
"title": "Documentation",
"url": "documentation/configuration",
"children": [
{ "title": "API", "url": "documentation/api" },
{ "title": "Configuration", "url": "documentation/configuration" },
{ "title": "Loaders", "url": "documentation/loaders" },
{ "title": "Plugins", "url": "documentation/plugins" },
{ "title": "Development", "url": "documentation/development" }
]
},
{
"title": "Support",
"url": "support"
},
{
"title": "Blog",
"url": "//medium.com/webpack"
},
{
"title": "Donate",
"url": "//opencollective.com/webpack"
}
]
103 changes: 34 additions & 69 deletions components/navigation/navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,9 @@ import USFlag from '../../assets/language/english.png';
import ChineseFlag from '../../assets/language/chinese.png';

// TODO: Maybe by updating the routing scheme later on we can avoid hardcoding this?
let Sections = [
{
title: 'Concepts',
url: 'concepts'
},
{
title: 'Guides',
url: 'guides'
},
{
title: 'Documentation',
url: 'configuration',
children: [
{ title: 'CLI', url: 'api/cli' },
{ title: 'API', url: 'api' },
{ title: 'Configuration', url: 'configuration' },
{ title: 'Loaders', url: 'loaders' },
{ title: 'Plugins', url: 'plugins' },
{ title: 'Development', url: 'development' }
]
},
{
title: 'Donate',
url: '//opencollective.com/webpack'
},
{
title: 'Blog',
url: '//medium.com/webpack'
},
{
title: 'Support',
url: 'support'
}
];
import Links from './navigation-links.json';

// TODO: Move back to using state once we can handle algolia on our own
// TODO: Migrate to react-banner
export default class Navigation extends React.Component {
render() {
let { pageUrl = '' } = this.props;
Expand All @@ -60,16 +27,16 @@ export default class Navigation extends React.Component {

<nav className="navigation__links">
{
Sections.map(section => {
let active = this._isActive(section);
Links.map(link => {
let active = this._isActive(link);
let activeMod = active ? 'navigation__link--active' : '';

return (
<Link
key={ `navigation__link-${section.title}` }
key={ `navigation__link-${link.title}` }
className={ `navigation__link ${activeMod}` }
to={ `/${section.url}` }>
{ section.title }
to={ `/${link.url}` }>
{ link.title }
</Link>
);
})
Expand Down Expand Up @@ -113,28 +80,26 @@ export default class Navigation extends React.Component {
</Container>

{
Sections.filter(section => this._isActive(section) && section.children).map(section => {
return (
<div className="navigation__bottom" key={ section.title }>
<Container className="navigation__inner">
{
section.children.map(child => {
let activeMod = this._isActive(child) ? 'navigation__child--active' : '';

return (
<Link
key={ `navigation__child-${child.title}` }
className={ `navigation__child ${activeMod}` }
to={ `/${child.url}` }>
{ child.title }
</Link>
);
})
}
</Container>
</div>
);
})
Links.filter(link => this._isActive(link) && link.children).map(link => (
<div className="navigation__bottom" key={ link.title }>
<Container className="navigation__inner">
{
link.children.map(child => {
let activeMod = this._isActive(child) ? 'navigation__child--active' : '';

return (
<Link
key={ `navigation__child-${child.title}` }
className={ `navigation__child ${activeMod}` }
to={ `/${child.url}` }>
{ child.title }
</Link>
);
})
}
</Container>
</div>
))
}
</header>
);
Expand Down Expand Up @@ -164,18 +129,18 @@ export default class Navigation extends React.Component {
}

/**
* Check if section is active
* Check if link is active
*
* @param {object} section - An object describing the section
* @return {bool} - Whether or not the given section is active
* @param {object} link - An object describing the link
* @return {bool} - Whether or not the given link is active
*/
_isActive(section) {
_isActive(link) {
let { pageUrl = '' } = this.props;

if (section.children) {
return section.children.some(child => pageUrl.includes(`${child.url}/`));
if (link.children) {
return link.children.some(child => pageUrl.includes(`${child.url}/`));

} else return pageUrl.includes(`${section.url}/`);
} else return pageUrl.includes(`${link.url}/`);
}

/**
Expand Down
Loading