From 65421db62ece5f14f9a281fcd151750e1fdc81a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= <165856+hramos@users.noreply.github.com> Date: Mon, 4 Dec 2017 19:21:02 -0800 Subject: [PATCH] Add Prettier Formatting (#258) * Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs * Remove trailing-comma as we are using Node 6 on Circle * Use latest Node 6 LTS version in Circle * Remove unused test --- .circleci/config.yml | 26 +- .prettierrc | 9 + examples/basics/core/Footer.js | 46 ++- examples/basics/pages/en/help.js | 19 +- examples/basics/pages/en/index.js | 102 +++---- examples/basics/pages/en/users.js | 8 +- examples/basics/siteConfig.js | 50 ++-- examples/translations/languages.js | 138 ++++----- .../pages/en/help-with-translations.js | 21 +- examples/versions/pages/en/versions.js | 47 ++-- lib/build-files.js | 26 +- lib/copy-examples.js | 124 ++++---- lib/core/BlogPageLayout.js | 43 ++- lib/core/BlogPost.js | 44 +-- lib/core/BlogPostLayout.js | 67 +++-- lib/core/BlogSidebar.js | 20 +- lib/core/CompLibrary.js | 8 +- lib/core/Container.js | 32 +-- lib/core/Doc.js | 14 +- lib/core/DocsLayout.js | 46 ++- lib/core/DocsSidebar.js | 12 +- lib/core/GridBlock.js | 42 ++- lib/core/Head.js | 52 ++-- lib/core/Header.js | 10 +- lib/core/MarkdownBlock.js | 5 +- lib/core/Redirect.js | 22 +- lib/core/Remarkable.js | 52 ++-- lib/core/Site.js | 48 ++-- lib/core/nav/HeaderNav.js | 78 +++--- lib/core/nav/SideNav.js | 28 +- lib/core/toSlug.js | 22 +- lib/core/unindent.js | 8 +- lib/generate-feed.js | 26 +- lib/publish-gh-pages.js | 50 ++-- lib/rename-version.js | 66 ++--- lib/server/feed.js | 50 ++-- lib/server/generate.js | 233 ++++++++------- lib/server/readCategories.js | 26 +- lib/server/readMetadata.js | 200 +++++++------ lib/server/server.js | 265 +++++++++--------- lib/server/sitemap.js | 88 +++--- lib/server/translate-plugin.js | 24 +- lib/server/translate.js | 36 +-- lib/server/translation.js | 24 +- lib/server/versionFallback.js | 132 +++++---- lib/start-server.js | 33 +-- lib/version.js | 66 ++--- lib/write-translations.js | 122 ++++---- package.json | 10 +- yarn.lock | 6 +- 50 files changed, 1376 insertions(+), 1350 deletions(-) create mode 100644 .prettierrc diff --git a/.circleci/config.yml b/.circleci/config.yml index 299996280b..599b843af0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,36 +26,27 @@ aliases: defaults: &defaults working_directory: ~/docusaurus + docker: + - image: circleci/node:6 version: 2 jobs: - test-js-node: - <<: *defaults - docker: - - image: circleci/node:6.11.4 - steps: - - checkout - - restore-cache: *restore-yarn-cache - - run: *yarn - - save-cache: *save-yarn-cache - - run: yarn run test test-website: <<: *defaults - docker: - - image: circleci/node:6.11.4 steps: - checkout - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache + - run: + name: Check Prettier + command: yarn ci-check - run: name: Test Build Static Website command: cd website && yarn run build deploy-website: <<: *defaults - docker: - - image: circleci/node:6.11.4 steps: - add_ssh_keys: fingerprints: @@ -84,8 +75,6 @@ jobs: publish-npm: <<: *defaults - docker: - - image: circleci/node:6.11.4 steps: - checkout - restore-cache: *restore-yarn-cache @@ -105,11 +94,6 @@ jobs: workflows: version: 2 - test_node: - jobs: - - test-js-node: - filters: *filter-ignore-gh-pages - website: jobs: - test-website: diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..61793cffde --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "bracketSpacing": false, + "jsxBracketSameLine": true, + "parser": "flow", + "printWidth": 80, + "proseWrap": false, + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/examples/basics/core/Footer.js b/examples/basics/core/Footer.js index 31d09d1b4a..73f6042965 100644 --- a/examples/basics/core/Footer.js +++ b/examples/basics/core/Footer.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); +const React = require('react'); class Footer extends React.Component { render() { @@ -26,31 +26,28 @@ class Footer extends React.Component { + '/doc1.html' + }> Getting Started (or other categories) + '/doc2.html' + }> Guides (or other categories) + '/doc3.html' + }> API Reference (or other categories) @@ -58,15 +55,13 @@ class Footer extends React.Component {
Community
+ this.props.config.baseUrl + this.props.language + '/users.html' + }> User Showcase + target="_blank"> Stack Overflow Project Chat @@ -76,28 +71,27 @@ class Footer extends React.Component {
More
- Blog + Blog GitHub - + aria-label="Star this project on GitHub"> Star - +
+ className="fbOpenSource"> Facebook Open Source
- +

{siteConfig.title} - - {siteConfig.tagline} - + {siteConfig.tagline}

@@ -53,21 +51,19 @@ class HomeSplash extends React.Component {
@@ -83,7 +79,7 @@ class HomeSplash extends React.Component { class Index extends React.Component { render() { - let language = this.props.language || "en"; + let language = this.props.language || 'en'; const showcase = siteConfig.users .filter(user => { return user.pinned; @@ -100,22 +96,22 @@ class Index extends React.Component {
- + @@ -123,67 +119,61 @@ class Index extends React.Component {
+ style={{textAlign: 'center'}}>

Feature Callout

These are features of this project
- + - + - +
-

- {"Who's Using This?"} -

+

{"Who's Using This?"}

This project is used by all these people

-
- {showcase} -
+
{showcase}
diff --git a/examples/basics/pages/en/users.js b/examples/basics/pages/en/users.js index 76f3ae7374..847c558391 100644 --- a/examples/basics/pages/en/users.js +++ b/examples/basics/pages/en/users.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); +const React = require('react'); -const CompLibrary = require("../../core/CompLibrary.js"); +const CompLibrary = require('../../core/CompLibrary.js'); const Container = CompLibrary.Container; -const siteConfig = require(process.cwd() + "/siteConfig.js"); +const siteConfig = require(process.cwd() + '/siteConfig.js'); class Users extends React.Component { render() { @@ -24,7 +24,7 @@ class Users extends React.Component { return (
- +

Who's Using This?

diff --git a/examples/basics/siteConfig.js b/examples/basics/siteConfig.js index f211d9f282..aa6411b93e 100644 --- a/examples/basics/siteConfig.js +++ b/examples/basics/siteConfig.js @@ -8,49 +8,47 @@ /* List of projects/orgs using your project for the users page */ const users = [ { - caption: "User1", - image: "/test-site/img/docusaurus.svg", - infoLink: "https://www.example.com", - pinned: true - } + caption: 'User1', + image: '/test-site/img/docusaurus.svg', + infoLink: 'https://www.example.com', + pinned: true, + }, ]; const siteConfig = { - title: "Test Site" /* title for your website */, - tagline: "A website for testing", - url: "https://deltice.github.io" /* your website url */, - baseUrl: "/test-site/" /* base url for your project */, - projectName: "test-site", + title: 'Test Site' /* title for your website */, + tagline: 'A website for testing', + url: 'https://deltice.github.io' /* your website url */, + baseUrl: '/test-site/' /* base url for your project */, + projectName: 'test-site', headerLinks: [ - { doc: "doc1", label: "Docs" }, - { doc: "doc4", label: "API" }, - { page: "help", label: "Help" }, - { blog: true, label: "Blog" } + {doc: 'doc1', label: 'Docs'}, + {doc: 'doc4', label: 'API'}, + {page: 'help', label: 'Help'}, + {blog: true, label: 'Blog'}, ], users, /* path to images for header/footer */ - headerIcon: "img/docusaurus.svg", - footerIcon: "img/docusaurus.svg", - favicon: "img/favicon.png", + headerIcon: 'img/docusaurus.svg', + footerIcon: 'img/docusaurus.svg', + favicon: 'img/favicon.png', /* colors for website */ colors: { - primaryColor: "#2E8555", - secondaryColor: "#205C3B" + primaryColor: '#2E8555', + secondaryColor: '#205C3B', }, // This copyright info is used in /core/Footer.js and blog rss/atom feeds. copyright: - "Copyright © " + + 'Copyright © ' + new Date().getFullYear() + - " Your Name or Your Company Name", + ' Your Name or Your Company Name', highlight: { // Highlight.js theme to use for syntax highlighting in code blocks - theme: "default" + theme: 'default', }, - scripts: [ - "https://buttons.github.io/buttons.js" - ], + scripts: ['https://buttons.github.io/buttons.js'], // You may provide arbitrary config keys to be used as needed by your template. - repoUrl: "https://github.com/deltice/test-site", + repoUrl: 'https://github.com/deltice/test-site', }; module.exports = siteConfig; diff --git a/examples/translations/languages.js b/examples/translations/languages.js index 01e7c50df8..fbe77f5c51 100644 --- a/examples/translations/languages.js +++ b/examples/translations/languages.js @@ -8,174 +8,174 @@ const languages = [ { enabled: true, - name: "English", - tag: "en" + name: 'English', + tag: 'en', }, { enabled: false, - name: "日本語", - tag: "ja" + name: '日本語', + tag: 'ja', }, { enabled: false, - name: "العربية", - tag: "ar" + name: 'العربية', + tag: 'ar', }, { enabled: false, - name: "Bosanski", - tag: "bs-BA" + name: 'Bosanski', + tag: 'bs-BA', }, { enabled: false, - name: "Català", - tag: "ca" + name: 'Català', + tag: 'ca', }, { enabled: false, - name: "Čeština", - tag: "cs" + name: 'Čeština', + tag: 'cs', }, { enabled: false, - name: "Dansk", - tag: "da" + name: 'Dansk', + tag: 'da', }, { enabled: false, - name: "Deutsch", - tag: "de" + name: 'Deutsch', + tag: 'de', }, { enabled: false, - name: "Ελληνικά", - tag: "el" + name: 'Ελληνικά', + tag: 'el', }, { enabled: false, - name: "Español", - tag: "es-ES" + name: 'Español', + tag: 'es-ES', }, { enabled: false, - name: "فارسی", - tag: "fa-IR" + name: 'فارسی', + tag: 'fa-IR', }, { enabled: false, - name: "Suomi", - tag: "fi" + name: 'Suomi', + tag: 'fi', }, { enabled: false, - name: "Français", - tag: "fr" + name: 'Français', + tag: 'fr', }, { enabled: false, - name: "עִברִית", - tag: "he" + name: 'עִברִית', + tag: 'he', }, { enabled: false, - name: "Magyar", - tag: "hu" + name: 'Magyar', + tag: 'hu', }, { enabled: false, - name: "Bahasa Indonesia", - tag: "id-ID" + name: 'Bahasa Indonesia', + tag: 'id-ID', }, { enabled: false, - name: "Italiano", - tag: "it" + name: 'Italiano', + tag: 'it', }, { enabled: false, - name: "Afrikaans", - tag: "af" + name: 'Afrikaans', + tag: 'af', }, { enabled: false, - name: "한국어", - tag: "ko" + name: '한국어', + tag: 'ko', }, { enabled: false, - name: "मराठी", - tag: "mr-IN" + name: 'मराठी', + tag: 'mr-IN', }, { enabled: false, - name: "Nederlands", - tag: "nl" + name: 'Nederlands', + tag: 'nl', }, { enabled: false, - name: "Norsk", - tag: "no-NO" + name: 'Norsk', + tag: 'no-NO', }, { enabled: false, - name: "Polskie", - tag: "pl" + name: 'Polskie', + tag: 'pl', }, { enabled: false, - name: "Português", - tag: "pt-PT" + name: 'Português', + tag: 'pt-PT', }, { enabled: false, - name: "Português (Brasil)", - tag: "pt-BR" + name: 'Português (Brasil)', + tag: 'pt-BR', }, { enabled: false, - name: "Română", - tag: "ro" + name: 'Română', + tag: 'ro', }, { enabled: false, - name: "Русский", - tag: "ru" + name: 'Русский', + tag: 'ru', }, { enabled: false, - name: "Slovenský", - tag: "sk-SK" + name: 'Slovenský', + tag: 'sk-SK', }, { enabled: false, - name: "Српски језик (Ћирилица)", - tag: "sr" + name: 'Српски језик (Ћирилица)', + tag: 'sr', }, { enabled: false, - name: "Svenska", - tag: "sv-SE" + name: 'Svenska', + tag: 'sv-SE', }, { enabled: false, - name: "Türkçe", - tag: "tr" + name: 'Türkçe', + tag: 'tr', }, { enabled: false, - name: "Українська", - tag: "uk" + name: 'Українська', + tag: 'uk', }, { enabled: false, - name: "Tiếng Việt", - tag: "vi" + name: 'Tiếng Việt', + tag: 'vi', }, { enabled: false, - name: "中文", - tag: "zh-Hans" + name: '中文', + tag: 'zh-Hans', }, - { enabled: false, name: "繁體中文", tag: "zh-Hant" } + {enabled: false, name: '繁體中文', tag: 'zh-Hant'}, ]; module.exports = languages; diff --git a/examples/translations/pages/en/help-with-translations.js b/examples/translations/pages/en/help-with-translations.js index 6c52b81d78..ba324ce7ed 100644 --- a/examples/translations/pages/en/help-with-translations.js +++ b/examples/translations/pages/en/help-with-translations.js @@ -5,15 +5,15 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); +const React = require('react'); -const CompLibrary = require("../../core/CompLibrary.js"); +const CompLibrary = require('../../core/CompLibrary.js'); const Container = CompLibrary.Container; const GridBlock = CompLibrary.GridBlock; -const translate = require("../../server/translate.js").translate; +const translate = require('../../server/translate.js').translate; -const siteConfig = require(process.cwd() + "/siteConfig.js"); +const siteConfig = require(process.cwd() + '/siteConfig.js'); class Help extends React.Component { render() { @@ -21,10 +21,11 @@ class Help extends React.Component { { content: ( - Learn more using the [documentation on this site.](/test-site/docs/en/doc1.html) + Learn more using the [documentation on this + site.](/test-site/docs/en/doc1.html) ), - title: Browse Docs + title: Browse Docs, }, { content: ( @@ -32,12 +33,12 @@ class Help extends React.Component { Ask questions about the documentation and project ), - title: Join the community + title: Join the community, }, { content: Find out what's new with this project, - title: Stay up to date - } + title: Stay up to date, + }, ]; return ( @@ -63,7 +64,7 @@ class Help extends React.Component { } Help.defaultProps = { - language: "en" + language: 'en', }; module.exports = Help; diff --git a/examples/versions/pages/en/versions.js b/examples/versions/pages/en/versions.js index 7dfe98012a..0aa9cd70b9 100644 --- a/examples/versions/pages/en/versions.js +++ b/examples/versions/pages/en/versions.js @@ -5,16 +5,16 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); +const React = require('react'); -const CompLibrary = require("../../core/CompLibrary"); +const CompLibrary = require('../../core/CompLibrary'); const Container = CompLibrary.Container; const GridBlock = CompLibrary.GridBlock; const CWD = process.cwd(); -const siteConfig = require(CWD + "/siteConfig.js"); -const versions = require(CWD + "/versions.json"); +const siteConfig = require(CWD + '/siteConfig.js'); +const versions = require(CWD + '/versions.json'); class Versions extends React.Component { render() { @@ -24,7 +24,7 @@ class Versions extends React.Component {
-

{siteConfig.title + " Versions"}

+

{siteConfig.title + ' Versions'}

New versions of this project are released every so often.

@@ -32,14 +32,12 @@ class Versions extends React.Component { - + @@ -55,10 +53,10 @@ class Versions extends React.Component { @@ -70,23 +68,22 @@ class Versions extends React.Component { {versions.map( version => - version !== latestVersion && - - - - - + version !== latestVersion && ( + + + + + + ) )}
- {latestVersion} - {latestVersion} - Documentation + Documentation - Release Notes + Release Notes
master - Documentation + Documentation - Release Notes + Release Notes
- {version} - - Documentation - - Release Notes -
{version} + Documentation + + Release Notes +

- You can find past versions of this project{" "} + You can find past versions of this project{' '} on GitHub .

diff --git a/lib/build-files.js b/lib/build-files.js index d6480860a1..e8fd7d2877 100755 --- a/lib/build-files.js +++ b/lib/build-files.js @@ -7,25 +7,25 @@ * LICENSE file in the root directory of this source tree. */ -require("babel-register")({ - babelrc: false, - only: [__dirname, process.cwd() + "/core"], - plugins: [require("./server/translate-plugin.js")], - presets: ["react", "env"] +require('babel-register')({ + babelrc: false, + only: [__dirname, process.cwd() + '/core'], + plugins: [require('./server/translate-plugin.js')], + presets: ['react', 'env'], }); // initial check that required files are present -const chalk = require("chalk"); -const fs = require("fs"); +const chalk = require('chalk'); +const fs = require('fs'); const CWD = process.cwd(); -if (!fs.existsSync(CWD + "/siteConfig.js")) { - console.error( - chalk.red("Error: No siteConfig.js file found in website folder!") - ); - process.exit(1); +if (!fs.existsSync(CWD + '/siteConfig.js')) { + console.error( + chalk.red('Error: No siteConfig.js file found in website folder!') + ); + process.exit(1); } // generate all static html files -const generate = require("./server/generate.js"); +const generate = require('./server/generate.js'); generate(); diff --git a/lib/copy-examples.js b/lib/copy-examples.js index f37f6c06df..b132548bcb 100755 --- a/lib/copy-examples.js +++ b/lib/copy-examples.js @@ -7,45 +7,45 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require("chalk"); -const commander = require("commander"); -const fs = require("fs-extra"); -const glob = require("glob"); -const path = require("path"); +const chalk = require('chalk'); +const commander = require('commander'); +const fs = require('fs-extra'); +const glob = require('glob'); +const path = require('path'); const CWD = process.cwd(); let feature; commander - .arguments("[feature]") + .arguments('[feature]') .action(feat => { feature = feat; }) .parse(process.argv); // add scripts to package.json file -if (fs.existsSync(CWD + "/package.json")) { +if (fs.existsSync(CWD + '/package.json')) { const packageContent = JSON.parse( - fs.readFileSync(CWD + "/package.json", "utf8") + fs.readFileSync(CWD + '/package.json', 'utf8') ); if (!packageContent.scripts) { packageContent.scripts = {}; } - packageContent.scripts["start"] = "docusaurus-start"; - packageContent.scripts["build"] = "docusaurus-build"; - packageContent.scripts["publish-gh-pages"] = "docusaurus-publish"; - packageContent.scripts["examples"] = "docusaurus-examples"; - packageContent.scripts["write-translations"] = - "docusaurus-write-translations"; - packageContent.scripts["version"] = "docusaurus-version"; - packageContent.scripts["rename-version"] = "docusaurus-rename-version"; + packageContent.scripts['start'] = 'docusaurus-start'; + packageContent.scripts['build'] = 'docusaurus-build'; + packageContent.scripts['publish-gh-pages'] = 'docusaurus-publish'; + packageContent.scripts['examples'] = 'docusaurus-examples'; + packageContent.scripts['write-translations'] = + 'docusaurus-write-translations'; + packageContent.scripts['version'] = 'docusaurus-version'; + packageContent.scripts['rename-version'] = 'docusaurus-rename-version'; fs.writeFileSync( - CWD + "/package.json", + CWD + '/package.json', JSON.stringify(packageContent, null, 2) ); console.log( - `${chalk.green("Wrote docusaurus scripts to package.json file.")}\n` + `${chalk.green('Wrote docusaurus scripts to package.json file.')}\n` ); } @@ -56,48 +56,48 @@ let blogCreated = false; let exampleSiteCreated = false; // handles cases where feature is "translations", "versions" or neither/not present -if (feature === "translations") { +if (feature === 'translations') { // copy files for translations - const folder = path.join(__dirname, "..", "examples", "translations"); - if (fs.existsSync(CWD + "/../crowdin.yaml")) { + const folder = path.join(__dirname, '..', 'examples', 'translations'); + if (fs.existsSync(CWD + '/../crowdin.yaml')) { console.log( - `${chalk.yellow("crowdin.yaml already exists")} in ${chalk.yellow( - outerFolder + "/" + `${chalk.yellow('crowdin.yaml already exists')} in ${chalk.yellow( + outerFolder + '/' )}. Rename or remove the file to regenerate an example version.\n` ); } else { - fs.copySync(folder + "/crowdin.yaml", CWD + "/../crowdin.yaml"); + fs.copySync(folder + '/crowdin.yaml', CWD + '/../crowdin.yaml'); exampleSiteCreated = true; } - let files = glob.sync(folder + "/**/*"); + let files = glob.sync(folder + '/**/*'); files.forEach(file => { if (fs.lstatSync(file).isDirectory()) { return; } - if (path.basename(file) === "crowdin.yaml") { + if (path.basename(file) === 'crowdin.yaml') { return; } const filePath = path.resolve(file).split(path.resolve(folder))[1]; try { fs.copySync(file, CWD + filePath, { overwrite: false, - errorOnExist: true + errorOnExist: true, }); exampleSiteCreated = true; } catch (e) { console.log( `${chalk.yellow( - path.basename(filePath) + " already exists" + path.basename(filePath) + ' already exists' )} in ${chalk.yellow( - "website" + filePath.split(path.basename(filePath))[0] + 'website' + filePath.split(path.basename(filePath))[0] )}. Rename or remove the file to regenerate an example version.\n` ); } }); -} else if (feature === "versions") { +} else if (feature === 'versions') { // copy files for versions - const folder = path.join(__dirname, "..", "examples", "versions"); - let files = glob.sync(folder + "/**/*"); + const folder = path.join(__dirname, '..', 'examples', 'versions'); + let files = glob.sync(folder + '/**/*'); files.forEach(file => { if (fs.lstatSync(file).isDirectory()) { return; @@ -106,76 +106,76 @@ if (feature === "translations") { try { fs.copySync(file, CWD + filePath, { overwrite: false, - errorOnExist: true + errorOnExist: true, }); exampleSiteCreated = true; } catch (e) { console.log( `${chalk.yellow( - path.basename(filePath) + " already exists" + path.basename(filePath) + ' already exists' )} in ${chalk.yellow( - "website" + filePath.split(path.basename(filePath))[0] + 'website' + filePath.split(path.basename(filePath))[0] )}. Rename or remove the file to regenerate an example version.\n` ); } }); } else { - const folder = path.join(__dirname, "..", "examples", "basics"); + const folder = path.join(__dirname, '..', 'examples', 'basics'); // copy docs examples - if (fs.existsSync(CWD + "/../docs-examples-from-docusaurus")) { + if (fs.existsSync(CWD + '/../docs-examples-from-docusaurus')) { console.log( `${chalk.yellow( - "Example docs already exist!" + 'Example docs already exist!' )} Rename or remove ${chalk.yellow( - outerFolder + "/docs-examples-from-docusaurus" + outerFolder + '/docs-examples-from-docusaurus' )} to regenerate example docs.\n` ); } else { fs.copySync( - folder + "/docs-examples-from-docusaurus", - CWD + "/../docs-examples-from-docusaurus" + folder + '/docs-examples-from-docusaurus', + CWD + '/../docs-examples-from-docusaurus' ); exampleSiteCreated = true; docsCreated = true; } // copy blog examples - if (fs.existsSync(CWD + "/blog-examples-from-docusaurus")) { + if (fs.existsSync(CWD + '/blog-examples-from-docusaurus')) { console.log( `${chalk.yellow( - "Example blog posts already exist!" + 'Example blog posts already exist!' )} Rename or remove ${chalk.yellow( - outerFolder + "/website/blog-examples-from-docusaurus" + outerFolder + '/website/blog-examples-from-docusaurus' )} to regenerate example blog posts.\n` ); } else { fs.copySync( - path.join(folder, "blog-examples-from-docusaurus"), - path.join(CWD, "blog-examples-from-docusaurus") + path.join(folder, 'blog-examples-from-docusaurus'), + path.join(CWD, 'blog-examples-from-docusaurus') ); exampleSiteCreated = true; blogCreated = true; } // copy .gitignore file - if (fs.existsSync(CWD + "/.gitignore")) { + if (fs.existsSync(CWD + '/.gitignore')) { console.log( - `${chalk.yellow(".gitignore already exists")} in ${chalk.yellow( + `${chalk.yellow('.gitignore already exists')} in ${chalk.yellow( CWD )}. Rename or remove the file to regenerate an example version.\n` ); } else { - fs.copySync(path.join(folder, "gitignore"), path.join(CWD, ".gitignore")); + fs.copySync(path.join(folder, 'gitignore'), path.join(CWD, '.gitignore')); } // copy other files - let files = glob.sync(folder + "/**/*"); + let files = glob.sync(folder + '/**/*'); files.forEach(file => { if (fs.lstatSync(file).isDirectory()) { return; } const containingFolder = path.basename(path.dirname(file)); if ( - path.basename(file) === "gitignore" || - containingFolder === "blog-examples-from-docusaurus" || - containingFolder === "docs-examples-from-docusaurus" + path.basename(file) === 'gitignore' || + containingFolder === 'blog-examples-from-docusaurus' || + containingFolder === 'docs-examples-from-docusaurus' ) { return; } @@ -183,15 +183,15 @@ if (feature === "translations") { try { fs.copySync(file, CWD + filePath, { overwrite: false, - errorOnExist: true + errorOnExist: true, }); exampleSiteCreated = true; } catch (e) { console.log( `${chalk.yellow( - path.basename(filePath) + " already exists" + path.basename(filePath) + ' already exists' )} in ${chalk.yellow( - "website" + filePath.split(path.basename(filePath))[0] + 'website' + filePath.split(path.basename(filePath))[0] )}. Rename or remove the file to regenerate an example version.\n` ); } @@ -200,8 +200,8 @@ if (feature === "translations") { if (exampleSiteCreated) { console.log( - `${chalk.green("Example website created")} in ${chalk.green( - CWD + "/website" + `${chalk.green('Example website created')} in ${chalk.green( + CWD + '/website' )}\n` ); } @@ -209,9 +209,9 @@ if (exampleSiteCreated) { if (docsCreated) { console.log( `Rename ${chalk.yellow( - outerFolder + "/docs-examples-from-docusaurus" + outerFolder + '/docs-examples-from-docusaurus' )} to ${chalk.yellow( - outerFolder + "/docs" + outerFolder + '/docs' )} to see the example docs on your site.\n` ); } @@ -219,9 +219,9 @@ if (docsCreated) { if (blogCreated) { console.log( `Rename ${chalk.yellow( - outerFolder + "/website/blog-examples-from-docusaurus" + outerFolder + '/website/blog-examples-from-docusaurus' )} to ${chalk.yellow( - outerFolder + "/website/blog" + outerFolder + '/website/blog' )} to see the example blog posts on your site.\n` ); } diff --git a/lib/core/BlogPageLayout.js b/lib/core/BlogPageLayout.js index dbdc41e0b2..df5e43ab79 100644 --- a/lib/core/BlogPageLayout.js +++ b/lib/core/BlogPageLayout.js @@ -5,19 +5,19 @@ * LICENSE file in the root directory of this source tree. */ -const BlogPost = require("./BlogPost.js"); -const BlogSidebar = require("./BlogSidebar.js"); -const Container = require("./Container.js"); -const MetadataBlog = require("./MetadataBlog.js"); -const React = require("react"); -const Site = require("./Site.js"); +const BlogPost = require('./BlogPost.js'); +const BlogSidebar = require('./BlogSidebar.js'); +const Container = require('./Container.js'); +const MetadataBlog = require('./MetadataBlog.js'); +const React = require('react'); +const Site = require('./Site.js'); // used to generate entire blog pages, i.e. collection of truncated blog posts class BlogPageLayout extends React.Component { getPageURL(page) { - let url = this.props.config.baseUrl + "blog/"; + let url = this.props.config.baseUrl + 'blog/'; if (page > 0) { - url += "page" + (page + 1) + "/"; + url += 'page' + (page + 1) + '/'; } return url; } @@ -34,20 +34,19 @@ class BlogPageLayout extends React.Component { />
- {MetadataBlog.slice( - page * perPage, - (page + 1) * perPage - ).map(post => { - return ( - - ); - })} + {MetadataBlog.slice(page * perPage, (page + 1) * perPage).map( + post => { + return ( + + ); + } + )}
{page > 0 && ( diff --git a/lib/core/BlogPost.js b/lib/core/BlogPost.js index d4e1ee05d4..bb5b123aca 100644 --- a/lib/core/BlogPost.js +++ b/lib/core/BlogPost.js @@ -5,27 +5,27 @@ * LICENSE file in the root directory of this source tree. */ -const MarkdownBlock = require("./MarkdownBlock.js"); -const React = require("react"); +const MarkdownBlock = require('./MarkdownBlock.js'); +const React = require('react'); // inner blog component for the article itself, without sidebar/header/footer class BlogPost extends React.Component { renderContent() { let content = this.props.content; let hasSplit = false; - if (content.split("").length > 1) { + if (content.split('').length > 1) { hasSplit = ( ); } if (this.props.truncate) { - content = content.split("")[0]; + content = content.split('')[0]; return (
{content} @@ -39,17 +39,17 @@ class BlogPost extends React.Component { renderAuthorPhoto() { const post = this.props.post; const className = - "authorPhoto" + - (post.author && post.authorTitle ? " authorPhoto-big" : ""); + 'authorPhoto' + + (post.author && post.authorTitle ? ' authorPhoto-big' : ''); if (post.authorFBID) { return (
@@ -72,7 +72,7 @@ class BlogPost extends React.Component { const post = this.props.post; return (

- + {post.title}

@@ -85,18 +85,18 @@ class BlogPost extends React.Component { // Because JavaScript sucks at date handling :( const year = match[1]; const month = [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December" + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', ][parseInt(match[2], 10) - 1]; const day = parseInt(match[3], 10); diff --git a/lib/core/BlogPostLayout.js b/lib/core/BlogPostLayout.js index 69e5771d2f..c4fa1bc339 100644 --- a/lib/core/BlogPostLayout.js +++ b/lib/core/BlogPostLayout.js @@ -5,31 +5,44 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); -const BlogPost = require("./BlogPost.js"); -const BlogSidebar = require("./BlogSidebar.js"); -const Container = require("./Container.js"); -const Site = require("./Site.js"); +const React = require('react'); +const BlogPost = require('./BlogPost.js'); +const BlogSidebar = require('./BlogSidebar.js'); +const Container = require('./Container.js'); +const Site = require('./Site.js'); // used for entire blog posts, i.e., each written blog article with sidebar with site header/footer class BlogPostLayout extends React.Component { - renderSocialButtons() { const post = this.props.metadata; - const fbLike = this.props.config.facebookAppId ? -
-
- : null; + const fbLike = this.props.config.facebookAppId ? ( +
+ ) : null; - const twitterShare = this.props.config.twitter ? - Tweet - : null; + const twitterShare = this.props.config.twitter ? ( + + Tweet + + ) : null; if (!fbLike && !twitterShare) { return; @@ -51,15 +64,14 @@ class BlogPostLayout extends React.Component { return ( + language={'en'} + description={this.props.children.trim().split('\n')[0]} + config={this.props.config}>
@@ -68,16 +80,13 @@ class BlogPostLayout extends React.Component { {this.renderSocialButtons()}
diff --git a/lib/core/BlogSidebar.js b/lib/core/BlogSidebar.js index 27fca57065..e1933fd89b 100644 --- a/lib/core/BlogSidebar.js +++ b/lib/core/BlogSidebar.js @@ -5,30 +5,30 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); -const Container = require("./Container.js"); -const SideNav = require("./nav/SideNav.js"); +const React = require('react'); +const Container = require('./Container.js'); +const SideNav = require('./nav/SideNav.js'); -const MetadataBlog = require("./MetadataBlog.js"); +const MetadataBlog = require('./MetadataBlog.js'); class BlogSidebar extends React.Component { render() { const contents = [ { - name: "Recent Posts", - links: MetadataBlog.slice(0, 5) - } + name: 'Recent Posts', + links: MetadataBlog.slice(0, 5), + }, ]; const title = this.props.current && this.props.current.title; const current = { - id: title || "", - category: "Recent Posts" + id: title || '', + category: 'Recent Posts', }; return ( = 0, - paddingBottom: this.props.padding.indexOf("bottom") >= 0, - paddingLeft: this.props.padding.indexOf("left") >= 0, - paddingRight: this.props.padding.indexOf("right") >= 0, - paddingTop: this.props.padding.indexOf("top") >= 0 + const containerClasses = classNames('container', this.props.className, { + darkBackground: this.props.background === 'dark', + highlightBackground: this.props.background === 'highlight', + lightBackground: this.props.background === 'light', + paddingAll: this.props.padding.indexOf('all') >= 0, + paddingBottom: this.props.padding.indexOf('bottom') >= 0, + paddingLeft: this.props.padding.indexOf('left') >= 0, + paddingRight: this.props.padding.indexOf('right') >= 0, + paddingTop: this.props.padding.indexOf('top') >= 0, }); let wrappedChildren; if (this.props.wrapper) { - wrappedChildren = ( -
- {this.props.children} -
- ); + wrappedChildren =
{this.props.children}
; } else { wrappedChildren = this.props.children; } @@ -40,9 +36,9 @@ class Container extends React.Component { } Container.defaultProps = { - background: "transparent", + background: 'transparent', padding: [], - wrapper: true + wrapper: true, }; module.exports = Container; diff --git a/lib/core/Doc.js b/lib/core/Doc.js index efe1d2069b..a12e076c3c 100644 --- a/lib/core/Doc.js +++ b/lib/core/Doc.js @@ -5,16 +5,16 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); -const MarkdownBlock = require("./MarkdownBlock.js"); +const React = require('react'); +const MarkdownBlock = require('./MarkdownBlock.js'); -const translate = require("../server/translate.js").translate; +const translate = require('../server/translate.js').translate; const editThisDoc = translate( - "Edit this Doc|recruitment message asking to edit the doc source" + 'Edit this Doc|recruitment message asking to edit the doc source' ); const translateThisDoc = translate( - "Translate this Doc|recruitment message asking to translate the docs" + 'Translate this Doc|recruitment message asking to translate the docs' ); // inner doc component for article itself @@ -29,14 +29,14 @@ class Doc extends React.Component { {editThisDoc} ); - if (this.props.language != "en") { + if (this.props.language != 'en') { editLink = !this.props.version && this.props.config.translationRecruitingLink && ( diff --git a/lib/core/DocsLayout.js b/lib/core/DocsLayout.js index 117202dcd3..32125a2962 100644 --- a/lib/core/DocsLayout.js +++ b/lib/core/DocsLayout.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); -const Container = require("./Container.js"); -const Doc = require("./Doc.js"); -const DocsSidebar = require("./DocsSidebar.js"); -const Site = require("./Site.js"); -const translation = require("../server/translation.js"); +const React = require('react'); +const Container = require('./Container.js'); +const Doc = require('./Doc.js'); +const DocsSidebar = require('./DocsSidebar.js'); +const Site = require('./Site.js'); +const translation = require('../server/translation.js'); // component used to generate whole webpage for docs, including sidebar/header/footer class DocsLayout extends React.Component { @@ -28,12 +28,12 @@ class DocsLayout extends React.Component { className="sideNavVisible" title={ i18n - ? translation[this.props.metadata.language]["localized-strings"][ + ? translation[this.props.metadata.language]['localized-strings'][ this.props.metadata.localized_id ] || this.props.metadata.title : this.props.metadata.title } - description={content.trim().split("\n")[0]} + description={content.trim().split('\n')[0]} language={metadata.language} version={metadata.version}>
@@ -47,7 +47,7 @@ class DocsLayout extends React.Component { title={ i18n ? translation[this.props.metadata.language][ - "localized-strings" + 'localized-strings' ][this.props.metadata.localized_id] || this.props.metadata.title : this.props.metadata.title @@ -58,34 +58,32 @@ class DocsLayout extends React.Component { {metadata.previous_id && ( - ←{" "} + href={metadata.previous_id + '.html'}> + ←{' '} {i18n ? translation[this.props.metadata.language][ - "localized-strings" + 'localized-strings' ][metadata.previous_id] || translation[this.props.metadata.language][ - "localized-strings" - ]["previous"] || - "Previous" - : metadata.previous_title || "Previous" - } + 'localized-strings' + ]['previous'] || + 'Previous' + : metadata.previous_title || 'Previous'} )} {metadata.next_id && ( + href={metadata.next_id + '.html'}> {i18n ? translation[this.props.metadata.language][ - "localized-strings" + 'localized-strings' ][metadata.next_id] || translation[this.props.metadata.language][ - "localized-strings" - ]["next"] || - "Next" - : metadata.next_title || "Next" - }{" "} + 'localized-strings' + ]['next'] || + 'Next' + : metadata.next_title || 'Next'}{' '} → )} diff --git a/lib/core/DocsSidebar.js b/lib/core/DocsSidebar.js index a82b8d9235..b62582458f 100644 --- a/lib/core/DocsSidebar.js +++ b/lib/core/DocsSidebar.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -const Metadata = require("./metadata.js"); -const React = require("react"); -const Container = require("./Container.js"); -const SideNav = require("./nav/SideNav.js"); -const siteConfig = require(process.cwd() + "/siteConfig.js"); -const readCategories = require("../server/readCategories.js"); +const Metadata = require('./metadata.js'); +const React = require('react'); +const Container = require('./Container.js'); +const SideNav = require('./nav/SideNav.js'); +const siteConfig = require(process.cwd() + '/siteConfig.js'); +const readCategories = require('../server/readCategories.js'); class DocsSidebar extends React.Component { render() { diff --git a/lib/core/GridBlock.js b/lib/core/GridBlock.js index 8e57735129..797f2bec11 100755 --- a/lib/core/GridBlock.js +++ b/lib/core/GridBlock.js @@ -5,32 +5,32 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); -const classNames = require("classnames"); +const React = require('react'); +const classNames = require('classnames'); -const MarkdownBlock = require("./MarkdownBlock.js"); +const MarkdownBlock = require('./MarkdownBlock.js'); class GridBlock extends React.Component { renderBlock(block) { - const blockClasses = classNames("blockElement", this.props.className, { - alignCenter: this.props.align === "center", - alignRight: this.props.align === "right", - fourByGridBlock: this.props.layout === "fourColumn", - imageAlignBottom: block.image && block.imageAlign === "bottom", + const blockClasses = classNames('blockElement', this.props.className, { + alignCenter: this.props.align === 'center', + alignRight: this.props.align === 'right', + fourByGridBlock: this.props.layout === 'fourColumn', + imageAlignBottom: block.image && block.imageAlign === 'bottom', imageAlignSide: block.image && - (block.imageAlign === "left" || block.imageAlign === "right"), - imageAlignTop: block.image && block.imageAlign === "top", - threeByGridBlock: this.props.layout === "threeColumn", - twoByGridBlock: this.props.layout === "twoColumn" + (block.imageAlign === 'left' || block.imageAlign === 'right'), + imageAlignTop: block.image && block.imageAlign === 'top', + threeByGridBlock: this.props.layout === 'threeColumn', + twoByGridBlock: this.props.layout === 'twoColumn', }); const topLeftImage = - (block.imageAlign === "top" || block.imageAlign === "left") && + (block.imageAlign === 'top' || block.imageAlign === 'left') && this.renderBlockImage(block.image, block.imageLink); const bottomRightImage = - (block.imageAlign === "bottom" || block.imageAlign === "right") && + (block.imageAlign === 'bottom' || block.imageAlign === 'right') && this.renderBlockImage(block.image, block.imageLink); return ( @@ -38,9 +38,7 @@ class GridBlock extends React.Component { {topLeftImage}
{this.renderBlockTitle(block.title)} - - {block.content} - + {block.content}
{bottomRightImage}
@@ -73,9 +71,7 @@ class GridBlock extends React.Component { if (title) { return (

- - {title} - + {title}

); } else { @@ -93,10 +89,10 @@ class GridBlock extends React.Component { } GridBlock.defaultProps = { - align: "left", + align: 'left', contents: [], - imagealign: "top", - layout: "twoColumn" + imagealign: 'top', + layout: 'twoColumn', }; module.exports = GridBlock; diff --git a/lib/core/Head.js b/lib/core/Head.js index b8b63cd748..82fa2b027e 100644 --- a/lib/core/Head.js +++ b/lib/core/Head.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -const React = require("react"); +const React = require('react'); // html head for each page class Head extends React.Component { @@ -17,8 +17,10 @@ class Head extends React.Component { }); const highlightDefaultVersion = '9.12.0'; - const highlightConfig = this.props.config.highlight - || { version: highlightDefaultVersion, theme: 'default' }; + const highlightConfig = this.props.config.highlight || { + version: highlightDefaultVersion, + theme: 'default', + }; const highlightVersion = highlightConfig.version || highlightDefaultVersion; const highlightTheme = highlightConfig.theme || 'default'; @@ -43,7 +45,7 @@ class Head extends React.Component { {this.props.redirect && ( {hasBlog && ( )} {hasBlog && ( )} {/* External resources */} - {this.props.config.stylesheets && this.props.config.stylesheets.map(function(source) { - return ( - - ); - })} - {this.props.config.scripts && this.props.config.scripts.map(function(source, idx) { - return ( -