Use template strings, update React components, and update package.json files

This commit is contained in:
Frank Li 2017-07-28 16:59:41 -07:00
parent 9b35317fb5
commit c6503c4bfa
11 changed files with 95 additions and 104 deletions

3
lib/build-files.js Normal file → Executable file
View file

@ -10,10 +10,9 @@
*/ */
require("babel-register")({ require("babel-register")({
ignore: false,
babelrc: false, babelrc: false,
plugins: [require("./server/translate-plugin.js")], plugins: [require("./server/translate-plugin.js")],
presets: ["react"] presets: ["react", "latest", "stage-0"]
}); });
const generate = require("./server/generate.js"); const generate = require("./server/generate.js");

0
lib/copy-examples.js Normal file → Executable file
View file

View file

@ -18,17 +18,17 @@ const React = require("react");
// Private helper vars // Private helper vars
const lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i; const lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
const _ = (Prism = { const Prism = {
util: { util: {
encode(tokens) { encode(tokens) {
if (tokens instanceof Token) { if (tokens instanceof Token) {
return new Token( return new Token(
tokens.type, tokens.type,
_.util.encode(tokens.content), Prism.util.encode(tokens.content),
tokens.alias tokens.alias
); );
} else if (_.util.type(tokens) === "Array") { } else if (Prism.util.type(tokens) === "Array") {
return tokens.map(_.util.encode); return tokens.map(Prism.util.encode);
} else { } else {
return tokens return tokens
.replace(/&/g, "&") .replace(/&/g, "&")
@ -43,7 +43,7 @@ const _ = (Prism = {
// Deep clone a language definition (e.g. to extend it) // Deep clone a language definition (e.g. to extend it)
clone(o) { clone(o) {
const type = _.util.type(o); const type = Prism.util.type(o);
switch (type) { switch (type) {
case "Object": case "Object":
@ -51,7 +51,7 @@ const _ = (Prism = {
for (const key in o) { for (const key in o) {
if (o.hasOwnProperty(key)) { if (o.hasOwnProperty(key)) {
clone[key] = _.util.clone(o[key]); clone[key] = Prism.util.clone(o[key]);
} }
} }
@ -62,7 +62,7 @@ const _ = (Prism = {
return ( return (
o.map && o.map &&
o.map(v => { o.map(v => {
return _.util.clone(v); return Prism.util.clone(v);
}) })
); );
} }
@ -73,7 +73,7 @@ const _ = (Prism = {
languages: { languages: {
extend(id, redef) { extend(id, redef) {
const lang = _.util.clone(_.languages[id]); const lang = Prism.util.clone(Prism.languages[id]);
for (const key in redef) { for (const key in redef) {
lang[key] = redef[key]; lang[key] = redef[key];
@ -92,7 +92,7 @@ const _ = (Prism = {
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted. * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
*/ */
insertBefore(inside, before, insert, root) { insertBefore(inside, before, insert, root) {
root = root || _.languages; root = root || Prism.languages;
const grammar = root[inside]; const grammar = root[inside];
if (arguments.length == 2) { if (arguments.length == 2) {
@ -124,7 +124,7 @@ const _ = (Prism = {
} }
// Update references in other language definitions // Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) { Prism.languages.DFS(Prism.languages, function(key, value) {
if (value === root[inside] && key != inside) { if (value === root[inside] && key != inside) {
this[key] = ret; this[key] = ret;
} }
@ -139,10 +139,10 @@ const _ = (Prism = {
if (o.hasOwnProperty(i)) { if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i); callback.call(o, i, o[i], type || i);
if (_.util.type(o[i]) === "Object") { if (Prism.util.type(o[i]) === "Object") {
_.languages.DFS(o[i], callback); Prism.languages.DFS(o[i], callback);
} else if (_.util.type(o[i]) === "Array") { } else if (Prism.util.type(o[i]) === "Array") {
_.languages.DFS(o[i], callback, i); Prism.languages.DFS(o[i], callback, i);
} }
} }
} }
@ -155,7 +155,7 @@ const _ = (Prism = {
); );
for (let i = 0, element; (element = elements[i++]); ) { for (let i = 0, element; (element = elements[i++]); ) {
_.highlightElement(element, async === true, callback); Prism.highlightElement(element, async === true, callback);
} }
}, },
@ -171,7 +171,7 @@ const _ = (Prism = {
if (parent) { if (parent) {
language = (parent.className.match(lang) || [, ""])[1]; language = (parent.className.match(lang) || [, ""])[1];
grammar = _.languages[language]; grammar = Prism.languages[language];
} }
// Set language on the element, if not present // Set language on the element, if not present
@ -209,20 +209,20 @@ const _ = (Prism = {
code code
}; };
_.hooks.run("before-highlight", env); Prism.hooks.run("before-highlight", env);
if (async && _self.Worker) { if (async && Prismself.Worker) {
const worker = new Worker(_.filename); const worker = new Worker(Prism.filename);
worker.onmessage = function(evt) { worker.onmessage = function(evt) {
env.highlightedCode = Token.stringify(JSON.parse(evt.data), language); env.highlightedCode = Token.stringify(JSON.parse(evt.data), language);
_.hooks.run("before-insert", env); Prism.hooks.run("before-insert", env);
env.element.innerHTML = env.highlightedCode; env.element.innerHTML = env.highlightedCode;
callback && callback.call(env.element); callback && callback.call(env.element);
_.hooks.run("after-highlight", env); Prism.hooks.run("after-highlight", env);
}; };
worker.postMessage( worker.postMessage(
@ -232,25 +232,25 @@ const _ = (Prism = {
}) })
); );
} else { } else {
env.highlightedCode = _.highlight(env.code, env.grammar, env.language); env.highlightedCode = Prism.highlight(env.code, env.grammar, env.language);
_.hooks.run("before-insert", env); Prism.hooks.run("before-insert", env);
env.element.innerHTML = env.highlightedCode; env.element.innerHTML = env.highlightedCode;
callback && callback.call(element); callback && callback.call(element);
_.hooks.run("after-highlight", env); Prism.hooks.run("after-highlight", env);
} }
}, },
highlight(text, grammar, language) { highlight(text, grammar, language) {
const tokens = _.tokenize(text, grammar); const tokens = Prism.tokenize(text, grammar);
return Token.stringify(_.util.encode(tokens), language); return Token.stringify(Prism.util.encode(tokens), language);
}, },
tokenize(text, grammar, language) { tokenize(text, grammar, language) {
const Token = _.Token; const Token = Prism.Token;
const strarr = [text]; const strarr = [text];
@ -270,7 +270,7 @@ const _ = (Prism = {
} }
let patterns = grammar[token]; let patterns = grammar[token];
patterns = _.util.type(patterns) === "Array" ? patterns : [patterns]; patterns = Prism.util.type(patterns) === "Array" ? patterns : [patterns];
for (let j = 0; j < patterns.length; ++j) { for (let j = 0; j < patterns.length; ++j) {
let pattern = patterns[j], let pattern = patterns[j],
@ -319,7 +319,7 @@ const _ = (Prism = {
const wrapped = new Token( const wrapped = new Token(
token, token,
inside ? _.tokenize(match, inside) : match, inside ? Prism.tokenize(match, inside) : match,
alias alias
); );
@ -342,7 +342,7 @@ const _ = (Prism = {
all: {}, all: {},
add(name, callback) { add(name, callback) {
const hooks = _.hooks.all; const hooks = Prism.hooks.all;
hooks[name] = hooks[name] || []; hooks[name] = hooks[name] || [];
@ -350,7 +350,7 @@ const _ = (Prism = {
}, },
run(name, env) { run(name, env) {
const callbacks = _.hooks.all[name]; const callbacks = Prism.hooks.all[name];
if (!callbacks || !callbacks.length) { if (!callbacks || !callbacks.length) {
return; return;
@ -361,9 +361,9 @@ const _ = (Prism = {
} }
} }
} }
}); };
const Token = (_.Token = function(type, content, alias) { const Token = (Prism.Token = function(type, content, alias) {
this.type = type; this.type = type;
this.content = content; this.content = content;
this.alias = alias; this.alias = alias;
@ -374,7 +374,7 @@ Token.reactify = function(o, language, parent, key) {
return o; return o;
} }
if (_.util.type(o) === "Array") { if (Prism.util.type(o) === "Array") {
return o.map((element, i) => { return o.map((element, i) => {
return Token.reactify(element, language, o, i); return Token.reactify(element, language, o, i);
}); });
@ -395,11 +395,11 @@ Token.reactify = function(o, language, parent, key) {
} }
if (o.alias) { if (o.alias) {
const aliases = _.util.type(o.alias) === "Array" ? o.alias : [o.alias]; const aliases = Prism.util.type(o.alias) === "Array" ? o.alias : [o.alias];
Array.prototype.push.apply(env.classes, aliases); Array.prototype.push.apply(env.classes, aliases);
} }
_.hooks.run("wrap", env); Prism.hooks.run("wrap", env);
env.attributes.className = env.classes.join(" "); env.attributes.className = env.classes.join(" ");
@ -1100,7 +1100,7 @@ Prism.languages.yaml = {
const PrismComponent = React.createClass({ const PrismComponent = React.createClass({
statics: { statics: {
_ Prism
}, },
getDefaultProps() { getDefaultProps() {
return { return {
@ -1123,10 +1123,10 @@ const PrismComponent = React.createClass({
} }
}); });
} }
const grammar = _.languages[this.props.language]; const grammar = Prism.languages[this.props.language];
return ( return (
<pre className={"prism language-" + this.props.language}> <pre className={"prism language-" + this.props.language}>
{Token.reactify(_.tokenize(this.props.children, grammar))} {Token.reactify(Prism.tokenize(this.props.children, grammar))}
{lines.map((line, ii) => { {lines.map((line, ii) => {
return ( return (
<div <div

0
lib/publish-gh-pages.js Normal file → Executable file
View file

3
lib/start-server.js Normal file → Executable file
View file

@ -10,10 +10,9 @@
*/ */
require("babel-register")({ require("babel-register")({
ignore: false,
babelrc: false, babelrc: false,
plugins: [require("./server/translate-plugin.js")], plugins: [require("./server/translate-plugin.js")],
presets: ["react"] presets: ["react", "latest", "stage-0"]
}); });
const program = require("commander"); const program = require("commander");

0
lib/write-translations.js Normal file → Executable file
View file

View file

@ -6,7 +6,9 @@
"examples": "./lib/copy-examples.js" "examples": "./lib/copy-examples.js"
}, },
"dependencies": { "dependencies": {
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1", "babel-register": "^6.24.1",
"babel-traverse": "^6.25.0", "babel-traverse": "^6.25.0",
"babylon": "^6.17.4", "babylon": "^6.17.4",

View file

@ -9,7 +9,44 @@
const React = require("react"); const React = require("react");
const githubButton = ( class Footer extends React.Component {
render() {
const currentYear = new Date().getFullYear();
return (
<footer className="nav-footer" id="footer">
<section className="sitemap">
<a href={this.props.config.baseUrl} className="nav-home">
<img
src={`${this.props.config.baseUrl}${this.props.config.footerIcon}`}
alt={this.props.config.title}
width="66"
height="58"
/>
</a>
<div>
<h5>Docs</h5>
<a
href={`
${this.props.config.baseUrl}docs/${this.props
.language}/getting-started.html`}
>
Getting Started
</a>
</div>
<div>
<h5>Community</h5>
<a
href={`${this.props.config.baseUrl}${this.props
.language}/users.html`}
>
User Showcase
</a>
</div>
<div>
<h5>More</h5>
<a href="https://github.com/facebookexperimental/docusaurus">
GitHub
</a>
<a <a
className="github-button" className="github-button"
href="https://github.com/facebookexperimental/docusaurus" href="https://github.com/facebookexperimental/docusaurus"
@ -21,49 +58,6 @@ const githubButton = (
> >
Star Star
</a> </a>
);
class Footer extends React.Component {
render() {
const currentYear = new Date().getFullYear();
return (
<footer className="nav-footer" id="footer">
<section className="sitemap">
<a href={this.props.config.baseUrl} className="nav-home">
<img
src={this.props.config.baseUrl + this.props.config.footerIcon}
alt={this.props.config.title}
width="66"
height="58"
/>
</a>
<div>
<h5>Docs</h5>
<a
href={
this.props.config.baseUrl +
"docs/" +
this.props.language +
"/getting-started.html"
}
>
Getting Started
</a>
</div>
<div>
<h5>Community</h5>
<a
href={
this.props.config.baseUrl + this.props.language + "/users.html"
}
>
User Showcase
</a>
</div>
<div>
<h5>More</h5>
<a href="https://github.com/facebookexperimental/docusaurus">GitHub</a>
{githubButton}
</div> </div>
</section> </section>
@ -73,7 +67,7 @@ class Footer extends React.Component {
className="fbOpenSource" className="fbOpenSource"
> >
<img <img
src={this.props.config.baseUrl + "img/oss_logo.png"} src={`${this.props.config.baseUrl}img/oss_logo.png`}
alt="Facebook Open Source" alt="Facebook Open Source"
width="170" width="170"
height="45" height="45"

View file

@ -1,9 +1,9 @@
{ {
"scripts": { "scripts": {
"start": "chmod +x ../lib/start-server.js && ../lib/start-server.js", "start": "../lib/start-server.js",
"build": "chmod +x ../lib/build-files.js && ../lib/build-files.js", "build": "../lib/build-files.js",
"publish-gh-pages": "chmod +x ../lib/publish-gh-pages.js && ../lib/publish-gh-pages.js", "publish-gh-pages": "../lib/publish-gh-pages.js",
"examples": "chmod +x ../lib/copy-examples.js && ../lib/copy-examples.js", "examples": "../lib/copy-examples.js",
"write-translations": "chmod +x ../lib/write-translations.js && ../lib/write-translations.js" "write-translations": "../lib/write-translations.js"
} }
} }

View file

@ -16,6 +16,10 @@ const GridBlock = CompLibrary.GridBlock;
const siteConfig = require(process.cwd() + "/siteConfig.js"); const siteConfig = require(process.cwd() + "/siteConfig.js");
class Help extends React.Component { class Help extends React.Component {
static defaultProps = {
language: "en"
};
render() { render() {
const supportLinks = [ const supportLinks = [
{ {
@ -24,11 +28,13 @@ class Help extends React.Component {
title: "Browse Docs" title: "Browse Docs"
}, },
{ {
content: "Submit issues and pull requests for any new features you may want to see or bugs you've found on [GitHub](https://github.com/facebookexperimental/docusaurus).", content:
"Submit issues and pull requests for any new features you may want to see or bugs you've found on [GitHub](https://github.com/facebookexperimental/docusaurus).",
title: "Join the community" title: "Join the community"
}, },
{ {
content: "Find out what's new with this project by checking back on the site.", content:
"Find out what's new with this project by checking back on the site.",
title: "Stay up to date" title: "Stay up to date"
} }
]; ];
@ -49,8 +55,4 @@ class Help extends React.Component {
} }
} }
Help.defaultProps = {
language: "en"
};
module.exports = Help; module.exports = Help;

View file

@ -17,6 +17,10 @@ const GridBlock = CompLibrary.GridBlock;
const siteConfig = require(process.cwd() + "/siteConfig.js"); const siteConfig = require(process.cwd() + "/siteConfig.js");
class Button extends React.Component { class Button extends React.Component {
static defaultProps = {
target: "_self"
};
render() { render() {
return ( return (
<div className="pluginWrapper buttonWrapper"> <div className="pluginWrapper buttonWrapper">
@ -28,10 +32,6 @@ class Button extends React.Component {
} }
} }
Button.defaultProps = {
target: "_self"
};
class HomeSplash extends React.Component { class HomeSplash extends React.Component {
render() { render() {
return ( return (
@ -39,7 +39,7 @@ class HomeSplash extends React.Component {
<div className="homeSplashFade"> <div className="homeSplashFade">
<div className="wrapper homeWrapper"> <div className="wrapper homeWrapper">
<div className="projectLogo"> <div className="projectLogo">
<img src={siteConfig.baseUrl + "img/docusaurus.svg"} /> <img src={`${siteConfig.baseUrl}img/docusaurus.svg`} />
</div> </div>
<div className="inner"> <div className="inner">
<h2 className="projectTitle"> <h2 className="projectTitle">
@ -52,12 +52,10 @@ class HomeSplash extends React.Component {
<div className="promoRow"> <div className="promoRow">
<div className="pluginRowBlock"> <div className="pluginRowBlock">
<Button <Button
href={ href={`
siteConfig.baseUrl + ${siteConfig.baseUrl}docs/${this.props
"docs/" + .language}/getting-started.html
this.props.language + `}
"/getting-started.html"
}
> >
Get Started Get Started
</Button> </Button>
@ -98,21 +96,21 @@ class Index extends React.Component {
{ {
content: content:
"Write all of your documentation and blog posts in Markdown and have it built into a website you can publish", "Write all of your documentation and blog posts in Markdown and have it built into a website you can publish",
image: siteConfig.baseUrl + "img/markdown.png", image: `${siteConfig.baseUrl}img/markdown.png`,
imageAlign: "top", imageAlign: "top",
title: "Markdown Documentation" title: "Markdown Documentation"
}, },
{ {
content: content:
"Write the content of your main pages as React components that automatically share a header and footer", "Write the content of your main pages as React components that automatically share a header and footer",
image: siteConfig.baseUrl + "img/react.svg", image: `${siteConfig.baseUrl}img/react.svg`,
imageAlign: "top", imageAlign: "top",
title: "React Main Pages" title: "React Main Pages"
}, },
{ {
content: content:
"Translate your docs and your website using Crowdin integration", "Translate your docs and your website using Crowdin integration",
image: siteConfig.baseUrl + "img/translation.svg", image: `${siteConfig.baseUrl}img/translation.svg`,
imageAlign: "top", imageAlign: "top",
title: "Translations" title: "Translations"
} }
@ -127,14 +125,14 @@ class Index extends React.Component {
{ {
content: content:
"Support users of all versions by easily providing documentation for each version of your program", "Support users of all versions by easily providing documentation for each version of your program",
image: siteConfig.baseUrl + "img/docusaurus.svg", image: `${siteConfig.baseUrl}img/docusaurus.svg`,
imageAlign: "top", imageAlign: "top",
title: "Versioning" title: "Versioning"
}, },
{ {
content: content:
"Provide search for your documentation using Algolia DocSearch integration", "Provide search for your documentation using Algolia DocSearch integration",
image: siteConfig.baseUrl + "img/docusaurus.svg", image: `${siteConfig.baseUrl}img/docusaurus.svg`,
imageAlign: "top", imageAlign: "top",
title: "Document Search" title: "Document Search"
} }
@ -149,7 +147,7 @@ class Index extends React.Component {
content: content:
"The provided site template lets you get a website for your project up and running quickly without having having to worry about all the site design. Provided example files help you configure your site.", "The provided site template lets you get a website for your project up and running quickly without having having to worry about all the site design. Provided example files help you configure your site.",
imageAlign: "right", imageAlign: "right",
image: siteConfig.baseUrl + "img/docusaurus.svg", image: `${siteConfig.baseUrl}img/docusaurus.svg`,
title: "Quick Setup" title: "Quick Setup"
} }
]} ]}
@ -163,7 +161,7 @@ class Index extends React.Component {
content: content:
"Use a local server to see how file changes affect your website without having to reload the server. Publish your site to GitHub pages manually using a script or with continuous integration like CircleCI.", "Use a local server to see how file changes affect your website without having to reload the server. Publish your site to GitHub pages manually using a script or with continuous integration like CircleCI.",
imageAlign: "left", imageAlign: "left",
image: siteConfig.baseUrl + "img/docusaurus.svg", image: `${siteConfig.baseUrl}img/docusaurus.svg`,
title: "Development and Deployment" title: "Development and Deployment"
} }
]} ]}
@ -177,7 +175,7 @@ class Index extends React.Component {
content: content:
"Docusaurus currently provides support to help your website use [translations](/docs/en/translation.html), [search](/docs/en/search.html), and [versioning](/docs/en/versioning.html), along with some other special [documentation markdown features](/docs/en/doc-markdown.html). If you have ideas for useful features, feel free to contribute on [GitHub](https://github.com/facebookexperimental/docusaurus)!", "Docusaurus currently provides support to help your website use [translations](/docs/en/translation.html), [search](/docs/en/search.html), and [versioning](/docs/en/versioning.html), along with some other special [documentation markdown features](/docs/en/doc-markdown.html). If you have ideas for useful features, feel free to contribute on [GitHub](https://github.com/facebookexperimental/docusaurus)!",
imageAlign: "right", imageAlign: "right",
image: siteConfig.baseUrl + "img/docusaurus.svg", image: `${siteConfig.baseUrl}img/docusaurus.svg`,
title: "Website Features" title: "Website Features"
} }
]} ]}
@ -196,10 +194,7 @@ class Index extends React.Component {
<div className="more-users"> <div className="more-users">
<a <a
className="button" className="button"
href={ href={`${siteConfig.baseUrl}${this.props.language}/users.html`}
siteConfig.baseUrl + this.props.language + "/" + "users.html"
}
target="_self"
> >
All Docusaurus Users All Docusaurus Users
</a> </a>