feat: docusaurus-init without example directories (#1378)

* feat: do not copy into examples folder

* Update documentation

* feat: use Undraw illustrations for initialized landing page (#1379)
This commit is contained in:
Yangshun Tay 2019-04-21 22:28:35 -07:00 committed by GitHub
parent 1a44d99db1
commit 21793a833d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 83 additions and 83 deletions

View file

@ -31,14 +31,17 @@ Along with previously existing files and directories, your root directory will n
```bash ```bash
root-directory root-directory
├── docs-examples-from-docusaurus ├── Dockerfile
├── README.md
├── docker-compose.yml
├── docs
│ ├── doc1.md │ ├── doc1.md
│ ├── doc2.md │ ├── doc2.md
│ ├── doc3.md │ ├── doc3.md
│ ├── exampledoc4.md │ ├── exampledoc4.md
│ └── exampledoc5.md │ └── exampledoc5.md
└── website └── website
├── blog-examples-from-docusaurus ├── blog
│ ├── 2016-03-11-blog-post.md │ ├── 2016-03-11-blog-post.md
│ ├── 2017-04-10-blog-post-two.md │ ├── 2017-04-10-blog-post-two.md
│ ├── 2017-09-25-testing-rss.md │ ├── 2017-09-25-testing-rss.md
@ -59,15 +62,13 @@ After running the Docusaurus initialization script, `docusaurus-init` as
described in the [Installation](#installing-docusaurus) section, you will have a described in the [Installation](#installing-docusaurus) section, you will have a
runnable, example website to use as your site's base. To run: runnable, example website to use as your site's base. To run:
1. In your root, rename `docs-examples-from-docusaurus` to `docs`.
1. `cd website` 1. `cd website`
1. Rename `blog-examples-from-docusaurus` to `blog`.
1. From within the `website` directory, run the local webserver using 1. From within the `website` directory, run the local webserver using
`yarn start` or `npm start`. `yarn start` or `npm start`.
1. Load the example site at http://localhost:3000 if it did not already open 1. Load the example site at http://localhost:3000 if it did not already open
automatically. automatically. If port 3000 has already been taken, another port will be used. Look at the console messages to see which.
You should see the example site loaded in your web browser. There's also a LiveReload server running and any changes made to the docs and files in the `website` directory will cause the page to refresh. You should see the example site loaded in your web browser. There's also a LiveReload server running and any changes made to the docs and files in the `website` directory will cause the page to refresh. A randomly generated primary and secondary theme color will be picked for you.
![](/img/getting-started-preparation-verify.png) ![](/img/getting-started-preparation-verify.png)

View file

@ -60,7 +60,7 @@ class HomeSplash extends React.Component {
return ( return (
<SplashContainer> <SplashContainer>
<Logo img_src={`${baseUrl}img/docusaurus.svg`} /> <Logo img_src={`${baseUrl}img/undraw_monitor.svg`} />
<div className="inner"> <div className="inner">
<ProjectTitle siteConfig={siteConfig} /> <ProjectTitle siteConfig={siteConfig} />
<PromoSection> <PromoSection>
@ -105,10 +105,13 @@ class Index extends React.Component {
<Block id="try"> <Block id="try">
{[ {[
{ {
content: 'Talk about trying this out', content:
image: `${baseUrl}img/docusaurus.svg`, 'To make your landing page more attractive, use illustrations! Check out ' +
'[**Undraw**](https://undraw.co/) which provides you with customizable illustrations which are free to use. ' +
'The illustrations you see on this page are from Undraw.',
image: `${baseUrl}img/undraw_code_review.svg`,
imageAlign: 'left', imageAlign: 'left',
title: 'Try it Out', title: 'Wonderful SVG Illustrations',
}, },
]} ]}
</Block> </Block>
@ -120,7 +123,7 @@ class Index extends React.Component {
{ {
content: content:
'This is another description of how this project is useful', 'This is another description of how this project is useful',
image: `${baseUrl}img/docusaurus.svg`, image: `${baseUrl}img/undraw_note_list.svg`,
imageAlign: 'right', imageAlign: 'right',
title: 'Description', title: 'Description',
}, },
@ -132,10 +135,11 @@ class Index extends React.Component {
<Block background="light"> <Block background="light">
{[ {[
{ {
content: 'Talk about learning how to use this', content:
image: `${baseUrl}img/docusaurus.svg`, 'Each new Docusaurus project has **randomly-generated** theme colors.',
image: `${baseUrl}img/undraw_youtube_tutorial.svg`,
imageAlign: 'right', imageAlign: 'right',
title: 'Learn How', title: 'Randomly Generated Theme Colors',
}, },
]} ]}
</Block> </Block>
@ -146,13 +150,13 @@ class Index extends React.Component {
{[ {[
{ {
content: 'This is the content of my feature', content: 'This is the content of my feature',
image: `${baseUrl}img/docusaurus.svg`, image: `${baseUrl}img/undraw_react.svg`,
imageAlign: 'top', imageAlign: 'top',
title: 'Feature One', title: 'Feature One',
}, },
{ {
content: 'The content of my second feature', content: 'The content of my second feature',
image: `${baseUrl}img/docusaurus.svg`, image: `${baseUrl}img/undraw_operating_system.svg`,
imageAlign: 'top', imageAlign: 'top',
title: 'Feature Two', title: 'Feature Two',
}, },

View file

@ -13,8 +13,8 @@ const users = [
{ {
caption: 'User1', caption: 'User1',
// You will need to prepend the image path with your baseUrl // You will need to prepend the image path with your baseUrl
// if it is not '/', like: '/test-site/img/docusaurus.svg'. // if it is not '/', like: '/test-site/img/image.jpg'.
image: '/img/docusaurus.svg', image: '/img/undraw_open_source.svg',
infoLink: 'https://www.facebook.com', infoLink: 'https://www.facebook.com',
pinned: true, pinned: true,
}, },
@ -48,9 +48,9 @@ const siteConfig = {
users, users,
/* path to images for header/footer */ /* path to images for header/footer */
headerIcon: 'img/docusaurus.svg', headerIcon: 'img/favicon.ico',
footerIcon: 'img/docusaurus.svg', footerIcon: 'img/favicon.ico',
favicon: 'img/favicon.png', favicon: 'img/favicon.ico',
/* Colors for website */ /* Colors for website */
colors: { colors: {
@ -89,8 +89,8 @@ const siteConfig = {
cleanUrl: true, cleanUrl: true,
// Open Graph and Twitter card images. // Open Graph and Twitter card images.
ogImage: 'img/docusaurus.png', ogImage: 'img/undraw_online.svg',
twitterImage: 'img/docusaurus.png', twitterImage: 'img/undraw_tweetstorm.svg',
// Show documentation's last contributor's name. // Show documentation's last contributor's name.
// enableUpdateBy: true, // enableUpdateBy: true,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 17 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 32 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 24 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.2 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -69,9 +69,7 @@ if (fs.existsSync(`${CWD}/package.json`)) {
const outerFolder = path.basename(path.dirname(CWD)); const outerFolder = path.basename(path.dirname(CWD));
let docsCreated = false; let docsCreatedInIntendedDirectory = true;
let blogCreated = false;
let exampleSiteCreated = false;
// handles cases where feature is "translations", "versions" or neither/not present // handles cases where feature is "translations", "versions" or neither/not present
if (feature === 'translations') { if (feature === 'translations') {
@ -85,7 +83,6 @@ if (feature === 'translations') {
); );
} else { } else {
fs.copySync(`${folder}/crowdin.yaml`, `${CWD}/../crowdin.yaml`); fs.copySync(`${folder}/crowdin.yaml`, `${CWD}/../crowdin.yaml`);
exampleSiteCreated = true;
} }
const files = glob.sync(`${folder}/**/*`); const files = glob.sync(`${folder}/**/*`);
files.forEach(file => { files.forEach(file => {
@ -101,7 +98,6 @@ if (feature === 'translations') {
overwrite: false, overwrite: false,
errorOnExist: true, errorOnExist: true,
}); });
exampleSiteCreated = true;
} catch (e) { } catch (e) {
console.log( console.log(
`${chalk.yellow( `${chalk.yellow(
@ -126,7 +122,6 @@ if (feature === 'translations') {
overwrite: false, overwrite: false,
errorOnExist: true, errorOnExist: true,
}); });
exampleSiteCreated = true;
} catch (e) { } catch (e) {
console.log( console.log(
`${chalk.yellow( `${chalk.yellow(
@ -140,34 +135,28 @@ if (feature === 'translations') {
} else { } else {
const folder = path.join(__dirname, '..', 'examples', 'basics'); const folder = path.join(__dirname, '..', 'examples', 'basics');
// copy docs examples // copy docs examples
if (fs.existsSync(`${CWD}/../docs-examples-from-docusaurus`)) { let targetDocsDir = `${CWD}/../docs`;
if (fs.existsSync(targetDocsDir)) {
console.log( console.log(
`- ${chalk.green( `- ${chalk.green('docs')} already exists in ${chalk.blue(
'docs-examples-from-docusaurus', outerFolder,
)} already exists in ${chalk.blue(outerFolder)}.`, )}. Copying into ${CWD}/../docs-examples-from-docusaurus instead.`,
); );
} else { targetDocsDir = `${CWD}/../docs-examples-from-docusaurus`;
fs.copySync( docsCreatedInIntendedDirectory = false;
`${folder}/docs-examples-from-docusaurus`,
`${CWD}/../docs-examples-from-docusaurus`,
);
exampleSiteCreated = true;
docsCreated = true;
} }
fs.copySync(`${folder}/docs`, targetDocsDir);
// copy blog examples // copy blog examples
if (fs.existsSync(`${CWD}/blog-examples-from-docusaurus`)) { if (fs.existsSync(`${CWD}/blog`)) {
console.log( console.log(
`- ${chalk.green( `- ${chalk.green('blog')} already exists in ${chalk.blue(
'blog-examples-from-docusaurus', `${outerFolder}/website`,
)} already exists in ${chalk.blue(`${outerFolder}/website`)}.`, )}.`,
); );
} else { } else {
fs.copySync( fs.copySync(path.join(folder, 'blog'), path.join(CWD, 'blog'));
path.join(folder, 'blog-examples-from-docusaurus'),
path.join(CWD, 'blog-examples-from-docusaurus'),
);
exampleSiteCreated = true;
blogCreated = true;
} }
const copyFileToProjectFolder = (fileNameFrom, fileNameTo) => { const copyFileToProjectFolder = (fileNameFrom, fileNameTo) => {
@ -199,6 +188,7 @@ if (feature === 'translations') {
// copy other files // copy other files
const files = glob.sync(`${folder}/**/*`); const files = glob.sync(`${folder}/**/*`);
const {primaryColor, secondaryColor} = colorScheme();
files.forEach(file => { files.forEach(file => {
if (fs.lstatSync(file).isDirectory()) { if (fs.lstatSync(file).isDirectory()) {
return; return;
@ -209,8 +199,8 @@ if (feature === 'translations') {
path.basename(file) === 'Dockerfile' || path.basename(file) === 'Dockerfile' ||
path.basename(file) === 'docker-compose.yml' || path.basename(file) === 'docker-compose.yml' ||
path.basename(file) === 'dockerignore' || path.basename(file) === 'dockerignore' ||
containingFolder === 'blog-examples-from-docusaurus' || containingFolder === 'blog' ||
containingFolder === 'docs-examples-from-docusaurus' containingFolder === 'docs'
) { ) {
return; return;
} }
@ -219,7 +209,6 @@ if (feature === 'translations') {
path.basename(file) === 'siteConfig.js' && path.basename(file) === 'siteConfig.js' &&
!fs.existsSync(CWD + filePath) !fs.existsSync(CWD + filePath)
) { ) {
const {primaryColor, secondaryColor} = colorScheme();
const siteConfig = fs const siteConfig = fs
.readFileSync(file, 'utf8') .readFileSync(file, 'utf8')
.replace('{{primaryColor}}', primaryColor) .replace('{{primaryColor}}', primaryColor)
@ -231,7 +220,6 @@ if (feature === 'translations') {
overwrite: false, overwrite: false,
errorOnExist: true, errorOnExist: true,
}); });
exampleSiteCreated = true;
} catch (e) { } catch (e) {
console.log( console.log(
`- ${chalk.green( `- ${chalk.green(
@ -246,38 +234,37 @@ if (feature === 'translations') {
} }
}); });
if (exampleSiteCreated) { const svgs = glob.sync(`${CWD}/static/img/**/*.svg`);
try { svgs.forEach(file => {
const tree = require('tree-node-cli'); // Replace primary colors of SVGs.
const dirString = tree(path.join(CWD, '..'), { const newImage = fs
exclude: [ .readFileSync(file, 'utf8')
/node_modules/, // npm .replace(/{{primaryColor}}/g, primaryColor);
/vendor/, // composer fs.writeFileSync(file, newImage);
], });
});
console.log(dirString); try {
} catch (error) { const tree = require('tree-node-cli');
console.warn(`Error printing directory: ${error}`); const dirString = tree(path.join(CWD, '..'), {
} exclude: [
/node_modules/, // npm
/vendor/, // composer
],
});
console.log(dirString);
} catch (error) {
console.warn(`Error printing directory: ${error}`);
} }
} }
if (docsCreated) { if (!docsCreatedInIntendedDirectory) {
console.log( console.log(
`Rename ${chalk.yellow( `The ${chalk.yellow(
`${outerFolder}/docs-examples-from-docusaurus`,
)} to ${chalk.yellow(
`${outerFolder}/docs`, `${outerFolder}/docs`,
)} to see the example docs on your site.\n`, )} directory was not created because it already exists. ` +
); `Please manually convert the contents into a Docusaurus-compatible format ` +
} `by referring to the examples from ${chalk.yellow(
`${outerFolder}/docs-examples-from-docusaurus`,
if (blogCreated) { )}.\n`,
console.log(
`Rename ${chalk.yellow(
`${outerFolder}/website/blog-examples-from-docusaurus`,
)} to ${chalk.yellow(
`${outerFolder}/website/blog`,
)} to see the example blog posts on your site.\n`,
); );
} }