mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 19:46:57 +02:00
refactor(v2): move source files to be under website/src directory (#1609)
* refactor(v2): move source files to be under website/src directory * misc: rename src constant
This commit is contained in:
parent
da3c91373e
commit
ffbc7a37f8
29 changed files with 56 additions and 37 deletions
|
@ -11,7 +11,7 @@ const fs = require('fs');
|
|||
const {encodePath, fileToPath, docuHash} = require('@docusaurus/utils');
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
path: 'pages', // Path to data on filesystem, relative to site dir.
|
||||
path: 'src/pages', // Path to data on filesystem, relative to site dir.
|
||||
routeBasePath: '', // URL Route.
|
||||
include: ['**/*.{js,jsx}'], // Extensions to include.
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
## Unreleased
|
||||
|
||||
- Added Google analytics and Google gtag plugins.
|
||||
- Moved source components to `/src`. Please create a `website/src` directory and move your `/pages` and `/theme` code into it. This is to make it easier to integrate your website with external build/static analysis tooling (you can now just pass in `src/**/*.js` as the path to process).
|
||||
|
||||
## 2.0.0-alpha.19
|
||||
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import shell from 'shelljs';
|
||||
import {CONFIG_FILE_NAME} from '../constants';
|
||||
import {
|
||||
BUILD_DIR_NAME,
|
||||
CONFIG_FILE_NAME,
|
||||
GENERATED_FILES_DIR_NAME,
|
||||
} from '../constants';
|
||||
import {loadConfig} from '../server/config';
|
||||
import {build} from './build';
|
||||
|
||||
|
@ -131,9 +135,9 @@ export async function deploy(siteDir: string): Promise<void> {
|
|||
|
||||
shell.cd('../..');
|
||||
|
||||
const fromPath = path.join('build');
|
||||
const fromPath = path.join(BUILD_DIR_NAME);
|
||||
const toPath = path.join(
|
||||
'.docusaurus',
|
||||
GENERATED_FILES_DIR_NAME,
|
||||
`${projectName}-${deploymentBranch}`,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import fs from 'fs-extra';
|
|||
import importFresh from 'import-fresh';
|
||||
import path from 'path';
|
||||
|
||||
import {THEME_PATH} from '../constants';
|
||||
|
||||
export async function swizzle(
|
||||
siteDir: string,
|
||||
themeName: string,
|
||||
|
@ -20,7 +22,7 @@ export async function swizzle(
|
|||
let fromPath = pluginInstance.getThemePath();
|
||||
|
||||
if (fromPath) {
|
||||
let toPath = path.resolve(siteDir, 'theme');
|
||||
let toPath = path.resolve(siteDir, THEME_PATH);
|
||||
if (componentName) {
|
||||
fromPath = path.join(fromPath, componentName);
|
||||
toPath = path.join(toPath, componentName);
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export const GENERATED_FILES_DIR_NAME = '.docusaurus';
|
||||
export const STATIC_DIR_NAME = 'static';
|
||||
export const BUILD_DIR_NAME = 'build';
|
||||
export const CONFIG_FILE_NAME = 'docusaurus.config.js';
|
||||
export const GENERATED_FILES_DIR_NAME = '.docusaurus';
|
||||
export const SRC_DIR_NAME = 'src';
|
||||
export const STATIC_DIR_NAME = 'static';
|
||||
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
||||
|
|
|
@ -18,7 +18,7 @@ module.exports = {
|
|||
'@docusaurus/plugin-content-docs',
|
||||
{
|
||||
path: '../docs',
|
||||
sidebarPath: require.resolve('./sidebars.json'),
|
||||
sidebarPath: require.resolve('./sidebars.js'),
|
||||
},
|
||||
],
|
||||
'@docusaurus/plugin-content-pages',
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
docs: {
|
||||
Test: ['foo/bar', 'foo/baz'],
|
||||
Guides: ['hello'],
|
||||
},
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"docs": {
|
||||
"Test": [
|
||||
"foo/bar",
|
||||
"foo/baz"
|
||||
],
|
||||
"Guides": [
|
||||
"hello"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ module.exports = {
|
|||
'@docusaurus/plugin-content-docs',
|
||||
{
|
||||
path: '../docs',
|
||||
sidebarPath: require.resolve('./sidebars.json'),
|
||||
sidebarPath: require.resolve('./sidebars.js'),
|
||||
},
|
||||
],
|
||||
'@docusaurus/plugin-content-pages',
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
docs: {
|
||||
Test: ['foo/bar', 'foo/baz'],
|
||||
Guides: ['hello'],
|
||||
},
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"docs": {
|
||||
"Test": [
|
||||
"foo/bar",
|
||||
"foo/baz"
|
||||
],
|
||||
"Guides": [
|
||||
"hello"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -8,7 +8,12 @@
|
|||
import {generate} from '@docusaurus/utils';
|
||||
import _ from 'lodash';
|
||||
import path from 'path';
|
||||
import {CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME} from '../constants';
|
||||
import {
|
||||
BUILD_DIR_NAME,
|
||||
CONFIG_FILE_NAME,
|
||||
GENERATED_FILES_DIR_NAME,
|
||||
THEME_PATH,
|
||||
} from '../constants';
|
||||
import {loadClientModules} from './client-modules';
|
||||
import {loadConfig} from './config';
|
||||
import {loadPlugins} from './plugins';
|
||||
|
@ -39,7 +44,7 @@ export async function load(
|
|||
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
||||
);
|
||||
|
||||
const outDir = path.resolve(siteDir, 'build');
|
||||
const outDir = path.resolve(siteDir, BUILD_DIR_NAME);
|
||||
const {baseUrl} = siteConfig;
|
||||
|
||||
const context: LoadContext = {
|
||||
|
@ -72,7 +77,7 @@ export async function load(
|
|||
const pluginThemes = _.compact(
|
||||
plugins.map(plugin => plugin.getThemePath && plugin.getThemePath()),
|
||||
);
|
||||
const userTheme = path.resolve(siteDir, 'theme');
|
||||
const userTheme = path.resolve(siteDir, THEME_PATH);
|
||||
const alias = loadThemeAlias([fallbackTheme, ...pluginThemes, userTheme]);
|
||||
// Make a fake plugin to resolve aliased theme components.
|
||||
plugins.push({
|
||||
|
|
|
@ -74,7 +74,7 @@ module.exports = {
|
|||
sidebarPath: require.resolve('./sidebars.js'),
|
||||
},
|
||||
theme: {
|
||||
customCss: require.resolve('./css/custom.css'),
|
||||
customCss: require.resolve('./src/css/custom.css'),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -59,7 +59,7 @@ The headers are well-spaced so that the hierarchy is clear.
|
|||
|
||||
This will render in the browser as follows:
|
||||
|
||||
import BrowserWindow from '../components/BrowserWindow';
|
||||
import BrowserWindow from '../src/components/BrowserWindow';
|
||||
|
||||
<BrowserWindow url="http://localhost:3000">
|
||||
<h2>Hello from Docusaurus</h2>
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = {
|
|||
postsPerPage: 3,
|
||||
},
|
||||
theme: {
|
||||
customCss: require.resolve('./css/custom.css'),
|
||||
customCss: require.resolve('./src/css/custom.css'),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue