Merge branch 'master' into update-examples

This commit is contained in:
Frank Li 2017-07-18 12:12:44 -07:00
commit 7a79690228
16 changed files with 112 additions and 22 deletions

View file

@ -6,6 +6,17 @@
In your project repo, all of your documentation files should be placed inside a `docs` folder. Any blog posts should be inside a `blog` folder. Create a `website` folder inside which you will install and run docusaurus. In your project repo, all of your documentation files should be placed inside a `docs` folder. Any blog posts should be inside a `blog` folder. Create a `website` folder inside which you will install and run docusaurus.
Example project structure:
```
project-repo/
blog/
2017-05-06-blog-post.md
docs/
en/
doc1.md
website/
```
### Installation ### Installation
Inside of your `website` folder, create a `package.json` file with the following scripts for Docusaurus: Inside of your `website` folder, create a `package.json` file with the following scripts for Docusaurus:
@ -129,8 +140,10 @@ yarn run start
``` ```
This will start a server hosting your website locally at `localhost:3000`. This server will ignore any occurences `siteConfig.baseUrl` in URLs, e.g. `localhost:3000/your-site/index.html` will be the same as `localhost:3000/index.html`. Any changes to configured files will be reflected by refreshing the page, i.e. the server does not need to be restarted to show changes. You may also specify a different port to start your server on as a command line argument, e.g. `npm run start 9000`. This will start a server hosting your website locally at `localhost:3000`. This server will ignore any occurences `siteConfig.baseUrl` in URLs, e.g. `localhost:3000/your-site/index.html` will be the same as `localhost:3000/index.html`. Any changes to configured files will be reflected by refreshing the page, i.e. the server does not need to be restarted to show changes. You may also specify a different port to start your server on by using a `--port` flag:
```
npm run start -- --port 9000
```
### Build Static Pages ### Build Static Pages

View file

@ -13,6 +13,17 @@ next: translation
In your project repo, all of your documentation files should be placed inside a `docs` folder. Any blog posts should be inside a `blog` folder. Create a `website` folder inside which you will install and run docusaurus. In your project repo, all of your documentation files should be placed inside a `docs` folder. Any blog posts should be inside a `blog` folder. Create a `website` folder inside which you will install and run docusaurus.
Example project structure:
```
project-repo/
blog/
2017-05-06-blog-post.md
docs/
en/
doc1.md
website/
```
### Installation ### Installation
Inside of your `website` folder, create a `package.json` file with the following scripts for Docusaurus: Inside of your `website` folder, create a `package.json` file with the following scripts for Docusaurus:
@ -136,8 +147,10 @@ yarn run start
``` ```
This will start a server hosting your website locally at `localhost:3000`. This server will ignore any occurences `siteConfig.baseUrl` in URLs, e.g. `localhost:3000/your-site/index.html` will be the same as `localhost:3000/index.html`. Any changes to configured files will be reflected by refreshing the page, i.e. the server does not need to be restarted to show changes. You may also specify a different port to start your server on as a command line argument, e.g. `npm run start 9000`. This will start a server hosting your website locally at `localhost:3000`. This server will ignore any occurences `siteConfig.baseUrl` in URLs, e.g. `localhost:3000/your-site/index.html` will be the same as `localhost:3000/index.html`. Any changes to configured files will be reflected by refreshing the page, i.e. the server does not need to be restarted to show changes. You may also specify a different port to start your server on by using a `--port` flag:
```
npm run start -- --port 9000
```
### Build Static Pages ### Build Static Pages

View file

@ -1,6 +1,7 @@
--- ---
id: doc1 id: doc1
title: Docusaurus title: Docusaurus
sidebar_title: Docusaurus Guide
layout: docs layout: docs
category: Docusaurus category: Docusaurus
permalink: docs/en/doc1.html permalink: docs/en/doc1.html

View file

