mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
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
This commit is contained in:
parent
0cead4b6f9
commit
65421db62e
50 changed files with 1376 additions and 1350 deletions
|
@ -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:
|
||||
|
|
9
.prettierrc
Normal file
9
.prettierrc
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"bracketSpacing": false,
|
||||
"jsxBracketSameLine": true,
|
||||
"parser": "flow",
|
||||
"printWidth": 80,
|
||||
"proseWrap": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
}
|
|
@ -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 {
|
|||
<a
|
||||
href={
|
||||
this.props.config.baseUrl +
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
this.props.language +
|
||||
"/doc1.html"
|
||||
}
|
||||
>
|
||||
'/doc1.html'
|
||||
}>
|
||||
Getting Started (or other categories)
|
||||
</a>
|
||||
<a
|
||||
href={
|
||||
this.props.config.baseUrl +
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
this.props.language +
|
||||
"/doc2.html"
|
||||
}
|
||||
>
|
||||
'/doc2.html'
|
||||
}>
|
||||
Guides (or other categories)
|
||||
</a>
|
||||
<a
|
||||
href={
|
||||
this.props.config.baseUrl +
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
this.props.language +
|
||||
"/doc3.html"
|
||||
}
|
||||
>
|
||||
'/doc3.html'
|
||||
}>
|
||||
API Reference (or other categories)
|
||||
</a>
|
||||
</div>
|
||||
|
@ -58,15 +55,13 @@ class Footer extends React.Component {
|
|||
<h5>Community</h5>
|
||||
<a
|
||||
href={
|
||||
this.props.config.baseUrl + this.props.language + "/users.html"
|
||||
}
|
||||
>
|
||||
this.props.config.baseUrl + this.props.language + '/users.html'
|
||||
}>
|
||||
User Showcase
|
||||
</a>
|
||||
<a
|
||||
href="http://stackoverflow.com/questions/tagged/"
|
||||
target="_blank"
|
||||
>
|
||||
target="_blank">
|
||||
Stack Overflow
|
||||
</a>
|
||||
<a href="https://discordapp.com/">Project Chat</a>
|
||||
|
@ -76,16 +71,16 @@ class Footer extends React.Component {
|
|||
</div>
|
||||
<div>
|
||||
<h5>More</h5>
|
||||
<a href={this.props.config.baseUrl + "blog"}>Blog</a>
|
||||
<a href={this.props.config.baseUrl + 'blog'}>Blog</a>
|
||||
<a href="https://github.com/">GitHub</a>
|
||||
<a className="github-button"
|
||||
<a
|
||||
className="github-button"
|
||||
href={this.props.config.repoUrl}
|
||||
data-icon="octicon-star"
|
||||
data-count-href="/deltice/test-site/stargazers"
|
||||
data-show-count={true}
|
||||
data-count-aria-label="# stargazers on GitHub"
|
||||
aria-label="Star this project on GitHub"
|
||||
>
|
||||
aria-label="Star this project on GitHub">
|
||||
Star
|
||||
</a>
|
||||
</div>
|
||||
|
@ -94,10 +89,9 @@ class Footer extends React.Component {
|
|||
<a
|
||||
href="https://code.facebook.com/projects/"
|
||||
target="_blank"
|
||||
className="fbOpenSource"
|
||||
>
|
||||
className="fbOpenSource">
|
||||
<img
|
||||
src={this.props.config.baseUrl + "img/oss_logo.png"}
|
||||
src={this.props.config.baseUrl + 'img/oss_logo.png'}
|
||||
alt="Facebook Open Source"
|
||||
width="170"
|
||||
height="45"
|
||||
|
|
|
@ -5,31 +5,30 @@
|
|||
* 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 siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const siteConfig = require(process.cwd() + '/siteConfig.js');
|
||||
|
||||
class Help extends React.Component {
|
||||
|
||||
render() {
|
||||
const supportLinks = [
|
||||
{
|
||||
content:
|
||||
"Learn more using the [documentation on this site.](/test-site/docs/en/doc1.html)",
|
||||
title: "Browse Docs"
|
||||
'Learn more using the [documentation on this site.](/test-site/docs/en/doc1.html)',
|
||||
title: 'Browse Docs',
|
||||
},
|
||||
{
|
||||
content: "Ask questions about the documentation and project",
|
||||
title: "Join the community"
|
||||
content: 'Ask questions about the documentation and project',
|
||||
title: 'Join the community',
|
||||
},
|
||||
{
|
||||
content: "Find out what's new with this project",
|
||||
title: "Stay up to date"
|
||||
}
|
||||
title: 'Stay up to date',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
* 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 MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */
|
||||
const Container = CompLibrary.Container;
|
||||
const GridBlock = CompLibrary.GridBlock;
|
||||
|
||||
const siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const siteConfig = require(process.cwd() + '/siteConfig.js');
|
||||
|
||||
class Button extends React.Component {
|
||||
render() {
|
||||
|
@ -27,7 +27,7 @@ class Button extends React.Component {
|
|||
}
|
||||
|
||||
Button.defaultProps = {
|
||||
target: "_self"
|
||||
target: '_self',
|
||||
};
|
||||
|
||||
class HomeSplash extends React.Component {
|
||||
|
@ -37,14 +37,12 @@ class HomeSplash extends React.Component {
|
|||
<div className="homeSplashFade">
|
||||
<div className="wrapper homeWrapper">
|
||||
<div className="projectLogo">
|
||||
<img src={siteConfig.baseUrl + "img/docusaurus.svg"} />
|
||||
<img src={siteConfig.baseUrl + 'img/docusaurus.svg'} />
|
||||
</div>
|
||||
<div className="inner">
|
||||
<h2 className="projectTitle">
|
||||
{siteConfig.title}
|
||||
<small>
|
||||
{siteConfig.tagline}
|
||||
</small>
|
||||
<small>{siteConfig.tagline}</small>
|
||||
</h2>
|
||||
<div className="section promoSection">
|
||||
<div className="promoRow">
|
||||
|
@ -53,21 +51,19 @@ class HomeSplash extends React.Component {
|
|||
<Button
|
||||
href={
|
||||
siteConfig.baseUrl +
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
this.props.language +
|
||||
"/doc1.html"
|
||||
}
|
||||
>
|
||||
'/doc1.html'
|
||||
}>
|
||||
Example Link
|
||||
</Button>
|
||||
<Button
|
||||
href={
|
||||
siteConfig.baseUrl +
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
this.props.language +
|
||||
"/doc2.html"
|
||||
}
|
||||
>
|
||||
'/doc2.html'
|
||||
}>
|
||||
Example Link 2
|
||||
</Button>
|
||||
</div>
|
||||
|
@ -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 {
|
|||
<div>
|
||||
<HomeSplash language={language} />
|
||||
<div className="mainContainer">
|
||||
<Container padding={["bottom", "top"]}>
|
||||
<Container padding={['bottom', 'top']}>
|
||||
<GridBlock
|
||||
align="center"
|
||||
contents={[
|
||||
{
|
||||
content: "This is the content of my feature",
|
||||
image: siteConfig.baseUrl + "img/docusaurus.svg",
|
||||
imageAlign: "top",
|
||||
title: "Feature One"
|
||||
content: 'This is the content of my feature',
|
||||
image: siteConfig.baseUrl + 'img/docusaurus.svg',
|
||||
imageAlign: 'top',
|
||||
title: 'Feature One',
|
||||
},
|
||||
{
|
||||
content: "The content of my second feature",
|
||||
image: siteConfig.baseUrl + "img/docusaurus.svg",
|
||||
imageAlign: "top",
|
||||
title: "Feature Two"
|
||||
}
|
||||
content: 'The content of my second feature',
|
||||
image: siteConfig.baseUrl + 'img/docusaurus.svg',
|
||||
imageAlign: 'top',
|
||||
title: 'Feature Two',
|
||||
},
|
||||
]}
|
||||
layout="fourColumn"
|
||||
/>
|
||||
|
@ -123,67 +119,61 @@ class Index extends React.Component {
|
|||
|
||||
<div
|
||||
className="productShowcaseSection paddingBottom"
|
||||
style={{ textAlign: "center" }}
|
||||
>
|
||||
style={{textAlign: 'center'}}>
|
||||
<h2>Feature Callout</h2>
|
||||
<MarkdownBlock>These are features of this project</MarkdownBlock>
|
||||
</div>
|
||||
|
||||
<Container padding={["bottom", "top"]} background="light">
|
||||
<Container padding={['bottom', 'top']} background="light">
|
||||
<GridBlock
|
||||
contents={[
|
||||
{
|
||||
content: "Talk about learning how to use this",
|
||||
image: siteConfig.baseUrl + "img/docusaurus.svg",
|
||||
imageAlign: "right",
|
||||
title: "Learn How"
|
||||
}
|
||||
content: 'Talk about learning how to use this',
|
||||
image: siteConfig.baseUrl + 'img/docusaurus.svg',
|
||||
imageAlign: 'right',
|
||||
title: 'Learn How',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Container>
|
||||
|
||||
<Container padding={["bottom", "top"]} id="try">
|
||||
<Container padding={['bottom', 'top']} id="try">
|
||||
<GridBlock
|
||||
contents={[
|
||||
{
|
||||
content: "Talk about trying this out",
|
||||
image: siteConfig.baseUrl + "img/docusaurus.svg",
|
||||
imageAlign: "left",
|
||||
title: "Try it Out"
|
||||
}
|
||||
content: 'Talk about trying this out',
|
||||
image: siteConfig.baseUrl + 'img/docusaurus.svg',
|
||||
imageAlign: 'left',
|
||||
title: 'Try it Out',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Container>
|
||||
|
||||
<Container padding={["bottom", "top"]} background="dark">
|
||||
<Container padding={['bottom', 'top']} background="dark">
|
||||
<GridBlock
|
||||
contents={[
|
||||
{
|
||||
content:
|
||||
"This is another description of how this project is useful",
|
||||
image: siteConfig.baseUrl + "img/docusaurus.svg",
|
||||
imageAlign: "right",
|
||||
title: "Description"
|
||||
}
|
||||
'This is another description of how this project is useful',
|
||||
image: siteConfig.baseUrl + 'img/docusaurus.svg',
|
||||
imageAlign: 'right',
|
||||
title: 'Description',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Container>
|
||||
|
||||
<div className="productShowcaseSection paddingBottom">
|
||||
<h2>
|
||||
{"Who's Using This?"}
|
||||
</h2>
|
||||
<h2>{"Who's Using This?"}</h2>
|
||||
<p>This project is used by all these people</p>
|
||||
<div className="logos">
|
||||
{showcase}
|
||||
</div>
|
||||
<div className="logos">{showcase}</div>
|
||||
<div className="more-users">
|
||||
<a
|
||||
className="button"
|
||||
href={
|
||||
siteConfig.baseUrl + this.props.language + "/" + "users.html"
|
||||
}
|
||||
>
|
||||
siteConfig.baseUrl + this.props.language + '/' + 'users.html'
|
||||
}>
|
||||
More {siteConfig.title} Users
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -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 (
|
||||
<div className="mainContainer">
|
||||
<Container padding={["bottom", "top"]}>
|
||||
<Container padding={['bottom', 'top']}>
|
||||
<div className="showcaseSection">
|
||||
<div className="prose">
|
||||
<h1>Who's Using This?</h1>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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: (
|
||||
<translate>
|
||||
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)
|
||||
</translate>
|
||||
),
|
||||
title: <translate>Browse Docs</translate>
|
||||
title: <translate>Browse Docs</translate>,
|
||||
},
|
||||
{
|
||||
content: (
|
||||
|
@ -32,12 +33,12 @@ class Help extends React.Component {
|
|||
Ask questions about the documentation and project
|
||||
</translate>
|
||||
),
|
||||
title: <translate>Join the community</translate>
|
||||
title: <translate>Join the community</translate>,
|
||||
},
|
||||
{
|
||||
content: <translate>Find out what's new with this project</translate>,
|
||||
title: <translate>Stay up to date</translate>
|
||||
}
|
||||
title: <translate>Stay up to date</translate>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
@ -63,7 +64,7 @@ class Help extends React.Component {
|
|||
}
|
||||
|
||||
Help.defaultProps = {
|
||||
language: "en"
|
||||
language: 'en',
|
||||
};
|
||||
|
||||
module.exports = Help;
|
||||
|
|
|
@ -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 {
|
|||
<Container className="mainContainer versionsContainer">
|
||||
<div className="post">
|
||||
<header className="postHeader">
|
||||
<h2>{siteConfig.title + " Versions"}</h2>
|
||||
<h2>{siteConfig.title + ' Versions'}</h2>
|
||||
</header>
|
||||
<p>New versions of this project are released every so often.</p>
|
||||
<a name="latest" />
|
||||
|
@ -32,14 +32,12 @@ class Versions extends React.Component {
|
|||
<table className="versions">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
{latestVersion}
|
||||
</th>
|
||||
<th>{latestVersion}</th>
|
||||
<td>
|
||||
<a href={""}>Documentation</a>
|
||||
<a href={''}>Documentation</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href={""}>Release Notes</a>
|
||||
<a href={''}>Release Notes</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -55,10 +53,10 @@ class Versions extends React.Component {
|
|||
<tr>
|
||||
<th>master</th>
|
||||
<td>
|
||||
<a href={""}>Documentation</a>
|
||||
<a href={''}>Documentation</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href={""}>Release Notes</a>
|
||||
<a href={''}>Release Notes</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -70,23 +68,22 @@ class Versions extends React.Component {
|
|||
<tbody>
|
||||
{versions.map(
|
||||
version =>
|
||||
version !== latestVersion &&
|
||||
version !== latestVersion && (
|
||||
<tr>
|
||||
<th>
|
||||
{version}
|
||||
</th>
|
||||
<th>{version}</th>
|
||||
<td>
|
||||
<a href={""}>Documentation</a>
|
||||
<a href={''}>Documentation</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href={""}>Release Notes</a>
|
||||
<a href={''}>Release Notes</a>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
You can find past versions of this project{" "}
|
||||
You can find past versions of this project{' '}
|
||||
<a href="https://github.com/"> on GitHub </a>.
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -7,25 +7,25 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
require("babel-register")({
|
||||
require('babel-register')({
|
||||
babelrc: false,
|
||||
only: [__dirname, process.cwd() + "/core"],
|
||||
plugins: [require("./server/translate-plugin.js")],
|
||||
presets: ["react", "env"]
|
||||
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")) {
|
||||
if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
||||
console.error(
|
||||
chalk.red("Error: No siteConfig.js file found in website folder!")
|
||||
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();
|
||||
|
|
|
@ -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`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,10 +34,8 @@ class BlogPageLayout extends React.Component {
|
|||
/>
|
||||
<Container className="mainContainer documentContainer postContainer blogContainer">
|
||||
<div className="posts">
|
||||
{MetadataBlog.slice(
|
||||
page * perPage,
|
||||
(page + 1) * perPage
|
||||
).map(post => {
|
||||
{MetadataBlog.slice(page * perPage, (page + 1) * perPage).map(
|
||||
post => {
|
||||
return (
|
||||
<BlogPost
|
||||
post={post}
|
||||
|
@ -47,7 +45,8 @@ class BlogPageLayout extends React.Component {
|
|||
config={this.props.config}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
}
|
||||
)}
|
||||
<div className="docs-prevnext">
|
||||
{page > 0 && (
|
||||
<a className="docs-prev" href={this.getPageURL(page - 1)}>
|
||||
|
|
|
@ -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("<!--truncate-->").length > 1) {
|
||||
if (content.split('<!--truncate-->').length > 1) {
|
||||
hasSplit = (
|
||||
<div className="read-more">
|
||||
<a
|
||||
className="button"
|
||||
href={this.props.config.baseUrl + "blog/" + this.props.post.path}>
|
||||
href={this.props.config.baseUrl + 'blog/' + this.props.post.path}>
|
||||
Read More
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (this.props.truncate) {
|
||||
content = content.split("<!--truncate-->")[0];
|
||||
content = content.split('<!--truncate-->')[0];
|
||||
return (
|
||||
<article className="post-content">
|
||||
<MarkdownBlock>{content}</MarkdownBlock>
|
||||
|
@ -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 (
|
||||
<div className={className}>
|
||||
<a href={post.authorURL} target="_blank">
|
||||
<img
|
||||
src={
|
||||
"https://graph.facebook.com/" +
|
||||
'https://graph.facebook.com/' +
|
||||
post.authorFBID +
|
||||
"/picture/?height=200&width=200"
|
||||
'/picture/?height=200&width=200'
|
||||
}
|
||||
/>
|
||||
</a>
|
||||
|
@ -72,7 +72,7 @@ class BlogPost extends React.Component {
|
|||
const post = this.props.post;
|
||||
return (
|
||||
<h1>
|
||||
<a href={this.props.config.baseUrl + "blog/" + post.path}>
|
||||
<a href={this.props.config.baseUrl + 'blog/' + post.path}>
|
||||
{post.title}
|
||||
</a>
|
||||
</h1>
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 ?
|
||||
const fbLike = this.props.config.facebookAppId ? (
|
||||
<div
|
||||
className="fb-like"
|
||||
data-layout="standard"
|
||||
data-share="true"
|
||||
data-width="225"
|
||||
data-show-faces="false">
|
||||
</div>
|
||||
: null;
|
||||
data-show-faces="false"
|
||||
/>
|
||||
) : null;
|
||||
|
||||
const twitterShare = this.props.config.twitter ?
|
||||
<a href="https://twitter.com/share" className="twitter-share-button" data-text={post.title} data-url={this.props.config.url + this.props.config.baseUrl + "blog/" + post.path} data-related={this.props.config.twitter} data-via={post.authorTwitter} data-show-count="false">Tweet</a>
|
||||
: null;
|
||||
const twitterShare = this.props.config.twitter ? (
|
||||
<a
|
||||
href="https://twitter.com/share"
|
||||
className="twitter-share-button"
|
||||
data-text={post.title}
|
||||
data-url={
|
||||
this.props.config.url +
|
||||
this.props.config.baseUrl +
|
||||
'blog/' +
|
||||
post.path
|
||||
}
|
||||
data-related={this.props.config.twitter}
|
||||
data-via={post.authorTwitter}
|
||||
data-show-count="false">
|
||||
Tweet
|
||||
</a>
|
||||
) : null;
|
||||
|
||||
if (!fbLike && !twitterShare) {
|
||||
return;
|
||||
|
@ -51,15 +64,14 @@ class BlogPostLayout extends React.Component {
|
|||
return (
|
||||
<Site
|
||||
className="sideNavVisible"
|
||||
url={"blog/" + this.props.metadata.path}
|
||||
url={'blog/' + this.props.metadata.path}
|
||||
title={this.props.metadata.title}
|
||||
language={"en"}
|
||||
description={this.props.children.trim().split("\n")[0]}
|
||||
config={this.props.config}
|
||||
>
|
||||
language={'en'}
|
||||
description={this.props.children.trim().split('\n')[0]}
|
||||
config={this.props.config}>
|
||||
<div className="docMainWrapper wrapper">
|
||||
<BlogSidebar
|
||||
language={"en"}
|
||||
language={'en'}
|
||||
current={this.props.metadata}
|
||||
config={this.props.config}
|
||||
/>
|
||||
|
@ -68,16 +80,13 @@ class BlogPostLayout extends React.Component {
|
|||
<BlogPost
|
||||
post={this.props.metadata}
|
||||
content={this.props.children}
|
||||
language={"en"}
|
||||
language={'en'}
|
||||
config={this.props.config}
|
||||
/>
|
||||
{this.renderSocialButtons()}
|
||||
</div>
|
||||
<div className="blog-recent">
|
||||
<a
|
||||
className="button"
|
||||
href={this.props.config.baseUrl + "blog"}
|
||||
>
|
||||
<a className="button" href={this.props.config.baseUrl + 'blog'}>
|
||||
Recent Posts
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -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 (
|
||||
<Container className="docsNavContainer" id="docsNav" wrapper={false}>
|
||||
<SideNav
|
||||
language={this.props.language}
|
||||
root={this.props.config.baseUrl + "blog/"}
|
||||
root={this.props.config.baseUrl + 'blog/'}
|
||||
title="Blog"
|
||||
contents={contents}
|
||||
current={current}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const MarkdownBlock = require("./MarkdownBlock.js");
|
||||
const Container = require("./Container.js");
|
||||
const GridBlock = require("./GridBlock.js");
|
||||
const MarkdownBlock = require('./MarkdownBlock.js');
|
||||
const Container = require('./Container.js');
|
||||
const GridBlock = require('./GridBlock.js');
|
||||
|
||||
// A collection of components to provide to users
|
||||
module.exports = {
|
||||
MarkdownBlock: MarkdownBlock,
|
||||
Container: Container,
|
||||
GridBlock: GridBlock
|
||||
GridBlock: GridBlock,
|
||||
};
|
||||
|
|
|
@ -5,29 +5,25 @@
|
|||
* 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');
|
||||
|
||||
class Container extends React.Component {
|
||||
render() {
|
||||
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
|
||||
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 = (
|
||||
<div className="wrapper">
|
||||
{this.props.children}
|
||||
</div>
|
||||
);
|
||||
wrappedChildren = <div className="wrapper">{this.props.children}</div>;
|
||||
} 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;
|
||||
|
|
|
@ -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}
|
||||
</a>
|
||||
);
|
||||
if (this.props.language != "en") {
|
||||
if (this.props.language != 'en') {
|
||||
editLink = !this.props.version &&
|
||||
this.props.config.translationRecruitingLink && (
|
||||
<a
|
||||
className="edit-page-link button"
|
||||
href={
|
||||
this.props.config.translationRecruitingLink +
|
||||
"/" +
|
||||
'/' +
|
||||
this.props.language
|
||||
}
|
||||
target="_blank">
|
||||
|
|
|
@ -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}>
|
||||
<div className="docMainWrapper wrapper">
|
||||
|
@ -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 && (
|
||||
<a
|
||||
className="docs-prev button"
|
||||
href={metadata.previous_id + ".html"}>
|
||||
←{" "}
|
||||
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'}
|
||||
</a>
|
||||
)}
|
||||
{metadata.next_id && (
|
||||
<a
|
||||
className="docs-next button"
|
||||
href={metadata.next_id + ".html"}>
|
||||
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'}{' '}
|
||||
→
|
||||
</a>
|
||||
)}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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}
|
||||
<div className="blockContent">
|
||||
{this.renderBlockTitle(block.title)}
|
||||
<MarkdownBlock>
|
||||
{block.content}
|
||||
</MarkdownBlock>
|
||||
<MarkdownBlock>{block.content}</MarkdownBlock>
|
||||
</div>
|
||||
{bottomRightImage}
|
||||
</div>
|
||||
|
@ -73,9 +71,7 @@ class GridBlock extends React.Component {
|
|||
if (title) {
|
||||
return (
|
||||
<h2>
|
||||
<MarkdownBlock>
|
||||
{title}
|
||||
</MarkdownBlock>
|
||||
<MarkdownBlock>{title}</MarkdownBlock>
|
||||
</h2>
|
||||
);
|
||||
} 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;
|
||||
|
|
|
@ -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 && (
|
||||
<meta
|
||||
http-equiv="refresh"
|
||||
content={"0; URL=" + this.props.redirect}
|
||||
content={'0; URL=' + this.props.redirect}
|
||||
/>
|
||||
)}
|
||||
<link
|
||||
|
@ -58,36 +60,38 @@ class Head extends React.Component {
|
|||
)}
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href={`//cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlightVersion}/styles/${highlightTheme}.min.css`}
|
||||
href={`//cdnjs.cloudflare.com/ajax/libs/highlight.js/${
|
||||
highlightVersion
|
||||
}/styles/${highlightTheme}.min.css`}
|
||||
/>
|
||||
{hasBlog && (
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/atom+xml"
|
||||
href={this.props.config.url + "/blog/atom.xml"}
|
||||
title={this.props.config.title + " Blog ATOM Feed"}
|
||||
href={this.props.config.url + '/blog/atom.xml'}
|
||||
title={this.props.config.title + ' Blog ATOM Feed'}
|
||||
/>
|
||||
)}
|
||||
{hasBlog && (
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
href={this.props.config.url + "/blog/feed.xml"}
|
||||
title={this.props.config.title + " Blog RSS Feed"}
|
||||
href={this.props.config.url + '/blog/feed.xml'}
|
||||
title={this.props.config.title + ' Blog RSS Feed'}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* External resources */}
|
||||
{this.props.config.stylesheets && this.props.config.stylesheets.map(function(source) {
|
||||
return (
|
||||
<link rel="stylesheet" href={source} />
|
||||
);
|
||||
{this.props.config.stylesheets &&
|
||||
this.props.config.stylesheets.map(function(source) {
|
||||
return <link rel="stylesheet" href={source} />;
|
||||
})}
|
||||
{this.props.config.scripts && this.props.config.scripts.map(function(source, idx) {
|
||||
{this.props.config.scripts &&
|
||||
this.props.config.scripts.map(function(source, idx) {
|
||||
return (
|
||||
<script
|
||||
type="text/javascript"
|
||||
key={"script" + idx}
|
||||
key={'script' + idx}
|
||||
src={source}
|
||||
/>
|
||||
);
|
||||
|
@ -96,7 +100,7 @@ class Head extends React.Component {
|
|||
{/* Site defined code. Keep these at the end to avoid overriding. */}
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href={this.props.config.baseUrl + "css/main.css"}
|
||||
href={this.props.config.baseUrl + 'css/main.css'}
|
||||
/>
|
||||
</head>
|
||||
);
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const React = require("react");
|
||||
const toSlug = require("./toSlug.js");
|
||||
const React = require('react');
|
||||
const toSlug = require('./toSlug.js');
|
||||
|
||||
class Header extends React.Component {
|
||||
render() {
|
||||
const slug = toSlug(this.props.toSlug || this.props.children);
|
||||
const Heading = "h" + this.props.level;
|
||||
const Heading = 'h' + this.props.level;
|
||||
|
||||
return (
|
||||
<Heading {...this.props}>
|
||||
<a className="anchor" name={slug} />
|
||||
{this.props.children}{" "}
|
||||
<a className="hash-link" href={"#" + slug}>
|
||||
{this.props.children}{' '}
|
||||
<a className="hash-link" href={'#' + slug}>
|
||||
#
|
||||
</a>
|
||||
</Heading>
|
||||
|
|
|
@ -14,11 +14,8 @@ const Remarkable = require('./Remarkable');
|
|||
|
||||
class MarkdownBlock extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Remarkable source={this.props.children} />
|
||||
);
|
||||
return <Remarkable source={this.props.children} />;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MarkdownBlock;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const React = require("react");
|
||||
const fs = require("fs");
|
||||
const Head = require("./Head.js");
|
||||
const translation = require("../server/translation.js");
|
||||
const React = require('react');
|
||||
const fs = require('fs');
|
||||
const Head = require('./Head.js');
|
||||
const translation = require('../server/translation.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
||||
|
@ -16,24 +16,24 @@ const CWD = process.cwd();
|
|||
class Redirect extends React.Component {
|
||||
render() {
|
||||
const tagline = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"].tagline
|
||||
? translation[this.props.language]['localized-strings'].tagline
|
||||
: this.props.config.tagline;
|
||||
const title = this.props.title
|
||||
? this.props.title + " · " + this.props.config.title
|
||||
? this.props.title + ' · ' + this.props.config.title
|
||||
: (!this.props.config.disableTitleTagline &&
|
||||
this.props.config.title + " · " + tagline) ||
|
||||
this.props.config.title + ' · ' + tagline) ||
|
||||
this.props.config.title;
|
||||
const description = this.props.description || tagline;
|
||||
const url =
|
||||
this.props.config.url +
|
||||
this.props.config.baseUrl +
|
||||
(this.props.url || "index.html");
|
||||
(this.props.url || 'index.html');
|
||||
let latestVersion;
|
||||
|
||||
const redirect = this.props.redirect || false;
|
||||
|
||||
if (fs.existsSync(CWD + "/versions.json")) {
|
||||
latestVersion = require(CWD + "/versions.json")[0];
|
||||
if (fs.existsSync(CWD + '/versions.json')) {
|
||||
latestVersion = require(CWD + '/versions.json')[0];
|
||||
}
|
||||
return (
|
||||
<html>
|
||||
|
@ -51,7 +51,7 @@ class Redirect extends React.Component {
|
|||
<!--
|
||||
window.location.href = "${this.props.redirect}";
|
||||
// -->
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</body>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const React = require('react');
|
||||
const hljs = require('highlight.js')
|
||||
const hljs = require('highlight.js');
|
||||
const Markdown = require('remarkable');
|
||||
const toSlug = require("./toSlug.js");
|
||||
const toSlug = require('./toSlug.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
||||
|
@ -13,21 +13,37 @@ const CWD = process.cwd();
|
|||
function anchors(md) {
|
||||
md.renderer.rules.heading_open = function(tokens, idx /*, options, env */) {
|
||||
const textToken = tokens[idx + 1];
|
||||
return '<h' + tokens[idx].hLevel + '><a class="anchor" aria-hidden="true" name="' + toSlug(textToken.content) + '"></a><a href="#' + toSlug(textToken.content) + '" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>';
|
||||
return (
|
||||
'<h' +
|
||||
tokens[idx].hLevel +
|
||||
'><a class="anchor" aria-hidden="true" name="' +
|
||||
toSlug(textToken.content) +
|
||||
'"></a><a href="#' +
|
||||
toSlug(textToken.content) +
|
||||
'" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>'
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
class Remarkable extends React.Component {
|
||||
content() {
|
||||
if (this.props.source) {
|
||||
return <span dangerouslySetInnerHTML={{ __html: this.renderMarkdown(this.props.source) }} />;
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<span
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: this.renderMarkdown(this.props.source),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return React.Children.map(this.props.children, child => {
|
||||
if (typeof child === 'string') {
|
||||
return <span dangerouslySetInnerHTML={{ __html: this.renderMarkdown(child) }} />;
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<span
|
||||
dangerouslySetInnerHTML={{__html: this.renderMarkdown(child)}}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return child;
|
||||
}
|
||||
});
|
||||
|
@ -36,14 +52,15 @@ class Remarkable extends React.Component {
|
|||
|
||||
renderMarkdown(source) {
|
||||
if (!this.md) {
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
this.md = new Markdown({
|
||||
// Highlight.js expects hljs css classes on the code element.
|
||||
// This results in <pre><code class="hljs css javascript">
|
||||
langPrefix: 'hljs css ',
|
||||
highlight: function(str, lang) {
|
||||
lang = lang || (siteConfig.highlight && siteConfig.highlight.defaultLang);
|
||||
lang =
|
||||
lang || (siteConfig.highlight && siteConfig.highlight.defaultLang);
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(lang, str).value;
|
||||
|
@ -69,7 +86,6 @@ class Remarkable extends React.Component {
|
|||
this.md.use(plugin);
|
||||
}, this);
|
||||
}
|
||||
|
||||
}
|
||||
const html = this.md.render(source);
|
||||
|
||||
|
@ -81,11 +97,7 @@ class Remarkable extends React.Component {
|
|||
render() {
|
||||
var Container = this.props.container;
|
||||
|
||||
return (
|
||||
<Container>
|
||||
{this.content()}
|
||||
</Container>
|
||||
);
|
||||
return <Container>{this.content()}</Container>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const React = require("react");
|
||||
const fs = require("fs");
|
||||
const HeaderNav = require("./nav/HeaderNav.js");
|
||||
const Head = require("./Head.js");
|
||||
const Footer = require(process.cwd() + "/core/Footer.js");
|
||||
const translation = require("../server/translation.js");
|
||||
const React = require('react');
|
||||
const fs = require('fs');
|
||||
const HeaderNav = require('./nav/HeaderNav.js');
|
||||
const Head = require('./Head.js');
|
||||
const Footer = require(process.cwd() + '/core/Footer.js');
|
||||
const translation = require('../server/translation.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
||||
|
@ -18,28 +18,28 @@ const CWD = process.cwd();
|
|||
class Site extends React.Component {
|
||||
render() {
|
||||
const tagline = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"].tagline
|
||||
? translation[this.props.language]['localized-strings'].tagline
|
||||
: this.props.config.tagline;
|
||||
const title = this.props.title
|
||||
? this.props.title + " · " + this.props.config.title
|
||||
? this.props.title + ' · ' + this.props.config.title
|
||||
: (!this.props.config.disableTitleTagline &&
|
||||
this.props.config.title + " · " + tagline) ||
|
||||
this.props.config.title + ' · ' + tagline) ||
|
||||
this.props.config.title;
|
||||
const description = this.props.description || tagline;
|
||||
const url =
|
||||
this.props.config.url +
|
||||
this.props.config.baseUrl +
|
||||
(this.props.url || "index.html");
|
||||
(this.props.url || 'index.html');
|
||||
let latestVersion;
|
||||
|
||||
const highlightDefaultVersion = "9.12.0";
|
||||
const highlightDefaultVersion = '9.12.0';
|
||||
const highlightConfig = this.props.config.highlight || {
|
||||
version: highlightDefaultVersion,
|
||||
theme: "default"
|
||||
theme: 'default',
|
||||
};
|
||||
const highlightVersion = highlightConfig.version || highlightDefaultVersion;
|
||||
if (fs.existsSync(CWD + "/versions.json")) {
|
||||
latestVersion = require(CWD + "/versions.json")[0];
|
||||
if (fs.existsSync(CWD + '/versions.json')) {
|
||||
latestVersion = require(CWD + '/versions.json')[0];
|
||||
}
|
||||
return (
|
||||
<html>
|
||||
|
@ -78,24 +78,24 @@ class Site extends React.Component {
|
|||
|
||||
ga('create', '${this.props.config.gaTrackingId}', 'auto');
|
||||
ga('send', 'pageview');
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{this.props.config.facebookAppId && (
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.fbAsyncInit = function() {FB.init({appId:'${this
|
||||
.props.config
|
||||
.facebookAppId}',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
`
|
||||
__html: `window.fbAsyncInit = function() {FB.init({appId:'${
|
||||
this.props.config.facebookAppId
|
||||
}',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{this.props.config.twitter && (
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));`
|
||||
__html: `window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
@ -111,10 +111,10 @@ class Site extends React.Component {
|
|||
algoliaOptions: ${JSON.stringify(
|
||||
this.props.config.algolia.algoliaOptions
|
||||
)
|
||||
.replace("VERSION", this.props.version || latestVersion)
|
||||
.replace("LANGUAGE", this.props.language)}
|
||||
.replace('VERSION', this.props.version || latestVersion)
|
||||
.replace('LANGUAGE', this.props.language)}
|
||||
});
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
|
@ -126,7 +126,7 @@ class Site extends React.Component {
|
|||
indexName: '${this.props.config.algolia.indexName}',
|
||||
inputSelector: '#search_input_react'
|
||||
});
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
|
|
@ -7,35 +7,35 @@
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const React = require("react");
|
||||
const fs = require("fs");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const translation = require("../../server/translation.js");
|
||||
const React = require('react');
|
||||
const fs = require('fs');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const translation = require('../../server/translation.js');
|
||||
|
||||
const translate = require("../../server/translate.js").translate;
|
||||
const setLanguage = require("../../server/translate.js").setLanguage;
|
||||
const translate = require('../../server/translate.js').translate;
|
||||
const setLanguage = require('../../server/translate.js').setLanguage;
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js');
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + '/versions.json');
|
||||
let versions;
|
||||
if (ENABLE_VERSIONING) {
|
||||
versions = require(CWD + "/versions.json");
|
||||
versions = require(CWD + '/versions.json');
|
||||
}
|
||||
const readMetadata = require("../../server/readMetadata.js");
|
||||
const readMetadata = require('../../server/readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
const Metadata = require("../metadata.js");
|
||||
const Metadata = require('../metadata.js');
|
||||
|
||||
// language dropdown nav item for when translations are enabled
|
||||
class LanguageDropDown extends React.Component {
|
||||
render() {
|
||||
const enabledLanguages = [];
|
||||
let currentLanguage = "English";
|
||||
let currentLanguage = 'English';
|
||||
setLanguage(this.props.language);
|
||||
let helpTranslateString = translate(
|
||||
"Help Translate|recruit community translators for your project"
|
||||
'Help Translate|recruit community translators for your project'
|
||||
);
|
||||
// add all enabled languages to dropdown
|
||||
translation["languages"].map(lang => {
|
||||
translation['languages'].map(lang => {
|
||||
if (lang.tag == this.props.language) {
|
||||
currentLanguage = lang.name;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class LanguageDropDown extends React.Component {
|
|||
<a id="languages-menu" href="#">
|
||||
<img
|
||||
className="languages-icon"
|
||||
src={this.props.baseUrl + "img/language.svg"}
|
||||
src={this.props.baseUrl + 'img/language.svg'}
|
||||
/>
|
||||
{currentLanguage}
|
||||
</a>
|
||||
|
@ -89,7 +89,7 @@ class LanguageDropDown extends React.Component {
|
|||
languagesDropDown.className = "hide";
|
||||
}
|
||||
});
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
|
@ -102,7 +102,7 @@ class HeaderNav extends React.Component {
|
|||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
slideoutActive: false
|
||||
slideoutActive: false,
|
||||
};
|
||||
}
|
||||
// function to generate each header link, used with each object in siteConfig.headerLinks
|
||||
|
@ -127,14 +127,14 @@ class HeaderNav extends React.Component {
|
|||
} else if (link.doc) {
|
||||
// set link to document with current page's language/version
|
||||
let id;
|
||||
if (!ENABLE_VERSIONING || this.props.version === "next") {
|
||||
id = this.props.language + "-" + link.doc;
|
||||
if (!ENABLE_VERSIONING || this.props.version === 'next') {
|
||||
id = this.props.language + '-' + link.doc;
|
||||
} else {
|
||||
id =
|
||||
this.props.language +
|
||||
"-version-" +
|
||||
'-version-' +
|
||||
(this.props.version || versions[0]) +
|
||||
"-" +
|
||||
'-' +
|
||||
link.doc;
|
||||
}
|
||||
if (!Metadata[id]) {
|
||||
|
@ -146,31 +146,31 @@ class HeaderNav extends React.Component {
|
|||
);
|
||||
}
|
||||
throw new Error(
|
||||
"A headerLink is specified with a document that does not exist. No document exists with id: " +
|
||||
'A headerLink is specified with a document that does not exist. No document exists with id: ' +
|
||||
link.doc
|
||||
);
|
||||
}
|
||||
href = this.props.config.baseUrl + Metadata[id].permalink;
|
||||
} else if (link.page) {
|
||||
// set link to page with current page's language if appropriate
|
||||
if (fs.existsSync(CWD + "/pages/en/" + link.page + ".js")) {
|
||||
if (fs.existsSync(CWD + '/pages/en/' + link.page + '.js')) {
|
||||
href =
|
||||
siteConfig.baseUrl + this.props.language + "/" + link.page + ".html";
|
||||
siteConfig.baseUrl + this.props.language + '/' + link.page + '.html';
|
||||
} else {
|
||||
href = siteConfig.baseUrl + link.page + ".html";
|
||||
href = siteConfig.baseUrl + link.page + '.html';
|
||||
}
|
||||
} else if (link.href) {
|
||||
// set link to specified href
|
||||
href = link.href;
|
||||
} else if (link.blog) {
|
||||
// set link to blog url
|
||||
href = this.props.baseUrl + "blog";
|
||||
href = this.props.baseUrl + 'blog';
|
||||
}
|
||||
return (
|
||||
<li key={link.label + "page"}>
|
||||
<a href={href} target={link.external ? "_blank" : "_self"}>
|
||||
<li key={link.label + 'page'}>
|
||||
<a href={href} target={link.external ? '_blank' : '_self'}>
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][link.label]
|
||||
? translation[this.props.language]['localized-strings'][link.label]
|
||||
: link.label}
|
||||
</a>
|
||||
</li>
|
||||
|
@ -181,8 +181,8 @@ class HeaderNav extends React.Component {
|
|||
const versionsLink =
|
||||
this.props.baseUrl +
|
||||
(ENABLE_TRANSLATION
|
||||
? this.props.language + "/versions.html"
|
||||
: "versions.html");
|
||||
? this.props.language + '/versions.html'
|
||||
: 'versions.html');
|
||||
return (
|
||||
<div className="fixedHeaderContainer">
|
||||
<div className="headerWrapper wrapper">
|
||||
|
@ -222,22 +222,26 @@ class HeaderNav extends React.Component {
|
|||
}
|
||||
let search = false;
|
||||
headerLinks.forEach(link => {
|
||||
if (link.doc && !fs.existsSync(CWD + "/../" + readMetadata.getDocsPath() + "/")) {
|
||||
if (
|
||||
link.doc &&
|
||||
!fs.existsSync(CWD + '/../' + readMetadata.getDocsPath() + '/')
|
||||
) {
|
||||
throw new Error(
|
||||
"You have 'doc' in your headerLinks, but no '" + readMetadata.getDocsPath() +
|
||||
"You have 'doc' in your headerLinks, but no '" +
|
||||
readMetadata.getDocsPath() +
|
||||
"' folder exists one level up from " +
|
||||
"'website' folder. Did you run `docusaurus-init` or `npm run examples`? If so, " +
|
||||
"make sure you rename 'docs-examples-from-docusaurus' to 'docs'."
|
||||
);
|
||||
}
|
||||
if (link.blog && !fs.existsSync(CWD + "/blog/")) {
|
||||
if (link.blog && !fs.existsSync(CWD + '/blog/')) {
|
||||
throw new Error(
|
||||
"You have 'blog' in your headerLinks, but no 'blog' folder exists in your " +
|
||||
"'website' folder. Did you run `docusaurus-init` or `npm run examples`? If so, " +
|
||||
"make sure you rename 'blog-examples-from-docusaurus' to 'blog'."
|
||||
);
|
||||
}
|
||||
if (link.page && !fs.existsSync(CWD + "/pages/")) {
|
||||
if (link.page && !fs.existsSync(CWD + '/pages/')) {
|
||||
throw new Error(
|
||||
"You have 'page' in your headerLinks, but no 'pages' folder exists in your " +
|
||||
"'website' folder."
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
* 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 siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const translation = require("../../server/translation.js");
|
||||
const siteConfig = require(process.cwd() + '/siteConfig.js');
|
||||
const translation = require('../../server/translation.js');
|
||||
|
||||
class SideNav extends React.Component {
|
||||
render() {
|
||||
|
@ -39,7 +39,7 @@ class SideNav extends React.Component {
|
|||
toggler.onclick = function() {
|
||||
nav.classList.toggle('docsSliderActive');
|
||||
};
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</nav>
|
||||
|
@ -56,7 +56,7 @@ class SideNav extends React.Component {
|
|||
// return appropriately translated category string
|
||||
getLocalizedCategoryString(category) {
|
||||
let categoryString = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][category] ||
|
||||
? translation[this.props.language]['localized-strings'][category] ||
|
||||
category
|
||||
: category;
|
||||
return categoryString;
|
||||
|
@ -69,12 +69,12 @@ class SideNav extends React.Component {
|
|||
|
||||
if (sbTitle) {
|
||||
localizedString = i18n
|
||||
? i18n["localized-strings"][sbTitle] || sbTitle
|
||||
? i18n['localized-strings'][sbTitle] || sbTitle
|
||||
: sbTitle;
|
||||
} else {
|
||||
const id = metadata.original_id || metadata.localized_id;
|
||||
localizedString = i18n
|
||||
? i18n["localized-strings"][id] || metadata.title
|
||||
? i18n['localized-strings'][id] || metadata.title
|
||||
: metadata.title;
|
||||
}
|
||||
return localizedString;
|
||||
|
@ -88,16 +88,16 @@ class SideNav extends React.Component {
|
|||
return siteConfig.baseUrl + metadata.permalink;
|
||||
}
|
||||
if (metadata.path) {
|
||||
return siteConfig.baseUrl + "blog/" + metadata.path;
|
||||
return siteConfig.baseUrl + 'blog/' + metadata.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
renderItemLink(link) {
|
||||
const itemClasses = classNames("navListItem", {
|
||||
navListItemActive: link.id === this.props.current.id
|
||||
const itemClasses = classNames('navListItem', {
|
||||
navListItemActive: link.id === this.props.current.id,
|
||||
});
|
||||
const linkClasses = classNames("navItem", {
|
||||
navItemActive: link.id === this.props.current.id
|
||||
const linkClasses = classNames('navItem', {
|
||||
navItemActive: link.id === this.props.current.id,
|
||||
});
|
||||
return (
|
||||
<li className={itemClasses} key={link.id}>
|
||||
|
@ -109,6 +109,6 @@ class SideNav extends React.Component {
|
|||
}
|
||||
}
|
||||
SideNav.defaultProps = {
|
||||
contents: []
|
||||
contents: [],
|
||||
};
|
||||
module.exports = SideNav;
|
||||
|
|
|
@ -8,33 +8,33 @@
|
|||
module.exports = string => {
|
||||
// var accents = "àáäâèéëêìíïîòóöôùúüûñç";
|
||||
const accents =
|
||||
"\u00e0\u00e1\u00e4\u00e2\u00e8" +
|
||||
"\u00e9\u00eb\u00ea\u00ec\u00ed\u00ef" +
|
||||
"\u00ee\u00f2\u00f3\u00f6\u00f4\u00f9" +
|
||||
"\u00fa\u00fc\u00fb\u00f1\u00e7";
|
||||
'\u00e0\u00e1\u00e4\u00e2\u00e8' +
|
||||
'\u00e9\u00eb\u00ea\u00ec\u00ed\u00ef' +
|
||||
'\u00ee\u00f2\u00f3\u00f6\u00f4\u00f9' +
|
||||
'\u00fa\u00fc\u00fb\u00f1\u00e7';
|
||||
|
||||
const without = "aaaaeeeeiiiioooouuuunc";
|
||||
const without = 'aaaaeeeeiiiioooouuuunc';
|
||||
|
||||
let slug = string
|
||||
.toString()
|
||||
// Handle uppercase characters
|
||||
.toLowerCase()
|
||||
// Handle accentuated characters
|
||||
.replace(new RegExp("[" + accents + "]", "g"), c => {
|
||||
.replace(new RegExp('[' + accents + ']', 'g'), c => {
|
||||
return without.charAt(accents.indexOf(c));
|
||||
})
|
||||
// Replace `.`, `(` and `?` with blank string like Github does
|
||||
.replace(/\.|\(|\?/g, "")
|
||||
.replace(/\.|\(|\?/g, '')
|
||||
// Dash special characters
|
||||
.replace(/[^a-z0-9]/g, "-")
|
||||
.replace(/[^a-z0-9]/g, '-')
|
||||
// Compress multiple dash
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/-+/g, '-')
|
||||
// Trim dashes
|
||||
.replace(/^-|-$/g, "");
|
||||
.replace(/^-|-$/g, '');
|
||||
|
||||
// Add trailing `-` if string contains ` ...` in the end like Github does
|
||||
if (/\s[.]{1,}/.test(string)) {
|
||||
slug += "-";
|
||||
slug += '-';
|
||||
}
|
||||
|
||||
return slug;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
// Remove the indentation introduced by JSX
|
||||
function unindent(code) {
|
||||
const lines = code.split("\n");
|
||||
if (lines[0] === "") {
|
||||
const lines = code.split('\n');
|
||||
if (lines[0] === '') {
|
||||
lines.shift();
|
||||
}
|
||||
if (lines.length <= 1) {
|
||||
|
@ -17,9 +17,9 @@ function unindent(code) {
|
|||
|
||||
const indent = lines[0].match(/^\s*/)[0];
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
lines[i] = lines[i].replace(new RegExp("^" + indent), "");
|
||||
lines[i] = lines[i].replace(new RegExp('^' + indent), '');
|
||||
}
|
||||
return lines.join("\n");
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
module.exports = unindent;
|
||||
|
|
|
@ -7,25 +7,25 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
require("babel-register")({
|
||||
require('babel-register')({
|
||||
babelrc: false,
|
||||
only: [__dirname, process.cwd() + "/core"],
|
||||
plugins: [require("./server/translate-plugin.js")],
|
||||
presets: ["react", "latest"]
|
||||
only: [__dirname, process.cwd() + '/core'],
|
||||
plugins: [require('./server/translate-plugin.js')],
|
||||
presets: ['react', 'latest'],
|
||||
});
|
||||
|
||||
// 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")) {
|
||||
if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
||||
console.error(
|
||||
chalk.red("Error: No siteConfig.js file found in website folder!")
|
||||
chalk.red('Error: No siteConfig.js file found in website folder!')
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// generate rss feed
|
||||
const feed = require("./server/feed.js");
|
||||
const feed = require('./server/feed.js');
|
||||
console.log(feed());
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const shell = require("shelljs");
|
||||
const shell = require('shelljs');
|
||||
|
||||
if (!shell.which("git")) {
|
||||
shell.echo("Sorry, this script requires git");
|
||||
if (!shell.which('git')) {
|
||||
shell.echo('Sorry, this script requires git');
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
const siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const siteConfig = require(process.cwd() + '/siteConfig.js');
|
||||
const GIT_USER = process.env.GIT_USER;
|
||||
const CURRENT_BRANCH =
|
||||
process.env.CIRCLE_BRANCH || shell.exec("git rev-parse --abbrev-ref HEAD");
|
||||
process.env.CIRCLE_BRANCH || shell.exec('git rev-parse --abbrev-ref HEAD');
|
||||
const ORGANIZATION_NAME =
|
||||
siteConfig.organizationName ||
|
||||
process.env.ORGANIZATION_NAME ||
|
||||
|
@ -30,7 +30,8 @@ const IS_PULL_REQUEST =
|
|||
process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
|
||||
const USE_SSH = process.env.USE_SSH;
|
||||
// github.io indicates organization repos that deploy via master. All others use gh-pages.
|
||||
const DEPLOYMENT_BRANCH = PROJECT_NAME.indexOf(".github.io") !== -1 ? "master" : "gh-pages";
|
||||
const DEPLOYMENT_BRANCH =
|
||||
PROJECT_NAME.indexOf('.github.io') !== -1 ? 'master' : 'gh-pages';
|
||||
|
||||
if (!ORGANIZATION_NAME) {
|
||||
shell.echo(
|
||||
|
@ -47,14 +48,16 @@ if (!PROJECT_NAME) {
|
|||
}
|
||||
|
||||
let remoteBranch;
|
||||
if (USE_SSH === "true") {
|
||||
if (USE_SSH === 'true') {
|
||||
remoteBranch = `git@github.com:${ORGANIZATION_NAME}/${PROJECT_NAME}.git`;
|
||||
} else {
|
||||
remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${PROJECT_NAME}.git`;
|
||||
remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${
|
||||
PROJECT_NAME
|
||||
}.git`;
|
||||
}
|
||||
|
||||
if (IS_PULL_REQUEST) {
|
||||
shell.echo("Skipping deploy on a pull request");
|
||||
shell.echo('Skipping deploy on a pull request');
|
||||
shell.exit(0);
|
||||
}
|
||||
|
||||
|
@ -66,18 +69,18 @@ if (CURRENT_BRANCH === DEPLOYMENT_BRANCH) {
|
|||
}
|
||||
|
||||
if (shell.exec(`node ${__dirname}/build-files.js`).code) {
|
||||
shell.echo("Error: generating html failed");
|
||||
shell.echo('Error: generating html failed');
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
shell.cd(process.cwd());
|
||||
shell.cd("build");
|
||||
shell.cd('build');
|
||||
|
||||
if (
|
||||
shell.exec(`git clone ${remoteBranch} ${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`)
|
||||
.code !== 0
|
||||
) {
|
||||
shell.echo("Error: git clone failed");
|
||||
shell.echo('Error: git clone failed');
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
|
@ -91,7 +94,8 @@ if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
|
|||
} else {
|
||||
if (
|
||||
shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +
|
||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`).code !==
|
||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
|
||||
.code !==
|
||||
0
|
||||
) {
|
||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||
|
@ -99,30 +103,34 @@ if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
|
|||
}
|
||||
}
|
||||
|
||||
shell.exec("git rm -rf .");
|
||||
shell.exec('git rm -rf .');
|
||||
|
||||
shell.cd("../..");
|
||||
shell.cd('../..');
|
||||
|
||||
shell.cp(
|
||||
"-R",
|
||||
'-R',
|
||||
`build/${PROJECT_NAME}/*`,
|
||||
`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}/`
|
||||
);
|
||||
shell.cd(`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
||||
|
||||
const currentCommit = shell.exec("git rev-parse HEAD").stdout.trim();
|
||||
const currentCommit = shell.exec('git rev-parse HEAD').stdout.trim();
|
||||
|
||||
shell.exec("git add --all");
|
||||
shell.exec('git add --all');
|
||||
|
||||
shell.exec(
|
||||
`git commit -m "Deploy website" -m "Deploy website version based on ${currentCommit}"`
|
||||
`git commit -m "Deploy website" -m "Deploy website version based on ${
|
||||
currentCommit
|
||||
}"`
|
||||
);
|
||||
if (shell.exec(`git push origin ${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||
shell.echo("Error: Git push failed");
|
||||
shell.echo('Error: Git push failed');
|
||||
shell.exit(1);
|
||||
} else {
|
||||
shell.echo(
|
||||
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${PROJECT_NAME}/`
|
||||
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${
|
||||
PROJECT_NAME
|
||||
}/`
|
||||
);
|
||||
shell.exit(0);
|
||||
}
|
||||
|
|
|
@ -7,35 +7,35 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const chalk = require("chalk");
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const path = require("path");
|
||||
const readMetadata = require("./server/readMetadata.js");
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const readMetadata = require('./server/readMetadata.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
||||
// escape appropriate characters in a string to be used in a regex
|
||||
RegExp.escape = function(s) {
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
};
|
||||
|
||||
// generate a doc header from metadata
|
||||
function makeHeader(metadata) {
|
||||
let header = "---\n";
|
||||
let header = '---\n';
|
||||
Object.keys(metadata).forEach(key => {
|
||||
header += key + ": " + metadata[key] + "\n";
|
||||
header += key + ': ' + metadata[key] + '\n';
|
||||
});
|
||||
header += "---\n";
|
||||
header += '---\n';
|
||||
return header;
|
||||
}
|
||||
|
||||
let currentVersion, newVersion;
|
||||
|
||||
const program = require("commander");
|
||||
const program = require('commander');
|
||||
|
||||
program
|
||||
.arguments("<version_name> <new_version_name>")
|
||||
.arguments('<version_name> <new_version_name>')
|
||||
.action((ver1, ver2) => {
|
||||
currentVersion = ver1;
|
||||
newVersion = ver2;
|
||||
|
@ -45,58 +45,60 @@ program
|
|||
// require user to input two command line arguments, current version to be
|
||||
// renamed, and new version name
|
||||
if (
|
||||
typeof currentVersion === "undefined" ||
|
||||
typeof newVersion === "undefined"
|
||||
typeof currentVersion === 'undefined' ||
|
||||
typeof newVersion === 'undefined'
|
||||
) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Version numbers are not properly specified!"
|
||||
'Version numbers are not properly specified!'
|
||||
)}\nSpecify as command line arguments: the current version you wish to rename, then the version number you want to rename it to. `
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// error if no versions currently exist
|
||||
if (!fs.existsSync(CWD + "/versions.json")) {
|
||||
if (!fs.existsSync(CWD + '/versions.json')) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"No versions found!"
|
||||
'No versions found!'
|
||||
)}\nNo versions.json file currently exists. Use the \`versions\` script if you wish to create new versions.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const versions = JSON.parse(fs.readFileSync(CWD + "/versions.json", "utf8"));
|
||||
const versions = JSON.parse(fs.readFileSync(CWD + '/versions.json', 'utf8'));
|
||||
|
||||
const versionIndex = versions.indexOf(currentVersion);
|
||||
// error if current specified version does not exist
|
||||
if (versionIndex < 0) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Version " + currentVersion + " does not currently exist!"
|
||||
)}\n Version ${currentVersion} is not in the versions.json file. You can only rename existing versions.`
|
||||
'Version ' + currentVersion + ' does not currently exist!'
|
||||
)}\n Version ${
|
||||
currentVersion
|
||||
} is not in the versions.json file. You can only rename existing versions.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
// replace old version with new version in versions.json file
|
||||
versions[versionIndex] = newVersion;
|
||||
fs.writeFileSync(CWD + "/versions.json", JSON.stringify(versions));
|
||||
fs.writeFileSync(CWD + '/versions.json', JSON.stringify(versions));
|
||||
|
||||
// if folder of docs for this version exists, rename folder and rewrite doc
|
||||
// headers to use new version
|
||||
if (fs.existsSync(CWD + "/versioned_docs/version-" + currentVersion)) {
|
||||
if (fs.existsSync(CWD + '/versioned_docs/version-' + currentVersion)) {
|
||||
fs.renameSync(
|
||||
CWD + "/versioned_docs/version-" + currentVersion,
|
||||
CWD + "/versioned_docs/version-" + newVersion
|
||||
CWD + '/versioned_docs/version-' + currentVersion,
|
||||
CWD + '/versioned_docs/version-' + newVersion
|
||||
);
|
||||
|
||||
const files = glob.sync(CWD + "/versioned_docs/version-" + newVersion + "/*");
|
||||
const files = glob.sync(CWD + '/versioned_docs/version-' + newVersion + '/*');
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== ".md" && extension !== ".markdown") {
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
const res = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const res = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
const metadata = res.metadata;
|
||||
const rawContent = res.rawContent;
|
||||
if (!metadata.id) {
|
||||
|
@ -113,21 +115,21 @@ if (fs.existsSync(CWD + "/versioned_docs/version-" + currentVersion)) {
|
|||
// if sidebar file exists for this version, rename sidebar file and rewrite
|
||||
// doc ids in the file
|
||||
let currentSidebarFile =
|
||||
CWD + "/versioned_sidebars/version-" + currentVersion + "-sidebar.json";
|
||||
CWD + '/versioned_sidebars/version-' + currentVersion + '-sidebar.json';
|
||||
let newSidebarFile =
|
||||
CWD + "/versioned_sidebars/version-" + newVersion + "-sidebar.json";
|
||||
CWD + '/versioned_sidebars/version-' + newVersion + '-sidebar.json';
|
||||
if (fs.existsSync(currentSidebarFile)) {
|
||||
fs.renameSync(currentSidebarFile, newSidebarFile);
|
||||
let sidebarContent = fs.readFileSync(newSidebarFile, "utf8");
|
||||
let sidebarContent = fs.readFileSync(newSidebarFile, 'utf8');
|
||||
sidebarContent = sidebarContent.replace(
|
||||
new RegExp(`version-${RegExp.escape(currentVersion)}-`, "g"),
|
||||
new RegExp(`version-${RegExp.escape(currentVersion)}-`, 'g'),
|
||||
`version-${newVersion}-`
|
||||
);
|
||||
fs.writeFileSync(newSidebarFile, sidebarContent);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${chalk.green("Successfully enamed version ")}${chalk.yellow(
|
||||
`${chalk.green('Successfully enamed version ')}${chalk.yellow(
|
||||
currentVersion
|
||||
)}${chalk.green(" to version ")}${chalk.yellow(newVersion)}\n`
|
||||
)}${chalk.green(' to version ')}${chalk.yellow(newVersion)}\n`
|
||||
);
|
||||
|
|
|
@ -5,18 +5,18 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const Feed = require("feed");
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const Feed = require('feed');
|
||||
|
||||
const chalk = require("chalk");
|
||||
const chalk = require('chalk');
|
||||
const CWD = process.cwd();
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const blogFolder = path.resolve("../blog/");
|
||||
const blogRootURL = siteConfig.url + "/blog";
|
||||
const blogFolder = path.resolve('../blog/');
|
||||
const blogRootURL = siteConfig.url + '/blog';
|
||||
const jestImage = siteConfig.url + siteConfig.headerIcon;
|
||||
|
||||
/****************************************************************************/
|
||||
|
@ -24,40 +24,40 @@ const jestImage = siteConfig.url + siteConfig.headerIcon;
|
|||
let readMetadata;
|
||||
let Metadata;
|
||||
|
||||
readMetadata = require("./readMetadata.js");
|
||||
readMetadata = require('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
Metadata = require("../core/metadata.js");
|
||||
Metadata = require('../core/metadata.js');
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
module.exports = function(type) {
|
||||
console.log("feed.js triggered...");
|
||||
console.log('feed.js triggered...');
|
||||
|
||||
type = type || "rss";
|
||||
type = type || 'rss';
|
||||
|
||||
readMetadata.generateMetadataBlog();
|
||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||
const MetadataBlog = require('../core/MetadataBlog.js');
|
||||
|
||||
const feed = new Feed({
|
||||
title: siteConfig.title + " Blog",
|
||||
title: siteConfig.title + ' Blog',
|
||||
description:
|
||||
"The best place to stay up-to-date with the latest " +
|
||||
'The best place to stay up-to-date with the latest ' +
|
||||
siteConfig.title +
|
||||
" news and events.",
|
||||
' news and events.',
|
||||
id: blogRootURL,
|
||||
link: blogRootURL,
|
||||
image: jestImage,
|
||||
copyright: siteConfig.copyright,
|
||||
updated: new Date(MetadataBlog[0].date)
|
||||
updated: new Date(MetadataBlog[0].date),
|
||||
});
|
||||
|
||||
MetadataBlog.forEach(post => {
|
||||
const url = blogRootURL + "/" + post.path;
|
||||
let content = "";
|
||||
if (post.content.indexOf("<!--truncate-->") == -1) {
|
||||
const url = blogRootURL + '/' + post.path;
|
||||
let content = '';
|
||||
if (post.content.indexOf('<!--truncate-->') == -1) {
|
||||
content = post.content.trim().substring(0, 250);
|
||||
} else {
|
||||
let contentArr = post.content.split("<!--truncate-->");
|
||||
let contentArr = post.content.split('<!--truncate-->');
|
||||
if (contentArr.length > 0) {
|
||||
content = contentArr[0];
|
||||
}
|
||||
|
@ -69,13 +69,13 @@ module.exports = function(type) {
|
|||
author: [
|
||||
{
|
||||
name: post.author,
|
||||
link: post.authorURL
|
||||
}
|
||||
link: post.authorURL,
|
||||
},
|
||||
],
|
||||
date: new Date(post.date),
|
||||
description: content
|
||||
description: content,
|
||||
});
|
||||
});
|
||||
|
||||
return type === "rss" ? feed.rss2() : feed.atom1();
|
||||
return type === 'rss' ? feed.rss2() : feed.atom1();
|
||||
};
|
||||
|
|
|
@ -6,51 +6,51 @@
|
|||
*/
|
||||
|
||||
function execute() {
|
||||
const extractTranslations = require("../write-translations.js");
|
||||
const extractTranslations = require('../write-translations.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
const fs = require("fs-extra");
|
||||
const readMetadata = require("./readMetadata.js");
|
||||
const renderToStaticMarkup = require("react-dom/server").renderToStaticMarkup;
|
||||
const path = require("path");
|
||||
const toSlug = require("../core/toSlug.js");
|
||||
const React = require("react");
|
||||
const mkdirp = require("mkdirp");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const Site = require("../core/Site.js");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const translate = require("./translate.js");
|
||||
const versionFallback = require("./versionFallback.js");
|
||||
const fs = require('fs-extra');
|
||||
const readMetadata = require('./readMetadata.js');
|
||||
const renderToStaticMarkup = require('react-dom/server').renderToStaticMarkup;
|
||||
const path = require('path');
|
||||
const toSlug = require('../core/toSlug.js');
|
||||
const React = require('react');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const Site = require('../core/Site.js');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const translate = require('./translate.js');
|
||||
const versionFallback = require('./versionFallback.js');
|
||||
|
||||
const feed = require("./feed.js");
|
||||
const sitemap = require("./sitemap.js");
|
||||
const feed = require('./feed.js');
|
||||
const sitemap = require('./sitemap.js');
|
||||
|
||||
const join = path.join;
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(join(CWD, "languages.js"));
|
||||
const ENABLE_VERSIONING = fs.existsSync(join(CWD, "versions.json"));
|
||||
const ENABLE_TRANSLATION = fs.existsSync(join(CWD, 'languages.js'));
|
||||
const ENABLE_VERSIONING = fs.existsSync(join(CWD, 'versions.json'));
|
||||
|
||||
let languages;
|
||||
if (ENABLE_TRANSLATION) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
// create the folder path for a file if it does not exist, then write the file
|
||||
function writeFileAndCreateFolder(file, content) {
|
||||
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(file.replace(new RegExp('/[^/]*$'), ''));
|
||||
|
||||
fs.writeFileSync(file, content);
|
||||
}
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = "<AUTOGENERATED_TABLE_OF_CONTENTS>";
|
||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
||||
|
||||
// takes the content of a doc article and returns the content with a table of
|
||||
// contents inserted
|
||||
|
@ -64,7 +64,7 @@ function execute() {
|
|||
|
||||
const tableOfContents = headers
|
||||
.map(header => ` - [${header}](#${toSlug(header)})`)
|
||||
.join("\n");
|
||||
.join('\n');
|
||||
|
||||
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
|
||||
};
|
||||
|
@ -83,7 +83,7 @@ function execute() {
|
|||
return false;
|
||||
}
|
||||
|
||||
console.log("generate.js triggered...");
|
||||
console.log('generate.js triggered...');
|
||||
|
||||
// array of tags of enabled languages
|
||||
const enabledLanguages = [];
|
||||
|
@ -92,7 +92,7 @@ function execute() {
|
|||
});
|
||||
|
||||
readMetadata.generateMetadataDocs();
|
||||
const Metadata = require("../core/metadata.js");
|
||||
const Metadata = require('../core/metadata.js');
|
||||
|
||||
// TODO: what if the project is a github org page? We should not use
|
||||
// siteConfig.projectName in this case. Otherwise a GitHub org doc URL would
|
||||
|
@ -102,30 +102,30 @@ function execute() {
|
|||
// `title`. `projectName` is only used to generate a folder, which isn't
|
||||
// needed when the project's a GitHub org page
|
||||
|
||||
const buildDir = join(CWD, "build", siteConfig.projectName);
|
||||
const buildDir = join(CWD, 'build', siteConfig.projectName);
|
||||
|
||||
// mdToHtml is a map from a markdown file name to its html link, used to
|
||||
// change relative markdown links that work on GitHub into actual site links
|
||||
const mdToHtml = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== "en" || metadata.original_id) {
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
}
|
||||
let htmlLink =
|
||||
siteConfig.baseUrl + metadata.permalink.replace("/next/", "/");
|
||||
if (htmlLink.includes("/docs/en/")) {
|
||||
htmlLink = htmlLink.replace("/docs/en/", "/docs/en/VERSION/");
|
||||
siteConfig.baseUrl + metadata.permalink.replace('/next/', '/');
|
||||
if (htmlLink.includes('/docs/en/')) {
|
||||
htmlLink = htmlLink.replace('/docs/en/', '/docs/en/VERSION/');
|
||||
} else {
|
||||
htmlLink = htmlLink.replace("/docs/", "/docs/VERSION/");
|
||||
htmlLink = htmlLink.replace('/docs/', '/docs/VERSION/');
|
||||
}
|
||||
mdToHtml[metadata.source] = htmlLink;
|
||||
});
|
||||
|
||||
const DocsLayout = require("../core/DocsLayout.js");
|
||||
const Redirect = require("../core/Redirect.js");
|
||||
const DocsLayout = require('../core/DocsLayout.js');
|
||||
const Redirect = require('../core/Redirect.js');
|
||||
|
||||
fs.removeSync(join(CWD, "build"));
|
||||
fs.removeSync(join(CWD, 'build'));
|
||||
|
||||
// create html files for all docs by going through all doc ids
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
|
@ -133,16 +133,16 @@ function execute() {
|
|||
// determine what file to use according to its id
|
||||
let file;
|
||||
if (metadata.original_id) {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== "en") {
|
||||
file = join(CWD, "translated_docs", metadata.language, metadata.source);
|
||||
if (ENABLE_TRANSLATION && metadata.language !== 'en') {
|
||||
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
|
||||
} else {
|
||||
file = join(CWD, "versioned_docs", metadata.source);
|
||||
file = join(CWD, 'versioned_docs', metadata.source);
|
||||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = join(CWD, "..", readMetadata.getDocsPath(), metadata.source);
|
||||
if (metadata.language === 'en') {
|
||||
file = join(CWD, '..', readMetadata.getDocsPath(), metadata.source);
|
||||
} else {
|
||||
file = join(CWD, "translated_docs", metadata.language, metadata.source);
|
||||
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ function execute() {
|
|||
return;
|
||||
}
|
||||
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"))
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'))
|
||||
.rawContent;
|
||||
|
||||
const language = metadata.language;
|
||||
|
@ -163,36 +163,36 @@ function execute() {
|
|||
let latestVersion;
|
||||
if (ENABLE_VERSIONING) {
|
||||
latestVersion = JSON.parse(
|
||||
fs.readFileSync(join(CWD, "versions.json"), "utf8")
|
||||
fs.readFileSync(join(CWD, 'versions.json'), 'utf8')
|
||||
)[0];
|
||||
}
|
||||
|
||||
// replace any links to markdown files to their website html links
|
||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||
let link = mdToHtml[key];
|
||||
link = link.replace("/en/", "/" + language + "/");
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace(
|
||||
"/VERSION/",
|
||||
'/VERSION/',
|
||||
metadata.version && metadata.version !== latestVersion
|
||||
? "/" + metadata.version + "/"
|
||||
: "/"
|
||||
? '/' + metadata.version + '/'
|
||||
: '/'
|
||||
);
|
||||
// replace relative links without "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
// replace relative links with "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(\\./" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(\\./' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
});
|
||||
|
||||
// replace any relative links to static assets to absolute links
|
||||
rawContent = rawContent.replace(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "docs/assets/"
|
||||
'](' + siteConfig.baseUrl + 'docs/assets/'
|
||||
);
|
||||
|
||||
const docComp = (
|
||||
|
@ -206,7 +206,7 @@ function execute() {
|
|||
writeFileAndCreateFolder(targetFile, str);
|
||||
|
||||
// generate english page redirects when languages are enabled
|
||||
if (ENABLE_TRANSLATION && metadata.permalink.indexOf("docs/en") !== -1) {
|
||||
if (ENABLE_TRANSLATION && metadata.permalink.indexOf('docs/en') !== -1) {
|
||||
const redirectComp = (
|
||||
<Redirect
|
||||
metadata={metadata}
|
||||
|
@ -220,47 +220,47 @@ function execute() {
|
|||
// create a redirects page for doc files
|
||||
const redirectFile = join(
|
||||
buildDir,
|
||||
metadata.permalink.replace("docs/en", "docs")
|
||||
metadata.permalink.replace('docs/en', 'docs')
|
||||
);
|
||||
writeFileAndCreateFolder(redirectFile, redirectStr);
|
||||
}
|
||||
});
|
||||
|
||||
// copy docs assets if they exist
|
||||
if (fs.existsSync(join(CWD, "..", readMetadata.getDocsPath(), "assets"))) {
|
||||
if (fs.existsSync(join(CWD, '..', readMetadata.getDocsPath(), 'assets'))) {
|
||||
fs.copySync(
|
||||
join(CWD, readMetadata.getDocsPath(), "assets"),
|
||||
join(buildDir, "docs", "assets")
|
||||
join(CWD, readMetadata.getDocsPath(), 'assets'),
|
||||
join(buildDir, 'docs', 'assets')
|
||||
);
|
||||
}
|
||||
|
||||
// create html files for all blog posts (each article)
|
||||
if (fs.existsSync(join(__dirname, "..", "core", "MetadataBlog.js"))) {
|
||||
fs.removeSync(join(__dirname, "..", "core", "MetadataBlog.js"));
|
||||
if (fs.existsSync(join(__dirname, '..', 'core', 'MetadataBlog.js'))) {
|
||||
fs.removeSync(join(__dirname, '..', 'core', 'MetadataBlog.js'));
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
||||
const MetadataBlog = require('../core/MetadataBlog.js');
|
||||
const BlogPostLayout = require('../core/BlogPostLayout.js');
|
||||
|
||||
let files = glob.sync(join(CWD, "blog", "**", "*.*"));
|
||||
let files = glob.sync(join(CWD, 'blog', '**', '*.*'));
|
||||
files
|
||||
.sort()
|
||||
.reverse()
|
||||
.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== ".md" && extension !== ".markdown") {
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
|
||||
// convert filename to use slashes
|
||||
const filePath = path
|
||||
.basename(file)
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace(/\.md$/, ".html");
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace(/\.md$/, '.html');
|
||||
const result = readMetadata.extractMetadata(
|
||||
fs.readFileSync(file, { encoding: "utf8" })
|
||||
fs.readFileSync(file, {encoding: 'utf8'})
|
||||
);
|
||||
const rawContent = result.rawContent;
|
||||
const metadata = Object.assign(
|
||||
|
@ -269,26 +269,25 @@ function execute() {
|
|||
);
|
||||
metadata.id = metadata.title;
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const blogPostComp = (
|
||||
<BlogPostLayout
|
||||
metadata={metadata}
|
||||
language={language}
|
||||
config={siteConfig}
|
||||
>
|
||||
config={siteConfig}>
|
||||
{rawContent}
|
||||
</BlogPostLayout>
|
||||
);
|
||||
const str = renderToStaticMarkup(blogPostComp);
|
||||
|
||||
let targetFile = join(buildDir, "blog", filePath);
|
||||
let targetFile = join(buildDir, 'blog', filePath);
|
||||
writeFileAndCreateFolder(targetFile, str);
|
||||
});
|
||||
// create html files for all blog pages (collections of article previews)
|
||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||
const BlogPageLayout = require('../core/BlogPageLayout.js');
|
||||
const perPage = 10;
|
||||
for (let page = 0; page < Math.ceil(MetadataBlog.length / perPage); page++) {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const metadata = {page: page, perPage: perPage};
|
||||
const blogPageComp = (
|
||||
<BlogPageLayout
|
||||
|
@ -301,44 +300,44 @@ function execute() {
|
|||
|
||||
let targetFile = join(
|
||||
buildDir,
|
||||
"blog",
|
||||
page > 0 ? "page" + (page + 1) : "",
|
||||
"index.html"
|
||||
'blog',
|
||||
page > 0 ? 'page' + (page + 1) : '',
|
||||
'index.html'
|
||||
);
|
||||
writeFileAndCreateFolder(targetFile, str);
|
||||
}
|
||||
// create rss files for all blog pages, if there are any blog files
|
||||
if (MetadataBlog.length > 0) {
|
||||
let targetFile = join(buildDir, "blog", "feed.xml");
|
||||
let targetFile = join(buildDir, 'blog', 'feed.xml');
|
||||
writeFileAndCreateFolder(targetFile, feed());
|
||||
targetFile = join(buildDir, "blog", "atom.xml");
|
||||
writeFileAndCreateFolder(targetFile, feed("atom"));
|
||||
targetFile = join(buildDir, 'blog', 'atom.xml');
|
||||
writeFileAndCreateFolder(targetFile, feed('atom'));
|
||||
}
|
||||
|
||||
// create sitemap
|
||||
if (MetadataBlog.length > 0 && Object.keys(Metadata).length > 0) {
|
||||
let targetFile = join(buildDir, "sitemap.xml");
|
||||
let targetFile = join(buildDir, 'sitemap.xml');
|
||||
sitemap(xml => {
|
||||
writeFileAndCreateFolder(targetFile, xml);
|
||||
});
|
||||
}
|
||||
|
||||
// copy blog assets if they exist
|
||||
if (fs.existsSync(join(CWD, "blog", "assets"))) {
|
||||
fs.copySync(join(CWD, "blog", "assets"), join(buildDir, "blog", "assets"));
|
||||
if (fs.existsSync(join(CWD, 'blog', 'assets'))) {
|
||||
fs.copySync(join(CWD, 'blog', 'assets'), join(buildDir, 'blog', 'assets'));
|
||||
}
|
||||
|
||||
// copy all static files from docusaurus
|
||||
files = glob.sync(join(__dirname, "..", "static", "**"));
|
||||
files = glob.sync(join(__dirname, '..', 'static', '**'));
|
||||
files.forEach(file => {
|
||||
let targetFile = join(
|
||||
buildDir,
|
||||
// TODO: use x-platform path functions
|
||||
file.split("/static/")[1] || ""
|
||||
file.split('/static/')[1] || ''
|
||||
);
|
||||
// parse css files to replace colors according to siteConfig
|
||||
if (file.match(/\.css$/)) {
|
||||
let cssContent = fs.readFileSync(file, "utf8");
|
||||
let cssContent = fs.readFileSync(file, 'utf8');
|
||||
|
||||
if (
|
||||
!siteConfig.colors ||
|
||||
|
@ -347,80 +346,80 @@ function execute() {
|
|||
) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Missing color configuration."
|
||||
'Missing color configuration.'
|
||||
)} Make sure siteConfig.colors includes primaryColor and secondaryColor fields.`
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.writeFileSync(targetFile, cssContent);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// copy all static files from user
|
||||
files = glob.sync(join(CWD, "static", "**"));
|
||||
files = glob.sync(join(CWD, 'static', '**'));
|
||||
files.forEach(file => {
|
||||
// parse css files to replace colors according to siteConfig
|
||||
if (file.match(/\.css$/) && !isSeparateCss(file)) {
|
||||
const mainCss = join(buildDir, "css", "main.css");
|
||||
let cssContent = fs.readFileSync(file, "utf8");
|
||||
cssContent = fs.readFileSync(mainCss, "utf8") + "\n" + cssContent;
|
||||
const mainCss = join(buildDir, 'css', 'main.css');
|
||||
let cssContent = fs.readFileSync(file, 'utf8');
|
||||
cssContent = fs.readFileSync(mainCss, 'utf8') + '\n' + cssContent;
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
fs.writeFileSync(mainCss, cssContent);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
let parts = file.split("/static/");
|
||||
let parts = file.split('/static/');
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// compile/copy pages from user
|
||||
let pagesArr = [];
|
||||
files = glob.sync(join(CWD, "pages", "**"));
|
||||
files = glob.sync(join(CWD, 'pages', '**'));
|
||||
files.forEach(file => {
|
||||
// render .js files to strings
|
||||
if (file.match(/\.js$/)) {
|
||||
// make temp file for sake of require paths
|
||||
const parts = file.split("pages");
|
||||
let tempFile = join(__dirname, "..", "pages", parts[1]);
|
||||
const parts = file.split('pages');
|
||||
let tempFile = join(__dirname, '..', 'pages', parts[1]);
|
||||
tempFile = tempFile.replace(
|
||||
path.basename(file),
|
||||
"temp" + path.basename(file)
|
||||
'temp' + path.basename(file)
|
||||
);
|
||||
mkdirp.sync(tempFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(tempFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, tempFile);
|
||||
|
||||
const ReactComp = require(tempFile);
|
||||
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
targetFile = targetFile.replace(/\.js$/, ".html");
|
||||
targetFile = targetFile.replace(/\.js$/, '.html');
|
||||
|
||||
const regexLang = /\/pages\/(.*)\//;
|
||||
const match = regexLang.exec(file);
|
||||
const langParts = match[1].split("/");
|
||||
if (langParts.indexOf("en") !== -1) {
|
||||
const langParts = match[1].split('/');
|
||||
if (langParts.indexOf('en') !== -1) {
|
||||
// copy and compile a page for each enabled language from the English file
|
||||
for (let i = 0; i < enabledLanguages.length; i++) {
|
||||
let language = enabledLanguages[i];
|
||||
// skip conversion from english file if a file exists for this language
|
||||
if (
|
||||
language !== "en" &&
|
||||
language !== 'en' &&
|
||||
// TODO: use path functions
|
||||
fs.existsSync(file.replace("/en/", "/" + language + "/"))
|
||||
fs.existsSync(file.replace('/en/', '/' + language + '/'))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
@ -432,13 +431,13 @@ function execute() {
|
|||
);
|
||||
writeFileAndCreateFolder(
|
||||
// TODO: use path functions
|
||||
targetFile.replace("/en/", "/" + language + "/"),
|
||||
targetFile.replace('/en/', '/' + language + '/'),
|
||||
str
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// allow for rendering of other files not in pages/en folder
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
for (let i = 0; i < langParts.length; i++) {
|
||||
if (enabledLanguages.indexOf(langParts[i]) !== -1) {
|
||||
language = langParts[i];
|
||||
|
@ -455,17 +454,17 @@ function execute() {
|
|||
fs.removeSync(tempFile);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
// copy other non .js files
|
||||
let parts = file.split("pages");
|
||||
let parts = file.split('pages');
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// copy html files in 'en' to base level as well
|
||||
files = glob.sync(join(buildDir, "en", "**"));
|
||||
files = glob.sync(join(buildDir, 'en', '**'));
|
||||
files.forEach(file => {
|
||||
let targetFile = file.replace(join(buildDir, "en"), join(buildDir));
|
||||
let targetFile = file.replace(join(buildDir, 'en'), join(buildDir));
|
||||
if (file.match(/\.html$/)) {
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
|
@ -473,7 +472,7 @@ function execute() {
|
|||
|
||||
// Generate CNAME file if a custom domain is specified in siteConfig
|
||||
if (siteConfig.cname) {
|
||||
let targetFile = join(buildDir, "CNAME");
|
||||
let targetFile = join(buildDir, 'CNAME');
|
||||
fs.writeFileSync(targetFile, siteConfig.cname);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const Metadata = require("../core/metadata.js");
|
||||
const fs = require("fs");
|
||||
const Metadata = require('../core/metadata.js');
|
||||
const fs = require('fs');
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,14 @@ function readCategories(sidebar) {
|
|||
if (!articles[metadata.next]) {
|
||||
throw new Error(
|
||||
metadata.version
|
||||
? `Improper sidebars file for version ${metadata.version}, document with id '${metadata.next}' not found. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
|
||||
: `Improper sidebars.json file, document with id '${metadata.next}' not found. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
|
||||
? `Improper sidebars file for version ${
|
||||
metadata.version
|
||||
}, document with id '${
|
||||
metadata.next
|
||||
}' not found. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
|
||||
: `Improper sidebars.json file, document with id '${
|
||||
metadata.next
|
||||
}' not found. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
|
||||
);
|
||||
}
|
||||
previous[articles[metadata.next].id] = metadata.id;
|
||||
|
@ -85,7 +91,7 @@ function readCategories(sidebar) {
|
|||
currentCategory && categories.push(currentCategory);
|
||||
currentCategory = {
|
||||
name: metadata.category,
|
||||
links: []
|
||||
links: [],
|
||||
};
|
||||
}
|
||||
currentCategory.links.push(metadata);
|
||||
|
|
|
@ -7,28 +7,26 @@
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const versionFallback = require("./versionFallback.js");
|
||||
const escapeStringRegexp = require("escape-string-regexp");
|
||||
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const versionFallback = require('./versionFallback.js');
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + '/versions.json');
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -39,15 +37,13 @@ if (fs.existsSync(CWD + "/languages.js")) {
|
|||
// All .md docs still (currently) must be in one flat directory hierarchy.
|
||||
// e.g., docs/whereDocsReallyExist/*.md (all .md files in this dir)
|
||||
function getDocsPath() {
|
||||
return siteConfig.customDocsPath
|
||||
? siteConfig.customDocsPath
|
||||
: "docs";
|
||||
return siteConfig.customDocsPath ? siteConfig.customDocsPath : 'docs';
|
||||
}
|
||||
// returns map from id to object containing sidebar ordering info
|
||||
function readSidebar() {
|
||||
let allSidebars;
|
||||
if (fs.existsSync(CWD + "/sidebars.json")) {
|
||||
allSidebars = require(CWD + "/sidebars.json");
|
||||
if (fs.existsSync(CWD + '/sidebars.json')) {
|
||||
allSidebars = require(CWD + '/sidebars.json');
|
||||
} else {
|
||||
allSidebars = {};
|
||||
}
|
||||
|
@ -76,7 +72,7 @@ function readSidebar() {
|
|||
previous: previous,
|
||||
next: next,
|
||||
sidebar: sidebar,
|
||||
category: categoryOrder[i]
|
||||
category: categoryOrder[i],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
@ -85,19 +81,19 @@ function readSidebar() {
|
|||
|
||||
// split markdown header
|
||||
function splitHeader(content) {
|
||||
const lines = content.split("\n");
|
||||
if (lines[0] !== "---") {
|
||||
const lines = content.split('\n');
|
||||
if (lines[0] !== '---') {
|
||||
return {};
|
||||
}
|
||||
let i = 1;
|
||||
for (; i < lines.length - 1; ++i) {
|
||||
if (lines[i] === "---") {
|
||||
if (lines[i] === '---') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
header: lines.slice(1, i + 1).join("\n"),
|
||||
content: lines.slice(i + 1).join("\n")
|
||||
header: lines.slice(1, i + 1).join('\n'),
|
||||
content: lines.slice(i + 1).join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -108,13 +104,13 @@ function extractMetadata(content) {
|
|||
if (Object.keys(both).length === 0) {
|
||||
return {metadata, rawContent: content};
|
||||
}
|
||||
const lines = both.header.split("\n");
|
||||
const lines = both.header.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(":");
|
||||
const keyvalue = lines[i].split(':');
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(":")
|
||||
.join(':')
|
||||
.trim();
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
|
@ -126,11 +122,13 @@ function extractMetadata(content) {
|
|||
|
||||
// process the metadata for a document found in the docs folder
|
||||
function processMetadata(file) {
|
||||
const result = extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const result = extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
|
||||
let regexSubFolder = new RegExp("/" + escapeStringRegexp(getDocsPath()) + "\/(.*)\/.*/");
|
||||
let regexSubFolder = new RegExp(
|
||||
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
|
||||
);
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const match = regexSubFolder.exec(file);
|
||||
if (match) {
|
||||
language = match[1];
|
||||
|
@ -143,7 +141,7 @@ function processMetadata(file) {
|
|||
if (!metadata.id) {
|
||||
metadata.id = path.basename(file, path.extname(file));
|
||||
}
|
||||
if (metadata.id.includes("/")) {
|
||||
if (metadata.id.includes('/')) {
|
||||
throw new Error('Document id cannot include "/".');
|
||||
}
|
||||
if (!metadata.title) {
|
||||
|
@ -151,26 +149,26 @@ function processMetadata(file) {
|
|||
}
|
||||
|
||||
if (languages.length === 1 && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink = "docs/" + metadata.id + ".html";
|
||||
metadata.permalink = 'docs/' + metadata.id + '.html';
|
||||
} else {
|
||||
metadata.permalink = "docs/" + language + "/" + metadata.id + ".html";
|
||||
metadata.permalink = 'docs/' + language + '/' + metadata.id + '.html';
|
||||
}
|
||||
|
||||
if (ENABLE_VERSIONING) {
|
||||
metadata.version = "next";
|
||||
metadata.version = 'next';
|
||||
if (languages.length === 1 && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink = metadata.permalink.replace("docs/", "docs/next/");
|
||||
metadata.permalink = metadata.permalink.replace('docs/', 'docs/next/');
|
||||
} else {
|
||||
metadata.permalink = metadata.permalink.replace(
|
||||
"docs/" + language + "/",
|
||||
"docs/" + language + "/next/"
|
||||
'docs/' + language + '/',
|
||||
'docs/' + language + '/next/'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// change ids previous, next
|
||||
metadata.localized_id = metadata.id;
|
||||
metadata.id = language + "-" + metadata.id;
|
||||
metadata.id = language + '-' + metadata.id;
|
||||
metadata.language = language;
|
||||
|
||||
const order = readSidebar();
|
||||
|
@ -182,11 +180,11 @@ function processMetadata(file) {
|
|||
|
||||
if (order[id].next) {
|
||||
metadata.next_id = order[id].next;
|
||||
metadata.next = language + "-" + order[id].next;
|
||||
metadata.next = language + '-' + order[id].next;
|
||||
}
|
||||
if (order[id].previous) {
|
||||
metadata.previous_id = order[id].previous;
|
||||
metadata.previous = language + "-" + order[id].previous;
|
||||
metadata.previous = language + '-' + order[id].previous;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +193,7 @@ function processMetadata(file) {
|
|||
|
||||
// process metadata for all docs and save into core/metadata.js
|
||||
function generateMetadataDocs() {
|
||||
console.log("Generating Metadata for Docs....");
|
||||
console.log('Generating Metadata for Docs....');
|
||||
|
||||
let order;
|
||||
try {
|
||||
|
@ -216,13 +214,13 @@ function generateMetadataDocs() {
|
|||
const defaultMetadatas = {};
|
||||
|
||||
// metadata for english files
|
||||
let files = glob.sync(CWD + "/../" + getDocsPath() + "/**");
|
||||
let files = glob.sync(CWD + '/../' + getDocsPath() + '/**');
|
||||
files.forEach(file => {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
|
||||
const extension = path.extname(file);
|
||||
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
const res = processMetadata(file);
|
||||
|
||||
if (!res) {
|
||||
|
@ -235,36 +233,36 @@ function generateMetadataDocs() {
|
|||
// these will get replaced if/when the localized file is downloaded from crowdin
|
||||
enabledLanguages
|
||||
.filter(currentLanguage => {
|
||||
return currentLanguage != "en";
|
||||
return currentLanguage != 'en';
|
||||
})
|
||||
.map(currentLanguage => {
|
||||
let baseMetadata = Object.assign({}, metadata);
|
||||
baseMetadata["id"] = baseMetadata["id"]
|
||||
baseMetadata['id'] = baseMetadata['id']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
if (baseMetadata["permalink"])
|
||||
baseMetadata["permalink"] = baseMetadata["permalink"]
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
if (baseMetadata['permalink'])
|
||||
baseMetadata['permalink'] = baseMetadata['permalink']
|
||||
.toString()
|
||||
.replace(/^docs\/en\//, "docs/" + currentLanguage + "/");
|
||||
if (baseMetadata["next"])
|
||||
baseMetadata["next"] = baseMetadata["next"]
|
||||
.replace(/^docs\/en\//, 'docs/' + currentLanguage + '/');
|
||||
if (baseMetadata['next'])
|
||||
baseMetadata['next'] = baseMetadata['next']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
if (baseMetadata["previous"])
|
||||
baseMetadata["previous"] = baseMetadata["previous"]
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
if (baseMetadata['previous'])
|
||||
baseMetadata['previous'] = baseMetadata['previous']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
baseMetadata["language"] = currentLanguage;
|
||||
defaultMetadatas[baseMetadata["id"]] = baseMetadata;
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
baseMetadata['language'] = currentLanguage;
|
||||
defaultMetadatas[baseMetadata['id']] = baseMetadata;
|
||||
});
|
||||
Object.assign(metadatas, defaultMetadatas);
|
||||
}
|
||||
});
|
||||
|
||||
// metadata for non-english docs
|
||||
files = glob.sync(CWD + "/translated_docs/**");
|
||||
files = glob.sync(CWD + '/translated_docs/**');
|
||||
files.forEach(file => {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const match = regexSubFolder.exec(file);
|
||||
if (match) {
|
||||
language = match[1];
|
||||
|
@ -276,7 +274,7 @@ function generateMetadataDocs() {
|
|||
|
||||
const extension = path.extname(file);
|
||||
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
const res = processMetadata(file);
|
||||
if (!res) {
|
||||
return;
|
||||
|
@ -295,17 +293,17 @@ function generateMetadataDocs() {
|
|||
metadata.category = order[id].category;
|
||||
if (order[id].next) {
|
||||
metadata.next_id = order[id].next.replace(
|
||||
"version-" + metadata.version + "-",
|
||||
""
|
||||
'version-' + metadata.version + '-',
|
||||
''
|
||||
);
|
||||
metadata.next = metadata.language + "-" + order[id].next;
|
||||
metadata.next = metadata.language + '-' + order[id].next;
|
||||
}
|
||||
if (order[id].previous) {
|
||||
metadata.previous_id = order[id].previous.replace(
|
||||
"version-" + metadata.version + "-",
|
||||
""
|
||||
'version-' + metadata.version + '-',
|
||||
''
|
||||
);
|
||||
metadata.previous = metadata.language + "-" + order[id].previous;
|
||||
metadata.previous = metadata.language + '-' + order[id].previous;
|
||||
}
|
||||
}
|
||||
metadatas[metadata.id] = metadata;
|
||||
|
@ -319,7 +317,7 @@ function generateMetadataDocs() {
|
|||
metadatas[metadata].previous_title =
|
||||
metadatas[metadatas[metadata].previous].title;
|
||||
} else {
|
||||
metadatas[metadata].previous_title = "Previous";
|
||||
metadatas[metadata].previous_title = 'Previous';
|
||||
}
|
||||
}
|
||||
if (metadatas[metadata].next) {
|
||||
|
@ -327,19 +325,19 @@ function generateMetadataDocs() {
|
|||
metadatas[metadata].next_title =
|
||||
metadatas[metadatas[metadata].next].title;
|
||||
} else {
|
||||
metadatas[metadata].next_title = "Next";
|
||||
metadatas[metadata].next_title = 'Next';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
__dirname + "/../core/metadata.js",
|
||||
"/**\n" +
|
||||
" * @generated\n" +
|
||||
" */\n" +
|
||||
"module.exports = " +
|
||||
__dirname + '/../core/metadata.js',
|
||||
'/**\n' +
|
||||
' * @generated\n' +
|
||||
' */\n' +
|
||||
'module.exports = ' +
|
||||
JSON.stringify(metadatas, null, 2) +
|
||||
";"
|
||||
';'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -347,11 +345,11 @@ function generateMetadataDocs() {
|
|||
function generateMetadataBlog() {
|
||||
const metadatas = [];
|
||||
|
||||
let files = glob.sync(CWD + "/blog/**/*.*");
|
||||
let files = glob.sync(CWD + '/blog/**/*.*');
|
||||
if (!files || files.length == 0) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
CWD + "/blog/ appears to be empty"
|
||||
CWD + '/blog/ appears to be empty'
|
||||
)} Make sure you've put your blog files in your Docusaurus 'website' folder.`
|
||||
);
|
||||
}
|
||||
|
@ -360,7 +358,7 @@ function generateMetadataBlog() {
|
|||
.reverse()
|
||||
.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== ".md" && extension !== ".markdown") {
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
// Transform
|
||||
|
@ -369,13 +367,11 @@ function generateMetadataBlog() {
|
|||
// 2015/08/13/blog-post-name-0-5.html
|
||||
const filePath = path
|
||||
.basename(file)
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace(/\.md$/, ".html");
|
||||
const result = extractMetadata(
|
||||
fs.readFileSync(file, { encoding: "utf8" })
|
||||
);
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace(/\.md$/, '.html');
|
||||
const result = extractMetadata(fs.readFileSync(file, {encoding: 'utf8'}));
|
||||
const rawContent = result.rawContent;
|
||||
const metadata = Object.assign(
|
||||
{path: filePath, content: rawContent},
|
||||
|
@ -388,27 +384,27 @@ function generateMetadataBlog() {
|
|||
let filePathDateArr = path
|
||||
.basename(file)
|
||||
.toString()
|
||||
.split("-");
|
||||
.split('-');
|
||||
metadata.date = new Date(
|
||||
filePathDateArr[0] +
|
||||
"-" +
|
||||
'-' +
|
||||
filePathDateArr[1] +
|
||||
"-" +
|
||||
'-' +
|
||||
filePathDateArr[2] +
|
||||
"T06:00:00.000Z"
|
||||
'T06:00:00.000Z'
|
||||
);
|
||||
|
||||
metadatas.push(metadata);
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
__dirname + "/../core/MetadataBlog.js",
|
||||
"/**\n" +
|
||||
" * @generated\n" +
|
||||
" */\n" +
|
||||
"module.exports = " +
|
||||
__dirname + '/../core/MetadataBlog.js',
|
||||
'/**\n' +
|
||||
' * @generated\n' +
|
||||
' */\n' +
|
||||
'module.exports = ' +
|
||||
JSON.stringify(metadatas, null, 2) +
|
||||
";"
|
||||
';'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -418,5 +414,5 @@ module.exports = {
|
|||
extractMetadata,
|
||||
processMetadata,
|
||||
generateMetadataDocs,
|
||||
generateMetadataBlog
|
||||
generateMetadataBlog,
|
||||
};
|
||||
|
|
|
@ -7,30 +7,30 @@
|
|||
*/
|
||||
|
||||
function execute(port) {
|
||||
const extractTranslations = require("../write-translations.js");
|
||||
const extractTranslations = require('../write-translations.js');
|
||||
|
||||
const translation = require("./translation.js");
|
||||
const express = require("express");
|
||||
const React = require("react");
|
||||
const request = require("request");
|
||||
const renderToStaticMarkup = require("react-dom/server").renderToStaticMarkup;
|
||||
const fs = require("fs-extra");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const toSlug = require("../core/toSlug.js");
|
||||
const mkdirp = require("mkdirp");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const translate = require("./translate.js");
|
||||
const versionFallback = require("./versionFallback");
|
||||
const translation = require('./translation.js');
|
||||
const express = require('express');
|
||||
const React = require('react');
|
||||
const request = require('request');
|
||||
const renderToStaticMarkup = require('react-dom/server').renderToStaticMarkup;
|
||||
const fs = require('fs-extra');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const toSlug = require('../core/toSlug.js');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const translate = require('./translate.js');
|
||||
const versionFallback = require('./versionFallback');
|
||||
|
||||
const feed = require("./feed.js");
|
||||
const sitemap = require("./sitemap.js");
|
||||
const feed = require('./feed.js');
|
||||
const sitemap = require('./sitemap.js');
|
||||
// const sitemap = require("sitemap");
|
||||
|
||||
const CWD = process.cwd();
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js');
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + '/versions.json');
|
||||
|
||||
// remove a module and child modules from require cache, so server does not have
|
||||
// to be restarted
|
||||
|
@ -56,39 +56,39 @@ function execute(port) {
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
let readMetadata = require("./readMetadata.js");
|
||||
let readMetadata = require('./readMetadata.js');
|
||||
let Metadata;
|
||||
let MetadataBlog;
|
||||
let siteConfig;
|
||||
|
||||
function reloadMetadata() {
|
||||
removeModuleAndChildrenFromCache("./readMetadata.js");
|
||||
removeModuleAndChildrenFromCache('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
removeModuleAndChildrenFromCache("../core/metadata.js");
|
||||
Metadata = require("../core/metadata.js");
|
||||
removeModuleAndChildrenFromCache('../core/metadata.js');
|
||||
Metadata = require('../core/metadata.js');
|
||||
}
|
||||
|
||||
function reloadMetadataBlog() {
|
||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
||||
removeModuleAndChildrenFromCache("../core/MetadataBlog.js");
|
||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
||||
if (fs.existsSync(__dirname + '/../core/MetadataBlog.js')) {
|
||||
removeModuleAndChildrenFromCache('../core/MetadataBlog.js');
|
||||
fs.removeSync(__dirname + '/../core/MetadataBlog.js');
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
MetadataBlog = require("../core/MetadataBlog.js");
|
||||
MetadataBlog = require('../core/MetadataBlog.js');
|
||||
}
|
||||
|
||||
function reloadSiteConfig() {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
removeModuleAndChildrenFromCache(CWD + '/siteConfig.js');
|
||||
siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
if (siteConfig.highlight && siteConfig.highlight.hljs) {
|
||||
siteConfig.highlight.hljs(require("highlight.js"));
|
||||
siteConfig.highlight.hljs(require('highlight.js'));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = "<AUTOGENERATED_TABLE_OF_CONTENTS>";
|
||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
||||
|
||||
const insertTableOfContents = rawContent => {
|
||||
const regexp = /\n###\s+(`.*`.*)\n/g;
|
||||
|
@ -100,7 +100,7 @@ function execute(port) {
|
|||
|
||||
const tableOfContents = headers
|
||||
.map(header => ` - [${header}](#${toSlug(header)})`)
|
||||
.join("\n");
|
||||
.join('\n');
|
||||
|
||||
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
|
||||
};
|
||||
|
@ -121,7 +121,7 @@ function execute(port) {
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
console.log("server.js triggered...");
|
||||
console.log('server.js triggered...');
|
||||
|
||||
reloadMetadata();
|
||||
reloadMetadataBlog();
|
||||
|
@ -132,7 +132,7 @@ function execute(port) {
|
|||
const app = express();
|
||||
|
||||
app.get(/docs\/.*html$/, (req, res, next) => {
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, '');
|
||||
|
||||
// links is a map from a permalink to an id for each document
|
||||
let links = {};
|
||||
|
@ -146,15 +146,15 @@ function execute(port) {
|
|||
const mdToHtml = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== "en" || metadata.original_id) {
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
}
|
||||
let htmlLink =
|
||||
siteConfig.baseUrl + metadata.permalink.replace("/next/", "/");
|
||||
if (htmlLink.includes("/docs/en/")) {
|
||||
htmlLink = htmlLink.replace("/docs/en/", "/docs/en/VERSION/");
|
||||
siteConfig.baseUrl + metadata.permalink.replace('/next/', '/');
|
||||
if (htmlLink.includes('/docs/en/')) {
|
||||
htmlLink = htmlLink.replace('/docs/en/', '/docs/en/VERSION/');
|
||||
} else {
|
||||
htmlLink = htmlLink.replace("/docs/", "/docs/VERSION/");
|
||||
htmlLink = htmlLink.replace('/docs/', '/docs/VERSION/');
|
||||
}
|
||||
mdToHtml[metadata.source] = htmlLink;
|
||||
});
|
||||
|
@ -169,18 +169,19 @@ function execute(port) {
|
|||
// determine what file to use according to its id
|
||||
let file;
|
||||
if (metadata.original_id) {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== "en") {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== 'en') {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
CWD + '/translated_docs/' + metadata.language + '/' + metadata.source;
|
||||
} else {
|
||||
file = CWD + "/versioned_docs/" + metadata.source;
|
||||
file = CWD + '/versioned_docs/' + metadata.source;
|
||||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
|
||||
if (metadata.language === 'en') {
|
||||
file =
|
||||
CWD + '/../' + readMetadata.getDocsPath() + '/' + metadata.source;
|
||||
} else {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
CWD + '/translated_docs/' + metadata.language + '/' + metadata.source;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +190,7 @@ function execute(port) {
|
|||
return;
|
||||
}
|
||||
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"))
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'))
|
||||
.rawContent;
|
||||
|
||||
// generate table of contents if appropriate
|
||||
|
@ -200,46 +201,46 @@ function execute(port) {
|
|||
let latestVersion;
|
||||
if (ENABLE_VERSIONING) {
|
||||
latestVersion = JSON.parse(
|
||||
fs.readFileSync(CWD + "/versions.json", "utf8")
|
||||
fs.readFileSync(CWD + '/versions.json', 'utf8')
|
||||
)[0];
|
||||
}
|
||||
|
||||
// replace any links to markdown files to their website html links
|
||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||
let link = mdToHtml[key];
|
||||
link = link.replace("/en/", "/" + language + "/");
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace(
|
||||
"/VERSION/",
|
||||
'/VERSION/',
|
||||
metadata.version && metadata.version !== latestVersion
|
||||
? "/" + metadata.version + "/"
|
||||
: "/"
|
||||
? '/' + metadata.version + '/'
|
||||
: '/'
|
||||
);
|
||||
// replace relative links without "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
// replace relative links with "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(\\./" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(\\./' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
});
|
||||
|
||||
// replace any relative links to static assets to absolute links
|
||||
rawContent = rawContent.replace(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "docs/assets/"
|
||||
'](' + siteConfig.baseUrl + 'docs/assets/'
|
||||
);
|
||||
|
||||
removeModuleAndChildrenFromCache("../core/DocsLayout.js");
|
||||
const DocsLayout = require("../core/DocsLayout.js");
|
||||
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
||||
const DocsLayout = require('../core/DocsLayout.js');
|
||||
|
||||
let Doc;
|
||||
if (metadata.layout && siteConfig.layouts[metadata.layout]) {
|
||||
Doc = siteConfig.layouts[metadata.layout]({
|
||||
React,
|
||||
MarkdownBlock: require("../core/MarkdownBlock.js")
|
||||
MarkdownBlock: require('../core/MarkdownBlock.js'),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -256,38 +257,38 @@ function execute(port) {
|
|||
res.send(renderToStaticMarkup(docComp));
|
||||
});
|
||||
|
||||
app.get("/sitemap.xml", function(req, res) {
|
||||
res.set("Content-Type", "application/xml");
|
||||
app.get('/sitemap.xml', function(req, res) {
|
||||
res.set('Content-Type', 'application/xml');
|
||||
|
||||
sitemap(xml => {
|
||||
res.send(xml);
|
||||
});
|
||||
});
|
||||
app.get(/blog\/.*xml$/, (req, res) => {
|
||||
res.set("Content-Type", "application/rss+xml");
|
||||
let parts = req.path.toString().split("blog/");
|
||||
if (parts[1].toLowerCase() == "atom.xml") {
|
||||
res.send(feed("atom"));
|
||||
res.set('Content-Type', 'application/rss+xml');
|
||||
let parts = req.path.toString().split('blog/');
|
||||
if (parts[1].toLowerCase() == 'atom.xml') {
|
||||
res.send(feed('atom'));
|
||||
return;
|
||||
}
|
||||
res.send(feed("rss"));
|
||||
res.send(feed('rss'));
|
||||
});
|
||||
|
||||
app.get(/blog\/.*xml$/, (req, res) => {
|
||||
res.set("Content-Type", "application/rss+xml");
|
||||
let parts = req.path.toString().split("blog/");
|
||||
if (parts[1].toLowerCase() == "atom.xml") {
|
||||
res.send(feed("atom"));
|
||||
res.set('Content-Type', 'application/rss+xml');
|
||||
let parts = req.path.toString().split('blog/');
|
||||
if (parts[1].toLowerCase() == 'atom.xml') {
|
||||
res.send(feed('atom'));
|
||||
return;
|
||||
}
|
||||
res.send(feed("rss"));
|
||||
res.send(feed('rss'));
|
||||
});
|
||||
|
||||
// handle all requests for blog pages and posts
|
||||
app.get(/blog\/.*html$/, (req, res) => {
|
||||
// generate all of the blog pages
|
||||
removeModuleAndChildrenFromCache("../core/BlogPageLayout.js");
|
||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||
removeModuleAndChildrenFromCache('../core/BlogPageLayout.js');
|
||||
const BlogPageLayout = require('../core/BlogPageLayout.js');
|
||||
const blogPages = {};
|
||||
// make blog pages with 10 posts per page
|
||||
const perPage = 10;
|
||||
|
@ -296,7 +297,7 @@ function execute(port) {
|
|||
page < Math.ceil(MetadataBlog.length / perPage);
|
||||
page++
|
||||
) {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const metadata = {page: page, perPage: perPage};
|
||||
const blogPageComp = (
|
||||
<BlogPageLayout
|
||||
|
@ -307,46 +308,46 @@ function execute(port) {
|
|||
);
|
||||
const str = renderToStaticMarkup(blogPageComp);
|
||||
|
||||
let path = (page > 0 ? "page" + (page + 1) : "") + "/index.html";
|
||||
let path = (page > 0 ? 'page' + (page + 1) : '') + '/index.html';
|
||||
blogPages[path] = str;
|
||||
}
|
||||
|
||||
let parts = req.path.toString().split("blog/");
|
||||
let parts = req.path.toString().split('blog/');
|
||||
// send corresponding blog page if appropriate
|
||||
if (parts[1] === "index.html") {
|
||||
res.send(blogPages["/index.html"]);
|
||||
} else if (parts[1].endsWith("/index.html")) {
|
||||
if (parts[1] === 'index.html') {
|
||||
res.send(blogPages['/index.html']);
|
||||
} else if (parts[1].endsWith('/index.html')) {
|
||||
res.send(blogPages[parts[1]]);
|
||||
} else if (parts[1].match(/page([0-9]+)/)) {
|
||||
if (parts[1].endsWith("/")) {
|
||||
res.send(blogPages[parts[1] + "index.html"]);
|
||||
if (parts[1].endsWith('/')) {
|
||||
res.send(blogPages[parts[1] + 'index.html']);
|
||||
} else {
|
||||
res.send(blogPages[parts[1] + "/index.html"]);
|
||||
res.send(blogPages[parts[1] + '/index.html']);
|
||||
}
|
||||
} else {
|
||||
// else send corresponding blog post
|
||||
let file = parts[1];
|
||||
file = file.replace(/\.html$/, ".md");
|
||||
file = file.replace(new RegExp("/", "g"), "-");
|
||||
file = CWD + "/blog/" + file;
|
||||
file = file.replace(/\.html$/, '.md');
|
||||
file = file.replace(new RegExp('/', 'g'), '-');
|
||||
file = CWD + '/blog/' + file;
|
||||
|
||||
const result = readMetadata.extractMetadata(
|
||||
fs.readFileSync(file, { encoding: "utf8" })
|
||||
fs.readFileSync(file, {encoding: 'utf8'})
|
||||
);
|
||||
let rawContent = result.rawContent;
|
||||
rawContent = rawContent.replace(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "blog/assets/"
|
||||
'](' + siteConfig.baseUrl + 'blog/assets/'
|
||||
);
|
||||
const metadata = Object.assign(
|
||||
{ path: req.path.toString().split("blog/")[1], content: rawContent },
|
||||
{path: req.path.toString().split('blog/')[1], content: rawContent},
|
||||
result.metadata
|
||||
);
|
||||
metadata.id = metadata.title;
|
||||
|
||||
let language = "en";
|
||||
removeModuleAndChildrenFromCache("../core/BlogPostLayout.js");
|
||||
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
||||
let language = 'en';
|
||||
removeModuleAndChildrenFromCache('../core/BlogPostLayout.js');
|
||||
const BlogPostLayout = require('../core/BlogPostLayout.js');
|
||||
|
||||
const blogPostComp = (
|
||||
<BlogPostLayout
|
||||
|
@ -361,44 +362,44 @@ function execute(port) {
|
|||
});
|
||||
|
||||
// handle all other main pages
|
||||
app.get("*.html", (req, res, next) => {
|
||||
app.get('*.html', (req, res, next) => {
|
||||
// look for user provided html file first
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
htmlFile = CWD + "/pages/" + htmlFile;
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, '');
|
||||
htmlFile = CWD + '/pages/' + htmlFile;
|
||||
if (
|
||||
fs.existsSync(htmlFile) ||
|
||||
fs.existsSync(
|
||||
(htmlFile = htmlFile.replace(
|
||||
path.basename(htmlFile),
|
||||
"en/" + path.basename(htmlFile)
|
||||
'en/' + path.basename(htmlFile)
|
||||
))
|
||||
)
|
||||
) {
|
||||
res.send(fs.readFileSync(htmlFile, { encoding: "utf8" }));
|
||||
res.send(fs.readFileSync(htmlFile, {encoding: 'utf8'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// look for user provided react file either in specified path or in path for english files
|
||||
let file = req.path.toString().replace(/\.html$/, ".js");
|
||||
file = file.replace(siteConfig.baseUrl, "");
|
||||
let userFile = CWD + "/pages/" + file;
|
||||
let file = req.path.toString().replace(/\.html$/, '.js');
|
||||
file = file.replace(siteConfig.baseUrl, '');
|
||||
let userFile = CWD + '/pages/' + file;
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const regexLang = /(.*)\/.*\.html$/;
|
||||
const match = regexLang.exec(req.path);
|
||||
const parts = match[1].split("/");
|
||||
const parts = match[1].split('/');
|
||||
const enabledLangTags = [];
|
||||
for (let i = 0; i < translation["languages"].length; i++) {
|
||||
enabledLangTags.push(translation["languages"][i].tag);
|
||||
for (let i = 0; i < translation['languages'].length; i++) {
|
||||
enabledLangTags.push(translation['languages'][i].tag);
|
||||
}
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (enabledLangTags.indexOf(parts[i]) !== -1) {
|
||||
language = parts[i];
|
||||
}
|
||||
}
|
||||
let englishFile = CWD + "/pages/" + file;
|
||||
if (language !== "en") {
|
||||
englishFile = englishFile.replace("/" + language + "/", "/en/");
|
||||
let englishFile = CWD + '/pages/' + file;
|
||||
if (language !== 'en') {
|
||||
englishFile = englishFile.replace('/' + language + '/', '/en/');
|
||||
}
|
||||
|
||||
// check for: a file for the page, an english file for page with unspecified language, or an
|
||||
|
@ -408,26 +409,26 @@ function execute(port) {
|
|||
fs.existsSync(
|
||||
(userFile = userFile.replace(
|
||||
path.basename(userFile),
|
||||
"en/" + path.basename(userFile)
|
||||
'en/' + path.basename(userFile)
|
||||
))
|
||||
) ||
|
||||
fs.existsSync((userFile = englishFile))
|
||||
) {
|
||||
// copy into docusaurus so require paths work
|
||||
let parts = userFile.split("pages/");
|
||||
let tempFile = __dirname + "/../pages/" + parts[1];
|
||||
let parts = userFile.split('pages/');
|
||||
let tempFile = __dirname + '/../pages/' + parts[1];
|
||||
tempFile = tempFile.replace(
|
||||
path.basename(file),
|
||||
"temp" + path.basename(file)
|
||||
'temp' + path.basename(file)
|
||||
);
|
||||
mkdirp.sync(tempFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(tempFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(userFile, tempFile);
|
||||
|
||||
// render into a string
|
||||
removeModuleAndChildrenFromCache(tempFile);
|
||||
const ReactComp = require(tempFile);
|
||||
removeModuleAndChildrenFromCache("../core/Site.js");
|
||||
const Site = require("../core/Site.js");
|
||||
removeModuleAndChildrenFromCache('../core/Site.js');
|
||||
const Site = require('../core/Site.js');
|
||||
translate.setLanguage(language);
|
||||
const str = renderToStaticMarkup(
|
||||
<Site language={language} config={siteConfig}>
|
||||
|
@ -448,18 +449,18 @@ function execute(port) {
|
|||
app.get(/main\.css$/, (req, res) => {
|
||||
const mainCssPath =
|
||||
__dirname +
|
||||
"/../static/" +
|
||||
req.path.toString().replace(siteConfig.baseUrl, "/");
|
||||
let cssContent = fs.readFileSync(mainCssPath, { encoding: "utf8" });
|
||||
'/../static/' +
|
||||
req.path.toString().replace(siteConfig.baseUrl, '/');
|
||||
let cssContent = fs.readFileSync(mainCssPath, {encoding: 'utf8'});
|
||||
|
||||
let files = glob.sync(CWD + "/static/**/*.css");
|
||||
let files = glob.sync(CWD + '/static/**/*.css');
|
||||
|
||||
files.forEach(file => {
|
||||
if (isSeparateCss(file)) {
|
||||
return;
|
||||
}
|
||||
cssContent =
|
||||
cssContent + "\n" + fs.readFileSync(file, { encoding: "utf8" });
|
||||
cssContent + '\n' + fs.readFileSync(file, {encoding: 'utf8'});
|
||||
});
|
||||
|
||||
if (
|
||||
|
@ -469,14 +470,14 @@ function execute(port) {
|
|||
) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Missing color configuration."
|
||||
'Missing color configuration.'
|
||||
)} Make sure siteConfig.colors includes primaryColor and secondaryColor fields.`
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
res.send(cssContent);
|
||||
|
@ -484,22 +485,22 @@ function execute(port) {
|
|||
|
||||
// serve static assets from these locations
|
||||
app.use(
|
||||
siteConfig.baseUrl + "docs/assets/",
|
||||
express.static(CWD + "/../" + readMetadata.getDocsPath() + "/assets")
|
||||
siteConfig.baseUrl + 'docs/assets/',
|
||||
express.static(CWD + '/../' + readMetadata.getDocsPath() + '/assets')
|
||||
);
|
||||
app.use(
|
||||
siteConfig.baseUrl + "blog/assets/",
|
||||
express.static(CWD + "/blog/assets")
|
||||
siteConfig.baseUrl + 'blog/assets/',
|
||||
express.static(CWD + '/blog/assets')
|
||||
);
|
||||
app.use(siteConfig.baseUrl, express.static(CWD + "/static"));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + "/../static"));
|
||||
app.use(siteConfig.baseUrl, express.static(CWD + '/static'));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + '/../static'));
|
||||
|
||||
// "redirect" requests to pages ending with "/" or no extension so that
|
||||
// request to "...blog" returns same result as "...blog/index.html"
|
||||
app.get(/\/[^\.]*\/?$/, (req, res) => {
|
||||
if (req.path.toString().endsWith("/")) {
|
||||
if (req.path.toString().endsWith('/')) {
|
||||
request.get(
|
||||
"http://localhost:" + port + req.path + "index.html",
|
||||
'http://localhost:' + port + req.path + 'index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
|
@ -508,7 +509,7 @@ function execute(port) {
|
|||
);
|
||||
} else {
|
||||
request.get(
|
||||
"http://localhost:" + port + req.path + "/index.html",
|
||||
'http://localhost:' + port + req.path + '/index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
|
@ -519,8 +520,8 @@ function execute(port) {
|
|||
});
|
||||
|
||||
app.listen(port);
|
||||
console.log("listening on port: " + port);
|
||||
console.log("Open http://localhost:" + port + "/");
|
||||
console.log('listening on port: ' + port);
|
||||
console.log('Open http://localhost:' + port + '/');
|
||||
}
|
||||
|
||||
module.exports = execute;
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const Feed = require("feed");
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const Feed = require('feed');
|
||||
|
||||
const chalk = require("chalk");
|
||||
const glob = require("glob");
|
||||
const chalk = require('chalk');
|
||||
const glob = require('glob');
|
||||
const CWD = process.cwd();
|
||||
|
||||
const sitemap = require("sitemap");
|
||||
const sitemap = require('sitemap');
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const blogFolder = path.resolve("../blog/");
|
||||
const blogRootURL = siteConfig.url + "/blog";
|
||||
const blogFolder = path.resolve('../blog/');
|
||||
const blogRootURL = siteConfig.url + '/blog';
|
||||
const jestImage = siteConfig.url + siteConfig.headerIcon;
|
||||
|
||||
/****************************************************************************/
|
||||
|
@ -28,32 +28,33 @@ let readMetadata;
|
|||
let Metadata;
|
||||
let MetadataBlog;
|
||||
|
||||
readMetadata = require("./readMetadata.js");
|
||||
readMetadata = require('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
Metadata = require("../core/metadata.js");
|
||||
Metadata = require('../core/metadata.js');
|
||||
readMetadata.generateMetadataBlog();
|
||||
MetadataBlog = require("../core/MetadataBlog.js");
|
||||
|
||||
MetadataBlog = require('../core/MetadataBlog.js');
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
module.exports = function(callback) {
|
||||
console.log("sitemap.js triggered...");
|
||||
console.log('sitemap.js triggered...');
|
||||
|
||||
let urls = [];
|
||||
|
||||
let files = glob.sync(CWD + "/pages/en/**/*.js");
|
||||
let files = glob.sync(CWD + '/pages/en/**/*.js');
|
||||
|
||||
// English-only is the default.
|
||||
let enabledLanguages = [{
|
||||
let enabledLanguages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}];
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
|
||||
// If we have a languages.js file, get all the enabled languages in there
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
let languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
let languages = require(CWD + '/languages.js');
|
||||
enabledLanguages = languages.filter(lang => {
|
||||
return lang.enabled == true;
|
||||
});
|
||||
|
@ -61,43 +62,50 @@ module.exports = function(callback) {
|
|||
|
||||
// create a url mapping to all the enabled languages files
|
||||
files.map(file => {
|
||||
let url = file.split("/pages/en")[1];
|
||||
url = url.replace(/\.js$/, ".html");
|
||||
let url = file.split('/pages/en')[1];
|
||||
url = url.replace(/\.js$/, '.html');
|
||||
let links = enabledLanguages.map(lang => {
|
||||
let langUrl = lang.tag + url;
|
||||
return {lang: lang.tag, url: langUrl};
|
||||
});
|
||||
urls.push({ url, changefreq: "weekly", priority: 0.5, links });
|
||||
urls.push({url, changefreq: 'weekly', priority: 0.5, links});
|
||||
});
|
||||
|
||||
let htmlFiles = glob.sync(CWD + "/pages/**/*.html");
|
||||
let htmlFiles = glob.sync(CWD + '/pages/**/*.html');
|
||||
|
||||
MetadataBlog.map(blog => {
|
||||
urls.push({
|
||||
url: "/blog/" + blog.path,
|
||||
changefreq: "weekly",
|
||||
priority: 0.3
|
||||
url: '/blog/' + blog.path,
|
||||
changefreq: 'weekly',
|
||||
priority: 0.3,
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(Metadata).filter(key => Metadata[key].language === "en").map(key => {
|
||||
Object.keys(Metadata)
|
||||
.filter(key => Metadata[key].language === 'en')
|
||||
.map(key => {
|
||||
let doc = Metadata[key];
|
||||
let links = enabledLanguages.map(lang => {
|
||||
let langUrl = doc.permalink.replace("docs/en/", `docs/${lang.tag}/`);
|
||||
let langUrl = doc.permalink.replace('docs/en/', `docs/${lang.tag}/`);
|
||||
return {lang: lang.tag, url: langUrl};
|
||||
});
|
||||
urls.push({ url: doc.permalink, changefreq: "hourly", priority: 1.0, links });
|
||||
urls.push({
|
||||
url: doc.permalink,
|
||||
changefreq: 'hourly',
|
||||
priority: 1.0,
|
||||
links,
|
||||
});
|
||||
});
|
||||
|
||||
const sm = sitemap.createSitemap({
|
||||
hostname: siteConfig.url,
|
||||
cacheTime: 600 * 1000, // 600 sec - cache purge period
|
||||
urls: urls
|
||||
urls: urls,
|
||||
});
|
||||
|
||||
sm.toXML((err, xml) => {
|
||||
if (err) {
|
||||
return "An error has occured.";
|
||||
return 'An error has occured.';
|
||||
}
|
||||
callback(xml);
|
||||
});
|
||||
|
|
|
@ -13,35 +13,35 @@ module.exports = function translatePlugin(babel) {
|
|||
return {
|
||||
visitor: {
|
||||
JSXElement(path) {
|
||||
if (path.node.openingElement.name.name !== "translate") {
|
||||
if (path.node.openingElement.name.name !== 'translate') {
|
||||
return;
|
||||
}
|
||||
/* assume translate element only has one child which is the text */
|
||||
const text = path.node.children[0].value.trim().replace(/\s+/g, " ");
|
||||
let description = "no description given";
|
||||
const text = path.node.children[0].value.trim().replace(/\s+/g, ' ');
|
||||
let description = 'no description given';
|
||||
const attributes = path.node.openingElement.attributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name.name === "desc") {
|
||||
if (attributes[i].name.name === 'desc') {
|
||||
description = attributes[i].value.value;
|
||||
}
|
||||
}
|
||||
/* use an expression container if inside a jsxelement */
|
||||
if (path.findParent(path => true).node.type === "JSXElement") {
|
||||
if (path.findParent(path => true).node.type === 'JSXElement') {
|
||||
path.replaceWith(
|
||||
t.jSXExpressionContainer(
|
||||
t.callExpression(t.identifier("translate"), [
|
||||
t.stringLiteral(text + "|" + description)
|
||||
t.callExpression(t.identifier('translate'), [
|
||||
t.stringLiteral(text + '|' + description),
|
||||
])
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(
|
||||
t.callExpression(t.identifier("translate"), [
|
||||
t.stringLiteral(text + "|" + description)
|
||||
t.callExpression(t.identifier('translate'), [
|
||||
t.stringLiteral(text + '|' + description),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const translation = require("./translation.js");
|
||||
const translation = require('./translation.js');
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
|
||||
/* handle escaped characters that get converted into json strings */
|
||||
function parseEscapeSequences(str) {
|
||||
return str
|
||||
.replace(new RegExp("\\\\n", "g"), "\n")
|
||||
.replace(new RegExp("\\\\b", "g"), "\b")
|
||||
.replace(new RegExp("\\\\f", "g"), "\f")
|
||||
.replace(new RegExp("\\\\r", "g"), "\r")
|
||||
.replace(new RegExp("\\\\t", "g"), "\t")
|
||||
.replace(new RegExp("\\\\'", "g"), "'")
|
||||
.replace(new RegExp('\\\\"', "g"), '"')
|
||||
.replace(new RegExp("\\\\", "g"), "\\");
|
||||
.replace(new RegExp('\\\\n', 'g'), '\n')
|
||||
.replace(new RegExp('\\\\b', 'g'), '\b')
|
||||
.replace(new RegExp('\\\\f', 'g'), '\f')
|
||||
.replace(new RegExp('\\\\r', 'g'), '\r')
|
||||
.replace(new RegExp('\\\\t', 'g'), '\t')
|
||||
.replace(new RegExp("\\\\'", 'g'), "'")
|
||||
.replace(new RegExp('\\\\"', 'g'), '"')
|
||||
.replace(new RegExp('\\\\', 'g'), '\\');
|
||||
}
|
||||
|
||||
function setLanguage(lang) {
|
||||
|
@ -29,14 +29,14 @@ function setLanguage(lang) {
|
|||
function translate(str) {
|
||||
if (
|
||||
!translation[language] ||
|
||||
!translation[language]["pages-strings"] ||
|
||||
!translation[language]["pages-strings"][str]
|
||||
!translation[language]['pages-strings'] ||
|
||||
!translation[language]['pages-strings'][str]
|
||||
) {
|
||||
// if a translated string doesn't exist, but english does then fallback
|
||||
if (
|
||||
translation["en"] &&
|
||||
translation["en"]["pages-strings"] &&
|
||||
translation["en"]["pages-strings"][str]
|
||||
translation['en'] &&
|
||||
translation['en']['pages-strings'] &&
|
||||
translation['en']['pages-strings'][str]
|
||||
) {
|
||||
console.error(
|
||||
"Could not find a string translation in '" +
|
||||
|
@ -46,7 +46,7 @@ function translate(str) {
|
|||
"'. Using English version instead."
|
||||
);
|
||||
|
||||
return parseEscapeSequences(translation["en"]["pages-strings"][str]);
|
||||
return parseEscapeSequences(translation['en']['pages-strings'][str]);
|
||||
}
|
||||
throw new Error(
|
||||
"Text that you've identified for translation ('" +
|
||||
|
@ -54,10 +54,10 @@ function translate(str) {
|
|||
"') hasn't been added to the global list in 'en.json'. To solve this problem run 'yarn write-translations'."
|
||||
);
|
||||
}
|
||||
return parseEscapeSequences(translation[language]["pages-strings"][str]);
|
||||
return parseEscapeSequences(translation[language]['pages-strings'][str]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setLanguage: setLanguage,
|
||||
translate: translate
|
||||
translate: translate,
|
||||
};
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
// translation object contains all translations for each string in 18n/en.json
|
||||
|
||||
const CWD = process.cwd();
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ const enabledLanguages = languages.filter(lang => lang.enabled);
|
|||
|
||||
const translation = {languages: enabledLanguages};
|
||||
|
||||
const files = glob.sync(CWD + "/i18n/**");
|
||||
const files = glob.sync(CWD + '/i18n/**');
|
||||
const langRegex = /\/i18n\/(.*)\.json$/;
|
||||
|
||||
console.log("Loading translation files...");
|
||||
console.log('Loading translation files...');
|
||||
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".json") {
|
||||
if (extension === '.json') {
|
||||
const match = langRegex.exec(file);
|
||||
const language = match[1];
|
||||
translation[language] = require(file);
|
||||
|
|
|
@ -6,32 +6,32 @@
|
|||
*/
|
||||
|
||||
const CWD = process.cwd();
|
||||
const glob = require("glob");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const assert = require("assert");
|
||||
const glob = require('glob');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js');
|
||||
|
||||
let versions;
|
||||
if (fs.existsSync(CWD + "/versions.json")) {
|
||||
versions = require(CWD + "/versions.json");
|
||||
if (fs.existsSync(CWD + '/versions.json')) {
|
||||
versions = require(CWD + '/versions.json');
|
||||
} else {
|
||||
versions = [];
|
||||
}
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -40,16 +40,16 @@ if (fs.existsSync(CWD + "/languages.js")) {
|
|||
// included to prevent cyclical dependency with readMetadata.js
|
||||
|
||||
function splitHeader(content) {
|
||||
const lines = content.split("\n");
|
||||
const lines = content.split('\n');
|
||||
let i = 1;
|
||||
for (; i < lines.length - 1; ++i) {
|
||||
if (lines[i] === "---") {
|
||||
if (lines[i] === '---') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
header: lines.slice(1, i + 1).join("\n"),
|
||||
content: lines.slice(i + 1).join("\n")
|
||||
header: lines.slice(1, i + 1).join('\n'),
|
||||
content: lines.slice(i + 1).join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -61,13 +61,13 @@ function extractMetadata(content) {
|
|||
if (!both.content) {
|
||||
return {metadata, rawContent: both.header};
|
||||
}
|
||||
const lines = both.header.split("\n");
|
||||
const lines = both.header.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(":");
|
||||
const keyvalue = lines[i].split(':');
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(":")
|
||||
.join(':')
|
||||
.trim();
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
|
@ -79,7 +79,7 @@ function extractMetadata(content) {
|
|||
|
||||
/*****************************************************************/
|
||||
|
||||
const versionFolder = CWD + "/versioned_docs/";
|
||||
const versionFolder = CWD + '/versioned_docs/';
|
||||
|
||||
// available stores doc ids of documents that are available for
|
||||
// each version
|
||||
|
@ -87,39 +87,47 @@ const available = {};
|
|||
// versionFiles is used to keep track of what file to use with a
|
||||
// given version/id of a document
|
||||
const versionFiles = {};
|
||||
let files = glob.sync(versionFolder + "**");
|
||||
let files = glob.sync(versionFolder + '**');
|
||||
files.forEach(file => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== ".md" && ext !== ".markdown") {
|
||||
if (ext !== '.md' && ext !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
const res = extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const res = extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
const metadata = res.metadata;
|
||||
|
||||
if (!metadata.original_id) {
|
||||
console.error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`No 'original_id' field found in ${
|
||||
file
|
||||
}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
throw new Error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`No 'original_id' field found in ${
|
||||
file
|
||||
}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
}
|
||||
if (!metadata.id) {
|
||||
console.error(`No 'id' field found in ${file}.`);
|
||||
throw new Error(`No 'id' field found in ${file}.`);
|
||||
} else if (metadata.id.indexOf("version-") === -1) {
|
||||
} else if (metadata.id.indexOf('version-') === -1) {
|
||||
console.error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`The 'id' field in ${
|
||||
file
|
||||
} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
throw new Error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`The 'id' field in ${
|
||||
file
|
||||
} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
}
|
||||
|
||||
if (!(metadata.original_id in available)) {
|
||||
available[metadata.original_id] = new Set();
|
||||
}
|
||||
const version = metadata.id.split("-")[1];
|
||||
const version = metadata.id.split('-')[1];
|
||||
available[metadata.original_id].add(version);
|
||||
|
||||
if (!(version in versionFiles)) {
|
||||
|
@ -133,7 +141,9 @@ files.forEach(file => {
|
|||
function docVersion(id, req_version) {
|
||||
if (!available[id]) {
|
||||
throw new Error(
|
||||
`Document with id '${id}' was requested but no document with that id could be located.`
|
||||
`Document with id '${
|
||||
id
|
||||
}' was requested but no document with that id could be located.`
|
||||
);
|
||||
}
|
||||
// iterate through versions until a version less than or equal to the requested
|
||||
|
@ -179,40 +189,40 @@ function diffLatestDoc(file, id) {
|
|||
}
|
||||
|
||||
return (
|
||||
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent.trim() !==
|
||||
extractMetadata(fs.readFileSync(file, "utf8")).rawContent.trim()
|
||||
extractMetadata(fs.readFileSync(latestFile, 'utf8')).rawContent.trim() !==
|
||||
extractMetadata(fs.readFileSync(file, 'utf8')).rawContent.trim()
|
||||
);
|
||||
}
|
||||
|
||||
// return metadata for a versioned file given the file, its version (requested),
|
||||
// the version of the file to be used, and its language
|
||||
function processVersionMetadata(file, version, useVersion, language) {
|
||||
const metadata = extractMetadata(fs.readFileSync(file, "utf8")).metadata;
|
||||
metadata.source = "version-" + useVersion + "/" + path.basename(file);
|
||||
const metadata = extractMetadata(fs.readFileSync(file, 'utf8')).metadata;
|
||||
metadata.source = 'version-' + useVersion + '/' + path.basename(file);
|
||||
|
||||
const latestVersion = versions[0];
|
||||
|
||||
if (!ENABLE_TRANSLATION && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink =
|
||||
"docs/" +
|
||||
(version !== latestVersion ? version + "/" : "") +
|
||||
'docs/' +
|
||||
(version !== latestVersion ? version + '/' : '') +
|
||||
metadata.original_id +
|
||||
".html";
|
||||
'.html';
|
||||
} else {
|
||||
metadata.permalink =
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
language +
|
||||
"/" +
|
||||
(version !== latestVersion ? version + "/" : "") +
|
||||
'/' +
|
||||
(version !== latestVersion ? version + '/' : '') +
|
||||
metadata.original_id +
|
||||
".html";
|
||||
'.html';
|
||||
}
|
||||
metadata.id = metadata.id.replace(
|
||||
"version-" + useVersion + "-",
|
||||
"version-" + version + "-"
|
||||
'version-' + useVersion + '-',
|
||||
'version-' + version + '-'
|
||||
);
|
||||
metadata.localized_id = metadata.id;
|
||||
metadata.id = language + "-" + metadata.id;
|
||||
metadata.id = language + '-' + metadata.id;
|
||||
metadata.language = language;
|
||||
metadata.version = version;
|
||||
|
||||
|
@ -269,14 +279,16 @@ function sidebarVersion(req_version) {
|
|||
}
|
||||
if (
|
||||
fs.existsSync(
|
||||
CWD + "/versioned_sidebars/version-" + versions[i] + "-sidebars.json"
|
||||
CWD + '/versioned_sidebars/version-' + versions[i] + '-sidebars.json'
|
||||
)
|
||||
) {
|
||||
return versions[i];
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
`No sidebar file available to use for version ${req_version}. Verify that 'version-${req_version}-sidebars.json' exists.`
|
||||
`No sidebar file available to use for version ${
|
||||
req_version
|
||||
}. Verify that 'version-${req_version}-sidebars.json' exists.`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -290,11 +302,11 @@ function diffLatestSidebar() {
|
|||
|
||||
const version = sidebarVersion(latest);
|
||||
const latestSidebar =
|
||||
CWD + "/versioned_sidebars/version-" + version + "-sidebars.json";
|
||||
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json';
|
||||
if (!fs.existsSync(latestSidebar)) {
|
||||
return true;
|
||||
}
|
||||
const currentSidebar = CWD + "/sidebars.json";
|
||||
const currentSidebar = CWD + '/sidebars.json';
|
||||
// if no current sidebar file, return false so no sidebar file gets copied
|
||||
if (!fs.existsSync(currentSidebar)) {
|
||||
return false;
|
||||
|
@ -303,10 +315,10 @@ function diffLatestSidebar() {
|
|||
// compare for equality between latest version sidebar with version prefixes
|
||||
// stripped and current sidebar
|
||||
return (
|
||||
JSON.stringify(JSON.parse(fs.readFileSync(latestSidebar, "utf8"))).replace(
|
||||
new RegExp("version-" + version + "-", "g"),
|
||||
""
|
||||
) !== JSON.stringify(JSON.parse(fs.readFileSync(currentSidebar, "utf8")))
|
||||
JSON.stringify(JSON.parse(fs.readFileSync(latestSidebar, 'utf8'))).replace(
|
||||
new RegExp('version-' + version + '-', 'g'),
|
||||
''
|
||||
) !== JSON.stringify(JSON.parse(fs.readFileSync(currentSidebar, 'utf8')))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -319,12 +331,12 @@ function sidebarData() {
|
|||
const sidebar = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
CWD + "/versioned_sidebars/version-" + version + "-sidebars.json",
|
||||
"utf8"
|
||||
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json',
|
||||
'utf8'
|
||||
)
|
||||
.replace(
|
||||
new RegExp("version-" + version + "-", "g"),
|
||||
"version-" + versions[i] + "-"
|
||||
new RegExp('version-' + version + '-', 'g'),
|
||||
'version-' + versions[i] + '-'
|
||||
)
|
||||
);
|
||||
Object.assign(allSidebars, sidebar);
|
||||
|
@ -339,5 +351,5 @@ module.exports = {
|
|||
docData,
|
||||
sidebarVersion,
|
||||
diffLatestSidebar,
|
||||
sidebarData
|
||||
sidebarData,
|
||||
};
|
||||
|
|
|
@ -7,46 +7,43 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
require("babel-register")({
|
||||
require('babel-register')({
|
||||
babelrc: false,
|
||||
only: [__dirname, process.cwd() + "/core"],
|
||||
plugins: [require("./server/translate-plugin.js")],
|
||||
presets: ["react", "env"]
|
||||
only: [__dirname, process.cwd() + '/core'],
|
||||
plugins: [require('./server/translate-plugin.js')],
|
||||
presets: ['react', 'env'],
|
||||
});
|
||||
|
||||
// For verifying port usage
|
||||
const tcpPortUsed = require('tcp-port-used');
|
||||
|
||||
// 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")) {
|
||||
if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
||||
console.error(
|
||||
chalk.red("Error: No siteConfig.js file found in website folder!")
|
||||
chalk.red('Error: No siteConfig.js file found in website folder!')
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const program = require("commander");
|
||||
const program = require('commander');
|
||||
|
||||
program.option("--port <number>", "Specify port number").parse(process.argv);
|
||||
program.option('--port <number>', 'Specify port number').parse(process.argv);
|
||||
|
||||
const port = parseInt(program.port, 10) || 3000;
|
||||
|
||||
console.log("Checking if port " + port + " is free...");
|
||||
tcpPortUsed.check(port, "localhost")
|
||||
.then(function(inUse) {
|
||||
console.log('Checking if port ' + port + ' is free...');
|
||||
tcpPortUsed.check(port, 'localhost').then(function(inUse) {
|
||||
if (inUse) {
|
||||
console.error(
|
||||
chalk.red("Port " + port + " is in use")
|
||||
);
|
||||
console.error(chalk.red('Port ' + port + ' is in use'));
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log("Starting Docusaurus server on port " + port + "...");
|
||||
console.log('Starting Docusaurus server on port ' + port + '...');
|
||||
// start local server on specified port
|
||||
const server = require("./server/server.js");
|
||||
const server = require('./server/server.js');
|
||||
server(port);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -7,36 +7,36 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const glob = require("glob");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const mkdirp = require("mkdirp");
|
||||
const chalk = require("chalk");
|
||||
const readMetadata = require("./server/readMetadata.js");
|
||||
const versionFallback = require("./server/versionFallback.js");
|
||||
const glob = require('glob');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const mkdirp = require('mkdirp');
|
||||
const chalk = require('chalk');
|
||||
const readMetadata = require('./server/readMetadata.js');
|
||||
const versionFallback = require('./server/versionFallback.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
let versions;
|
||||
if (fs.existsSync(CWD + "/versions.json")) {
|
||||
versions = require(CWD + "/versions.json");
|
||||
if (fs.existsSync(CWD + '/versions.json')) {
|
||||
versions = require(CWD + '/versions.json');
|
||||
} else {
|
||||
versions = [];
|
||||
}
|
||||
|
||||
let version;
|
||||
|
||||
const program = require("commander");
|
||||
const program = require('commander');
|
||||
program
|
||||
.arguments("<version>")
|
||||
.arguments('<version>')
|
||||
.action(ver => {
|
||||
version = ver;
|
||||
})
|
||||
.parse(process.argv);
|
||||
|
||||
if (typeof version === "undefined") {
|
||||
if (typeof version === 'undefined') {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"No version number specified!"
|
||||
'No version number specified!'
|
||||
)}\nPass the version you wish to create as an argument.\nEx: 1.0.0`
|
||||
);
|
||||
process.exit(1);
|
||||
|
@ -45,34 +45,34 @@ if (typeof version === "undefined") {
|
|||
if (versions.includes(version)) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"This version already exists!"
|
||||
'This version already exists!'
|
||||
)}\nSpecify a new version to create that does not already exist.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function makeHeader(metadata) {
|
||||
let header = "---\n";
|
||||
let header = '---\n';
|
||||
Object.keys(metadata).forEach(key => {
|
||||
header += key + ": " + metadata[key] + "\n";
|
||||
header += key + ': ' + metadata[key] + '\n';
|
||||
});
|
||||
header += "---\n";
|
||||
header += '---\n';
|
||||
return header;
|
||||
}
|
||||
|
||||
const versionFolder = CWD + "/versioned_docs/version-" + version;
|
||||
const versionFolder = CWD + '/versioned_docs/version-' + version;
|
||||
|
||||
mkdirp.sync(versionFolder);
|
||||
|
||||
// copy necessary files to new version, changing some of its metadata to reflect the versioning
|
||||
let files = glob.sync(CWD + "/../" + readMetadata.getDocsPath() + "/*");
|
||||
let files = glob.sync(CWD + '/../' + readMetadata.getDocsPath() + '/*');
|
||||
files.forEach(file => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== ".md" && ext !== ".markdown") {
|
||||
if (ext !== '.md' && ext !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
|
||||
const res = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const res = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
let metadata = res.metadata;
|
||||
// Don't version any docs without any metadata whatsoever.
|
||||
if (Object.keys(metadata).length === 0) {
|
||||
|
@ -82,7 +82,7 @@ files.forEach(file => {
|
|||
if (!metadata.id) {
|
||||
metadata.id = path.basename(file, path.extname(file));
|
||||
}
|
||||
if (metadata.id.includes("/")) {
|
||||
if (metadata.id.includes('/')) {
|
||||
throw new Error('Document id cannot include "/".');
|
||||
}
|
||||
if (!metadata.title) {
|
||||
|
@ -94,22 +94,22 @@ files.forEach(file => {
|
|||
}
|
||||
|
||||
metadata.original_id = metadata.id;
|
||||
metadata.id = "version-" + version + "-" + metadata.id;
|
||||
metadata.id = 'version-' + version + '-' + metadata.id;
|
||||
|
||||
const targetFile =
|
||||
CWD + "/versioned_docs/version-" + version + "/" + path.basename(file);
|
||||
CWD + '/versioned_docs/version-' + version + '/' + path.basename(file);
|
||||
|
||||
fs.writeFileSync(targetFile, makeHeader(metadata) + rawContent, "utf8");
|
||||
fs.writeFileSync(targetFile, makeHeader(metadata) + rawContent, 'utf8');
|
||||
});
|
||||
|
||||
// copy sidebar if necessary
|
||||
if (versionFallback.diffLatestSidebar()) {
|
||||
mkdirp(CWD + "/versioned_sidebars");
|
||||
const sidebar = JSON.parse(fs.readFileSync(CWD + "/sidebars.json", "utf8"));
|
||||
mkdirp(CWD + '/versioned_sidebars');
|
||||
const sidebar = JSON.parse(fs.readFileSync(CWD + '/sidebars.json', 'utf8'));
|
||||
const versioned = {};
|
||||
|
||||
Object.keys(sidebar).forEach(sb => {
|
||||
const version_sb = "version-" + version + "-" + sb;
|
||||
const version_sb = 'version-' + version + '-' + sb;
|
||||
versioned[version_sb] = {};
|
||||
|
||||
const categories = sidebar[sb];
|
||||
|
@ -118,20 +118,20 @@ if (versionFallback.diffLatestSidebar()) {
|
|||
|
||||
const ids = categories[category];
|
||||
ids.forEach((id, index) => {
|
||||
versioned[version_sb][category].push("version-" + version + "-" + id);
|
||||
versioned[version_sb][category].push('version-' + version + '-' + id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
CWD + "/versioned_sidebars/version-" + version + "-sidebars.json",
|
||||
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json',
|
||||
JSON.stringify(versioned, null, 2),
|
||||
"utf8"
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
// update versions.json file
|
||||
versions.unshift(version);
|
||||
fs.writeFileSync(CWD + "/versions.json", JSON.stringify(versions, null, 2));
|
||||
fs.writeFileSync(CWD + '/versions.json', JSON.stringify(versions, null, 2));
|
||||
|
||||
console.log(`${chalk.green("Version " + version + " created!\n")}`);
|
||||
console.log(`${chalk.green('Version ' + version + ' created!\n')}`);
|
||||
|
|
|
@ -10,48 +10,48 @@
|
|||
/* generate the i18n/en.json file */
|
||||
|
||||
const CWD = process.cwd();
|
||||
const fs = require("fs-extra");
|
||||
const mkdirp = require("mkdirp");
|
||||
const glob = require("glob");
|
||||
const readMetadata = require("./server/readMetadata.js");
|
||||
const path = require("path");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const babylon = require("babylon");
|
||||
const traverse = require("babel-traverse").default;
|
||||
const sidebars = require(CWD + "/sidebars.json");
|
||||
const fs = require('fs-extra');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
const readMetadata = require('./server/readMetadata.js');
|
||||
const path = require('path');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const babylon = require('babylon');
|
||||
const traverse = require('babel-traverse').default;
|
||||
const sidebars = require(CWD + '/sidebars.json');
|
||||
|
||||
let currentTranslations = {
|
||||
"localized-strings": {},
|
||||
"pages-strings": {}
|
||||
'localized-strings': {},
|
||||
'pages-strings': {},
|
||||
};
|
||||
if (fs.existsSync(path)) {
|
||||
currentTranslations = JSON.parse(
|
||||
fs.readFileSync(CWD + "/i18n/en.json", "utf8")
|
||||
fs.readFileSync(CWD + '/i18n/en.json', 'utf8')
|
||||
);
|
||||
}
|
||||
|
||||
function writeFileAndCreateFolder(file, content) {
|
||||
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(file.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.writeFileSync(file, content);
|
||||
}
|
||||
|
||||
function execute() {
|
||||
console.log("Extracting translateable strings from files...");
|
||||
console.log('Extracting translateable strings from files...');
|
||||
|
||||
let translations = {
|
||||
"localized-strings": {
|
||||
next: "Next",
|
||||
previous: "Previous",
|
||||
tagline: siteConfig.tagline
|
||||
'localized-strings': {
|
||||
next: 'Next',
|
||||
previous: 'Previous',
|
||||
tagline: siteConfig.tagline,
|
||||
},
|
||||
"pages-strings": {}
|
||||
'pages-strings': {},
|
||||
};
|
||||
|
||||
// look through markdown headers of docs for titles and categories to translate
|
||||
let files = glob.sync(CWD + "/../" + readMetadata.getDocsPath() + "/**");
|
||||
let files = glob.sync(CWD + '/../' + readMetadata.getDocsPath() + '/**');
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
let res;
|
||||
try {
|
||||
res = readMetadata.processMetadata(file);
|
||||
|
@ -64,10 +64,10 @@ function execute() {
|
|||
}
|
||||
const metadata = res.metadata;
|
||||
|
||||
translations["localized-strings"][metadata.localized_id] = metadata.title;
|
||||
translations['localized-strings'][metadata.localized_id] = metadata.title;
|
||||
|
||||
if (metadata.sidebar_label) {
|
||||
translations["localized-strings"][metadata.sidebar_label] =
|
||||
translations['localized-strings'][metadata.sidebar_label] =
|
||||
metadata.sidebar_label;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ function execute() {
|
|||
// look through header links for text to translate
|
||||
siteConfig.headerLinks.forEach(link => {
|
||||
if (link.label) {
|
||||
translations["localized-strings"][link.label] = link.label;
|
||||
translations['localized-strings'][link.label] = link.label;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -83,21 +83,25 @@ function execute() {
|
|||
Object.keys(sidebars).forEach(sb => {
|
||||
const categories = sidebars[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
translations["localized-strings"][category] = category;
|
||||
translations['localized-strings'][category] = category;
|
||||
});
|
||||
});
|
||||
|
||||
files = glob.sync(CWD + "/versioned_sidebars/*");
|
||||
files = glob.sync(CWD + '/versioned_sidebars/*');
|
||||
files.forEach(file => {
|
||||
if (!file.endsWith("-sidebars.json")) {
|
||||
if (file.endsWith("-sidebar.json")) {
|
||||
console.warn(`Skipping ${file}. Make sure your sidebar filenames follow this format: 'version-VERSION-sidebars.json'.`);
|
||||
if (!file.endsWith('-sidebars.json')) {
|
||||
if (file.endsWith('-sidebar.json')) {
|
||||
console.warn(
|
||||
`Skipping ${
|
||||
file
|
||||
}. Make sure your sidebar filenames follow this format: 'version-VERSION-sidebars.json'.`
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let sidebarContent;
|
||||
try {
|
||||
sidebarContent = JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
sidebarContent = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
} catch (e) {
|
||||
console.error(`Could not parse ${file} into json. ${e}`);
|
||||
process.exit(1);
|
||||
|
@ -106,69 +110,69 @@ function execute() {
|
|||
Object.keys(sidebarContent).forEach(sb => {
|
||||
const categories = sidebarContent[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
translations["localized-strings"][category] = category;
|
||||
translations['localized-strings'][category] = category;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// go through pages to look for text inside translate tags
|
||||
files = glob.sync(CWD + "/pages/en/**");
|
||||
files = glob.sync(CWD + '/pages/en/**');
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".js") {
|
||||
const ast = babylon.parse(fs.readFileSync(file, "utf8"), {
|
||||
plugins: ["jsx"]
|
||||
if (extension === '.js') {
|
||||
const ast = babylon.parse(fs.readFileSync(file, 'utf8'), {
|
||||
plugins: ['jsx'],
|
||||
});
|
||||
traverse(ast, {
|
||||
enter(path) {
|
||||
if (
|
||||
path.node.type === "JSXElement" &&
|
||||
path.node.openingElement.name.name === "translate"
|
||||
path.node.type === 'JSXElement' &&
|
||||
path.node.openingElement.name.name === 'translate'
|
||||
) {
|
||||
const text = path.node.children[0].value
|
||||
.trim()
|
||||
.replace(/\s+/g, " ");
|
||||
let description = "no description given";
|
||||
.replace(/\s+/g, ' ');
|
||||
let description = 'no description given';
|
||||
const attributes = path.node.openingElement.attributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name.name === "desc") {
|
||||
if (attributes[i].name.name === 'desc') {
|
||||
description = attributes[i].value.value;
|
||||
}
|
||||
}
|
||||
translations["pages-strings"][text + "|" + description] = text;
|
||||
}
|
||||
translations['pages-strings'][text + '|' + description] = text;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Manually add 'Help Translate' to en.json
|
||||
translations["pages-strings"][
|
||||
"Help Translate|recruit community translators for your project"
|
||||
translations['pages-strings'][
|
||||
'Help Translate|recruit community translators for your project'
|
||||
] =
|
||||
"Help Translate";
|
||||
translations["pages-strings"][
|
||||
"Edit this Doc|recruitment message asking to edit the doc source"
|
||||
'Help Translate';
|
||||
translations['pages-strings'][
|
||||
'Edit this Doc|recruitment message asking to edit the doc source'
|
||||
] =
|
||||
"Edit";
|
||||
translations["pages-strings"][
|
||||
"Translate this Doc|recruitment message asking to translate the docs"
|
||||
'Edit';
|
||||
translations['pages-strings'][
|
||||
'Translate this Doc|recruitment message asking to translate the docs'
|
||||
] =
|
||||
"Translate";
|
||||
translations["pages-strings"] = Object.assign(
|
||||
translations["pages-strings"],
|
||||
currentTranslations["pages-strings"]
|
||||
'Translate';
|
||||
translations['pages-strings'] = Object.assign(
|
||||
translations['pages-strings'],
|
||||
currentTranslations['pages-strings']
|
||||
);
|
||||
translations["localized-strings"] = Object.assign(
|
||||
translations["localized-strings"],
|
||||
currentTranslations["localized-strings"]
|
||||
translations['localized-strings'] = Object.assign(
|
||||
translations['localized-strings'],
|
||||
currentTranslations['localized-strings']
|
||||
);
|
||||
writeFileAndCreateFolder(
|
||||
CWD + "/i18n/en.json",
|
||||
CWD + '/i18n/en.json',
|
||||
JSON.stringify(
|
||||
Object.assign(
|
||||
{
|
||||
_comment: "This file is auto-generated by write-translations.js"
|
||||
_comment: 'This file is auto-generated by write-translations.js',
|
||||
},
|
||||
translations
|
||||
),
|
||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,12 @@
|
|||
{
|
||||
"scripts": {
|
||||
"test": "true"
|
||||
"ci-check": "yarn prettier:diff",
|
||||
"format:source": "prettier --config .prettierrc --write \"lib/**/*.js\"",
|
||||
"format:examples": "prettier --config .prettierrc --write \"examples/**/*.js\"",
|
||||
"nit:source": "prettier --config .prettierrc --list-different \"lib/**/*.js\"",
|
||||
"nit:examples": "prettier --config .prettierrc --list-different \"examples/**/*.js\"",
|
||||
"prettier": "yarn format:source && yarn format:examples",
|
||||
"prettier:diff": "yarn nit:source && yarn nit:examples"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-preset-env": "^1.6.0",
|
||||
|
@ -18,7 +24,7 @@
|
|||
"fs-extra": "^3.0.1",
|
||||
"glob": "^7.1.2",
|
||||
"highlight.js": "^9.12.0",
|
||||
"prettier": "^1.5.3",
|
||||
"prettier": "1.8.2",
|
||||
"react": "^15.5.4",
|
||||
"react-dom": "^15.5.4",
|
||||
"react-dom-factories": "^1.0.1",
|
||||
|
|
|
@ -1274,9 +1274,9 @@ performance-now@^2.1.0:
|
|||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||
|
||||
prettier@^1.5.3:
|
||||
version "1.7.4"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.4.tgz#5e8624ae9363c80f95ec644584ecdf55d74f93fa"
|
||||
prettier@1.8.2:
|
||||
version "1.8.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.8.2.tgz#bff83e7fd573933c607875e5ba3abbdffb96aeb8"
|
||||
|
||||
private@^0.1.6, private@^0.1.7:
|
||||
version "0.1.8"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue