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

feat(v2): implement theme component swizzling #1435

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"loader-utils": "^1.2.3"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0"
"@docusaurus/core": "^2.0.0",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"engines": {
"node": ">=8"
}
}
16 changes: 16 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ class DocusaurusPluginContentBlog {

configureWebpack(config, isServer, {getBabelLoader, getCacheLoader}) {
return {
resolve: {
alias: {
'@theme/BlogListPage': path.resolve(
__dirname,
'./theme/BlogListPage',
),
'@theme/BlogPostItem': path.resolve(
__dirname,
'./theme/BlogPostItem',
),
'@theme/BlogPostPage': path.resolve(
__dirname,
'./theme/BlogPostPage',
),
},
},
module: {
rules: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';

import Layout from '@theme/Layout'; // eslint-disable-line
import BlogPostItem from '../BlogPostItem';
import BlogPostItem from '@theme/BlogPostItem';

function BlogListPage(props) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';

import Layout from '@theme/Layout'; // eslint-disable-line
import BlogPostItem from '../BlogPostItem';
import BlogPostItem from '@theme/BlogPostItem';

function BlogPostPage(props) {
const {content: BlogPostContents, metadata} = props;
Expand Down
8 changes: 7 additions & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"loader-utils": "^1.2.3"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0"
"@docusaurus/core": "^2.0.0",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-config": "^5.0.0"
},
"engines": {
"node": ">=8"
}
}
11 changes: 11 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ class DocusaurusPluginContentDocs {

configureWebpack(config, isServer, {getBabelLoader, getCacheLoader}) {
return {
resolve: {
alias: {
'@theme/DocItem': path.resolve(__dirname, './theme/DocItem'),
'@theme/DocPage': path.resolve(__dirname, './theme/DocPage'),
'@theme/DocPaginator': path.resolve(
__dirname,
'./theme/DocPaginator',
),
'@theme/DocSidebar': path.resolve(__dirname, './theme/DocSidebar'),
},
},
module: {
rules: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';

import Head from '@docusaurus/Head';

import DocPaginator from '../DocPaginator';
import DocPaginator from '@theme/DocPaginator';

import styles from './styles.module.css';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {renderRoutes} from 'react-router-config';

import Layout from '@theme/Layout'; // eslint-disable-line

import DocSidebar from '../DocSidebar';
import DocSidebar from '@theme/DocSidebar';

function DocPage(props) {
const {route, docsMetadata, location} = props;
Expand Down
7 changes: 6 additions & 1 deletion packages/docusaurus-plugin-content-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"globby": "^9.1.0"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0"
"@docusaurus/core": "^2.0.0",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"engines": {
"node": ">=8"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@docusaurus/preset-classic",
"name": "@docusaurus/preset-default",
"version": "2.0.0-alpha.13",
"description": "Preset for classic Docusaurus",
"description": "Preset for default Docusaurus",
"main": "src/index.js",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

module.exports = function preset(context, opts = {}) {
return {
themes: [
{
name: '@docusaurus/theme-default',
},
],
plugins: [
{
name: '@docusaurus/plugin-content-docs',
Expand Down
21 changes: 21 additions & 0 deletions packages/docusaurus-theme-default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@docusaurus/theme-default",
"version": "2.0.0-alpha.13",
"description": "Default theme for Docusaurus",
"main": "src/index.js",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"dependencies": {
"docsearch.js": "^2.5.2"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"engines": {
"node": ">=8"
}
}
38 changes: 38 additions & 0 deletions packages/docusaurus-theme-default/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const path = require('path');

const DEFAULT_OPTIONS = {};

class DocusaurusThemeDefault {
constructor(context, opts) {
this.options = {...DEFAULT_OPTIONS, ...opts};
this.context = context;
}

getName() {
return 'docusaurus-theme-default';
}

configureWebpack() {
return {
resolve: {
alias: {
'@theme/Footer': path.resolve(__dirname, './theme/Footer'),
'@theme/Layout': path.resolve(__dirname, './theme/Layout'),
'@theme/Loading': path.resolve(__dirname, './theme/Loading'),
'@theme/Navbar': path.resolve(__dirname, './theme/Navbar'),
'@theme/NotFound': path.resolve(__dirname, './theme/NotFound'),
'@theme/Search': path.resolve(__dirname, './theme/Search'),
},
},
};
}
}

module.exports = DocusaurusThemeDefault;
2 changes: 1 addition & 1 deletion packages/docusaurus/lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = async function build(siteDir, cliOptions = {}) {
);
});

// Run webpack to build js bundle (client) and static html files (server) !!
// Run webpack to build JS bundle (client) and static html files (server).
await compile([clientConfig, serverConfig]);

// Remove server.bundle.js because it is useless
Expand Down
29 changes: 23 additions & 6 deletions packages/docusaurus/lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ module.exports = async function load(siteDir, cliOptions = {}) {
const context = {siteDir, generatedFilesDir, siteConfig, cliOptions};

// Process presets.
const presetPlugins = loadPresets(context);
const {plugins: presetPlugins, themes: presetThemes} = loadPresets(context);

// Process plugins and themes. Themes are also plugins, but they run after all
// the explicit plugins because they may override the resolve.alias(es)
// defined by the plugins.
const pluginConfigs = [
...presetPlugins,
...(siteConfig.plugins || []),
...presetThemes,
...(siteConfig.themes || []),
];

// Process plugins.
const pluginConfigs = [...presetPlugins, ...siteConfig.plugins];
const {plugins, pluginsRouteConfigs} = await loadPlugins({
pluginConfigs,
context,
Expand All @@ -43,8 +51,18 @@ module.exports = async function load(siteDir, cliOptions = {}) {
const outDir = path.resolve(siteDir, 'build');
const {baseUrl} = siteConfig;

// Resolve theme. TBD (Experimental)
const themePath = loadTheme(siteDir);
// Resolve custom theme override aliases.
const themeAliases = await loadTheme(siteDir);
// Make a fake plugin to resolve user's theme overrides.
if (themeAliases != null) {
plugins.push({
configureWebpack: () => ({
resolve: {
alias: themeAliases,
},
}),
});
}

// Routing
const {
Expand Down Expand Up @@ -81,7 +99,6 @@ ${Object.keys(registry)
siteConfig,
siteDir,
outDir,
themePath,
baseUrl,
generatedFilesDir,
routesPaths,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = function preset(context, opts = {}) {
return {
themes: [
{
name: '@docusaurus/theme-default',
options: opts.test,
},
],
plugins: [
{
name: '@docusaurus/plugin-test',
options: opts.test,
},
],
};
};
Loading