@ -48,6 +48,7 @@ const siteConfig = {
], ],
/* path to images for header/footer */ /* path to images for header/footer */
headerIcon: "img/docusaurus.svg", headerIcon: "img/docusaurus.svg",
disableHeaderTitle: false /* disable title text in header (only show headerIcon) */,
footerIcon: "img/docusaurus.svg", footerIcon: "img/docusaurus.svg",
favicon: "img/favicon.png", favicon: "img/favicon.png",
/* default link for docsSidebar */ /* default link for docsSidebar */

View file

@ -11,6 +11,7 @@
require("babel-register")({ require("babel-register")({
ignore: false, ignore: false,
babelrc: false,
plugins: [require("./server/translate-plugin.js")], plugins: [require("./server/translate-plugin.js")],
presets: ["react"] presets: ["react"]
}); });

View file

@ -40,6 +40,14 @@ class BlogPostLayout extends React.Component {
config={this.props.config} config={this.props.config}
/> />
</div> </div>
<div className="blog-recent">
<a
className="button"
href={this.props.config.baseUrl + "blog"}
>
Recent Posts
</a>
</div>
</Container> </Container>
</div> </div>
</Site> </Site>

View file

@ -113,9 +113,10 @@ class HeaderNav extends React.Component {
<header> <header>
<a href={this.props.baseUrl}> <a href={this.props.baseUrl}>
<img src={this.props.baseUrl + siteConfig.headerIcon} /> <img src={this.props.baseUrl + siteConfig.headerIcon} />
<h2> {!this.props.config.disableHeaderTitle &&
{this.props.title} <h2>
</h2> {this.props.title}
</h2>}
</a> </a>
{this.renderResponsiveNav()} {this.renderResponsiveNav()}
</header> </header>

View file

@ -69,12 +69,19 @@ class SideNav extends React.Component {
return categoryString; return categoryString;
} }
getLocalizedString(metadata) { getLocalizedString(metadata) {
let localizedString = translation[this.props.language] let localizedString;
? translation[this.props.language]["localized-strings"][ const i18n = translation[this.props.language];
metadata.localized_id const sbTitle = metadata.sidebar_title;
] || metadata.title
: metadata.title; if (sbTitle) {
localizedString = i18n
? i18n["localized-strings"][sbTitle] || sbTitle
: sbTitle;
} else {
localizedString = i18n
? i18n["localized-strings"][metadata.localized_id] || metadata.title
: metadata.title;
}
return localizedString; return localizedString;
} }
getLink(metadata) { getLink(metadata) {

View file

@ -106,6 +106,9 @@ function execute() {
if (extension === ".md" || extension === ".markdown") { if (extension === ".md" || extension === ".markdown") {
const result = readMetadata.processMetadata(file); const result = readMetadata.processMetadata(file);
if (!result) {
return;
}
const metadata = result.metadata; const metadata = result.metadata;
let rawContent = result.rawContent; let rawContent = result.rawContent;

View file

@ -60,6 +60,9 @@ function extractMetadata(content) {
function processMetadata(file) { function processMetadata(file) {
const result = extractMetadata(fs.readFileSync(file, "utf8")); const result = extractMetadata(fs.readFileSync(file, "utf8"));
if (!result.metadata || !result.rawContent) {
return null;
}
const regexSubFolder = /docs\/(.*)\/.*/; const regexSubFolder = /docs\/(.*)\/.*/;
@ -120,6 +123,9 @@ function generateDocsMetadata() {
if (extension === ".md" || extension === ".markdown") { if (extension === ".md" || extension === ".markdown") {
const res = processMetadata(file); const res = processMetadata(file);
if (!res) {
return;
}
const metadata = res.metadata; const metadata = res.metadata;
metadatas.push(metadata); metadatas.push(metadata);
} }

View file

@ -19,7 +19,7 @@ module.exports = function translatePlugin(babel) {
return; return;
} }
/* assume translate element only has one child which is the text */ /* assume translate element only has one child which is the text */
const text = path.node.children[0].value.trim(); const text = path.node.children[0].value.trim().replace(/\s+/g, " ");
let description = "no description given"; let description = "no description given";
const attributes = path.node.openingElement.attributes; const attributes = path.node.openingElement.attributes;
for (let i = 0; i < attributes.length; i++) { for (let i = 0; i < attributes.length; i++) {

View file

@ -11,12 +11,25 @@ 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"), "\\");
}
function setLanguage(lang) { function setLanguage(lang) {
language = lang; language = lang;
} }
function translate(str) { function translate(str) {
return translation[language]["pages-strings"][str]; return parseEscapeSequences(translation[language]["pages-strings"][str]);
} }
module.exports = { module.exports = {

View file

@ -11,14 +11,16 @@
require("babel-register")({ require("babel-register")({
ignore: false, ignore: false,
babelrc: false,
plugins: [require("./server/translate-plugin.js")], plugins: [require("./server/translate-plugin.js")],
presets: ["react"] presets: ["react"]
}); });
let port = 3000; const program = require("commander");
if (process.argv.length > 2) {
port = process.argv[2]; program.option("--port <number>", "Specify port number").parse(process.argv);
}
const port = program.port || 3000;
const server = require("./server/server.js"); const server = require("./server/server.js");
server(port); server(port);

View file

@ -1187,6 +1187,9 @@ ul#languages li {
color: #fff; color: #fff;
} }
} }
.algolia-autocomplete {
bottom: 10px;
}
.docs-prevnext { .docs-prevnext {
margin: 20px 0; margin: 20px 0;
@ -1554,6 +1557,17 @@ table tr th {
overflow: hidden; overflow: hidden;
width: 70px; width: 70px;
} }
.blog-recent {
margin: 20px 0;
}
.blog-recent > a {
float: left;
}
@media only screen and (min-device-width: 360px) and (max-device-width: 736px) {
.blog-recent {
height: 40px;
}
}
.header-link { .header-link {
position: absolute; position: absolute;

View file

@ -47,6 +47,11 @@ function execute() {
translations["localized-strings"][metadata.id] = metadata.title; translations["localized-strings"][metadata.id] = metadata.title;
translations["localized-strings"][metadata.category] = metadata.category; translations["localized-strings"][metadata.category] = metadata.category;
if (metadata.sidebar_title) {
translations["localized-strings"][metadata.sidebar_title] =
metadata.sidebar_title;
}
} }
}); });
/* look through header links for text to translate */ /* look through header links for text to translate */
@ -73,7 +78,9 @@ function execute() {
path.node.type === "JSXElement" && path.node.type === "JSXElement" &&
path.node.openingElement.name.name === "translate" path.node.openingElement.name.name === "translate"
) { ) {
const text = path.node.children[0].value.trim(); const text = path.node.children[0].value
.trim()
.replace(/\s+/g, " ");
let description = "no description given"; let description = "no description given";
const attributes = path.node.openingElement.attributes; const attributes = path.node.openingElement.attributes;
for (let i = 0; i < attributes.length; i++) { for (let i = 0; i < attributes.length; i++) {
@ -87,7 +94,6 @@ function execute() {
}); });
} }
}); });
writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations)); writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations));
} }

View file

@ -11,6 +11,7 @@
"babel-traverse": "^6.25.0", "babel-traverse": "^6.25.0",
"babylon": "^6.17.4", "babylon": "^6.17.4",
"classnames": "^2.2.5", "classnames": "^2.2.5",
"commander": "^2.11.0",
"express": "^4.15.3", "express": "^4.15.3",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"glob": "^7.1.2", "glob": "^7.1.2",
@ -20,7 +21,7 @@
"shelljs": "^0.7.8" "shelljs": "^0.7.8"
}, },
"name": "docusaurus", "name": "docusaurus",
"version": "1.0.0-alpha.14", "version": "1.0.0-alpha.17",
"bin": { "bin": {
"docusaurus-start": "./lib/start-server.js", "docusaurus-start": "./lib/start-server.js",
"docusaurus-build": "./lib/build-files.js", "docusaurus-build": "./lib/build-files.js",