diff --git a/README.md b/README.md index 1fdb8b79da..28845025e2 100644 --- a/README.md +++ b/README.md @@ -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. +Example project structure: +``` +project-repo/ + blog/ + 2017-05-06-blog-post.md + docs/ + en/ + doc1.md + website/ +``` + ### Installation 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 diff --git a/docs/en/getting-started.md b/docs/en/getting-started.md index 0e0cfae02f..484cf77f91 100644 --- a/docs/en/getting-started.md +++ b/docs/en/getting-started.md @@ -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. +Example project structure: +``` +project-repo/ + blog/ + 2017-05-06-blog-post.md + docs/ + en/ + doc1.md + website/ +``` + ### Installation 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 diff --git a/examples/docs-examples-from-docusaurus/en/doc1.md b/examples/docs-examples-from-docusaurus/en/doc1.md index 8f2fd96029..9b17145a73 100644 --- a/examples/docs-examples-from-docusaurus/en/doc1.md +++ b/examples/docs-examples-from-docusaurus/en/doc1.md @@ -1,6 +1,7 @@ --- id: doc1 title: Docusaurus +sidebar_title: Docusaurus Guide layout: docs category: Docusaurus permalink: docs/en/doc1.html diff --git a/examples/siteConfig.js b/examples/siteConfig.js index f5dcc7f1cf..36d5a7b107 100644 --- a/examples/siteConfig.js +++ b/examples/siteConfig.js @@ -48,6 +48,7 @@ const siteConfig = { ], /* path to images for header/footer */ headerIcon: "img/docusaurus.svg", + disableHeaderTitle: false /* disable title text in header (only show headerIcon) */, footerIcon: "img/docusaurus.svg", favicon: "img/favicon.png", /* default link for docsSidebar */ diff --git a/lib/build-files.js b/lib/build-files.js index bcc149e8b6..5d8c5e47fe 100644 --- a/lib/build-files.js +++ b/lib/build-files.js @@ -11,6 +11,7 @@ require("babel-register")({ ignore: false, + babelrc: false, plugins: [require("./server/translate-plugin.js")], presets: ["react"] }); diff --git a/lib/core/BlogPostLayout.js b/lib/core/BlogPostLayout.js index fe713e4030..6053eba35c 100644 --- a/lib/core/BlogPostLayout.js +++ b/lib/core/BlogPostLayout.js @@ -40,6 +40,14 @@ class BlogPostLayout extends React.Component { config={this.props.config} /> +
+ + Recent Posts + +
diff --git a/lib/core/nav/HeaderNav.js b/lib/core/nav/HeaderNav.js index ba86bbf263..e01ae1ee40 100644 --- a/lib/core/nav/HeaderNav.js +++ b/lib/core/nav/HeaderNav.js @@ -113,9 +113,10 @@ class HeaderNav extends React.Component {
-

- {this.props.title} -

+ {!this.props.config.disableHeaderTitle && +

+ {this.props.title} +

}
{this.renderResponsiveNav()}
diff --git a/lib/core/nav/SideNav.js b/lib/core/nav/SideNav.js index 2ea8576642..3ab9b04ec3 100644 --- a/lib/core/nav/SideNav.js +++ b/lib/core/nav/SideNav.js @@ -69,12 +69,19 @@ class SideNav extends React.Component { return categoryString; } getLocalizedString(metadata) { - let localizedString = translation[this.props.language] - ? translation[this.props.language]["localized-strings"][ - metadata.localized_id - ] || metadata.title - : metadata.title; - + let localizedString; + const i18n = translation[this.props.language]; + const sbTitle = metadata.sidebar_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; } getLink(metadata) { diff --git a/lib/server/generate.js b/lib/server/generate.js index 426bf7f323..8aec19a45c 100644 --- a/lib/server/generate.js +++ b/lib/server/generate.js @@ -106,6 +106,9 @@ function execute() { if (extension === ".md" || extension === ".markdown") { const result = readMetadata.processMetadata(file); + if (!result) { + return; + } const metadata = result.metadata; let rawContent = result.rawContent; diff --git a/lib/server/readMetadata.js b/lib/server/readMetadata.js index c07465727f..521f267624 100644 --- a/lib/server/readMetadata.js +++ b/lib/server/readMetadata.js @@ -60,6 +60,9 @@ function extractMetadata(content) { function processMetadata(file) { const result = extractMetadata(fs.readFileSync(file, "utf8")); + if (!result.metadata || !result.rawContent) { + return null; + } const regexSubFolder = /docs\/(.*)\/.*/; @@ -120,6 +123,9 @@ function generateDocsMetadata() { if (extension === ".md" || extension === ".markdown") { const res = processMetadata(file); + if (!res) { + return; + } const metadata = res.metadata; metadatas.push(metadata); } diff --git a/lib/server/translate-plugin.js b/lib/server/translate-plugin.js index cfadac8ca1..21bbbbf921 100644 --- a/lib/server/translate-plugin.js +++ b/lib/server/translate-plugin.js @@ -19,7 +19,7 @@ module.exports = function translatePlugin(babel) { return; } /* 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"; const attributes = path.node.openingElement.attributes; for (let i = 0; i < attributes.length; i++) { diff --git a/lib/server/translate.js b/lib/server/translate.js index 1ec08f3581..ac40dfc355 100644 --- a/lib/server/translate.js +++ b/lib/server/translate.js @@ -11,12 +11,25 @@ const translation = require("./translation.js"); 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) { language = lang; } function translate(str) { - return translation[language]["pages-strings"][str]; + return parseEscapeSequences(translation[language]["pages-strings"][str]); } module.exports = { diff --git a/lib/start-server.js b/lib/start-server.js index 66a17aa2e6..cc0b5a5970 100644 --- a/lib/start-server.js +++ b/lib/start-server.js @@ -11,14 +11,16 @@ require("babel-register")({ ignore: false, + babelrc: false, plugins: [require("./server/translate-plugin.js")], presets: ["react"] }); -let port = 3000; -if (process.argv.length > 2) { - port = process.argv[2]; -} +const program = require("commander"); + +program.option("--port ", "Specify port number").parse(process.argv); + +const port = program.port || 3000; const server = require("./server/server.js"); server(port); diff --git a/lib/static/css/main.css b/lib/static/css/main.css index 3fbe2e6a23..ac3b3e4c19 100644 --- a/lib/static/css/main.css +++ b/lib/static/css/main.css @@ -1187,6 +1187,9 @@ ul#languages li { color: #fff; } } +.algolia-autocomplete { + bottom: 10px; +} .docs-prevnext { margin: 20px 0; @@ -1554,6 +1557,17 @@ table tr th { overflow: hidden; 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 { position: absolute; diff --git a/lib/write-translations.js b/lib/write-translations.js index 7dff6ff650..4bd7e711a1 100644 --- a/lib/write-translations.js +++ b/lib/write-translations.js @@ -47,6 +47,11 @@ function execute() { translations["localized-strings"][metadata.id] = metadata.title; 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 */ @@ -73,7 +78,9 @@ function execute() { path.node.type === "JSXElement" && 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"; const attributes = path.node.openingElement.attributes; for (let i = 0; i < attributes.length; i++) { @@ -87,7 +94,6 @@ function execute() { }); } }); - writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations)); } diff --git a/package.json b/package.json index 90f4a8686d..4f380f1df6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "babel-traverse": "^6.25.0", "babylon": "^6.17.4", "classnames": "^2.2.5", + "commander": "^2.11.0", "express": "^4.15.3", "fs-extra": "^3.0.1", "glob": "^7.1.2", @@ -20,7 +21,7 @@ "shelljs": "^0.7.8" }, "name": "docusaurus", - "version": "1.0.0-alpha.14", + "version": "1.0.0-alpha.17", "bin": { "docusaurus-start": "./lib/start-server.js", "docusaurus-build": "./lib/build-files.js",