mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 19:46:57 +02:00
Merge branch 'master' into update-examples
This commit is contained in:
commit
7a79690228
16 changed files with 112 additions and 22 deletions
17
README.md
17
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
id: doc1
|
||||
title: Docusaurus
|
||||
sidebar_title: Docusaurus Guide
|
||||
layout: docs
|
||||
category: Docusaurus
|
||||
permalink: docs/en/doc1.html
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
require("babel-register")({
|
||||
ignore: false,
|
||||
babelrc: false,
|
||||
plugins: [require("./server/translate-plugin.js")],
|
||||
presets: ["react"]
|
||||
});
|
||||
|
|
|
@ -40,6 +40,14 @@ class BlogPostLayout extends React.Component {
|
|||
config={this.props.config}
|
||||
/>
|
||||
</div>
|
||||
<div className="blog-recent">
|
||||
<a
|
||||
className="button"
|
||||
href={this.props.config.baseUrl + "blog"}
|
||||
>
|
||||
Recent Posts
|
||||
</a>
|
||||
</div>
|
||||
</Container>
|
||||
</div>
|
||||
</Site>
|
||||
|
|
|
@ -113,9 +113,10 @@ class HeaderNav extends React.Component {
|
|||
<header>
|
||||
<a href={this.props.baseUrl}>
|
||||
<img src={this.props.baseUrl + siteConfig.headerIcon} />
|
||||
<h2>
|
||||
{this.props.title}
|
||||
</h2>
|
||||
{!this.props.config.disableHeaderTitle &&
|
||||
<h2>
|
||||
{this.props.title}
|
||||
</h2>}
|
||||
</a>
|
||||
{this.renderResponsiveNav()}
|
||||
</header>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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 <number>", "Specify port number").parse(process.argv);
|
||||
|
||||
const port = program.port || 3000;
|
||||
|
||||
const server = require("./server/server.js");
|
||||
server(port);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue