Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow modifying docs url prefix #914

Merged
merged 26 commits into from Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
caa4c0c
Allow other routes than /docs in the URL
Aug 24, 2018
6af23e1
Make "docsRoute" field optional
Aug 24, 2018
c633d27
Isolate docsRoute login in getDocsRoute function
Sep 10, 2018
34babf1
Rename docsRoute to docsUrl
Sep 29, 2018
11e1cfa
Run prettier
Sep 29, 2018
7ba71ee
Remove old folders
Oct 8, 2018
f519351
Merge branch 'master' into master
Oct 8, 2018
34e84a0
Merge remote-tracking branch 'dom/master' into feature/customized-pat…
wgao19 Nov 8, 2018
9423dd6
fix: Restore docusaurus reference link
wgao19 Nov 8, 2018
6767a57
fix: Add `docsUrl` param fallback. Refactor multiple function calls
wgao19 Nov 8, 2018
c186224
Merge pull request #1 from wgao19/feature/customized-pathname-prefix
Nov 9, 2018
3c4cc5b
Fix linting errors
Nov 9, 2018
c59394e
Update description for docsUrl field
Nov 9, 2018
939feaf
Reduce redundant calls to getDocsUrl
Nov 9, 2018
596ab0e
Replace a missed use case for `docsUrl` instead of the function call
wgao19 Nov 11, 2018
720e948
Move `getDocsUrl` out from `server/routing.js` to `server/utils.js`
wgao19 Nov 11, 2018
30586b8
WiP: Align leading slashes and fix routing around `docsUrl`
wgao19 Nov 11, 2018
05e7dd8
Make leading slashes canonical cross routing and generated links
wgao19 Nov 12, 2018
1f68f9b
Alternative fallback for `docsUrl`
wgao19 Nov 17, 2018
f52e695
Merge pull request #2 from wgao19/feature/customized-pathname-prefix
Nov 23, 2018
23c8b10
rework/ fix implementation
endiliey Nov 24, 2018
f41336d
cleanup
endiliey Nov 28, 2018
bba3852
Merge remote-tracking branch 'upstream/master'
endiliey Nov 28, 2018
bc73010
refactor and add docs for config props
endiliey Nov 28, 2018
eb33fe6
fix typo
endiliey Nov 28, 2018
59b95d7
fix broken url
endiliey Nov 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/api-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ title: Pages and Styles

Docusaurus provides support for writing pages as React components inside the `website/pages` directory which will share the same header, footer, and styles as the rest of the site.

## Provided Props

Docusaurus provides your [siteConfig.js](api-site-config.md) as a `config` props. Hence, you can access `baseUrl` or `title` through this props.

Example

```js
const React = require('react');

class MyPage extends React.Component {
render() {
const siteConfig = this.props.config;
return <div>{siteConfig.title}</div>;
}
}

module.exports = MyPage;
```

## URLs for Pages

Any `.js` files in `website/pages` will be rendered to static HTML using the path of the file after `pages`. Files in `website/pages/en` will also get copied out into `pages` and will OVERRIDE any files of the same name in `pages`. For example, the page for the `website/pages/en/help.js` file will be found at the URL `${baseUrl}en/help.js` as well as the URL `${baseUrl}help.js`, where `${baseUrl}` is the `baseUrl` field set in your [siteConfig.js file](api-site-config.md).
Expand All @@ -31,7 +50,7 @@ module.exports = MyPage;

## Description for Pages

By default, the description your page is `tagline` set in [`siteConfig.js`](api-site-config.md). If you want to set a specific description for your custom pages, add a `description` class property on your exported React component.
By default, the description your page is `tagline` set in [`siteConfig.js`](api-site-config.md). If you want to set a specific description for your custom pages, add a `description` class property on your exported React component.

Example:

Expand Down Expand Up @@ -138,7 +157,7 @@ A React component to organize text and images.
className="myCustomClass"
contents={[
{
title: `[Learn](${siteConfig.baseUrl}docs/tutorial.html)`,
title: `[Learn](${siteConfig.baseUrl}${siteConfig.docsUrl}/tutorial.html)`,
content: 'Learn how to use this project',
image: siteConfig.baseUrl + 'img/learn.png',
imageAlt: 'Learn how to use this project',
Expand Down
13 changes: 9 additions & 4 deletions docs/api-site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ headerLinks: [
],
```

#### `noIndex` [boolean]

Boolean. If true, Docusaurus will politely ask crawlers and search engines to avoid indexing your site. This is done with a header tag and so only applies to docs and pages. Will not attempt to hide static resources. This is a best effort request. Malicious crawlers can and will still index your site.

#### `organizationName` [string]

GitHub username of the organization or user hosting this project. This is used by the publishing script to determine where your GitHub pages website will be hosted.
Expand Down Expand Up @@ -130,6 +126,11 @@ customDocsPath: 'website-docs';

The default version for the site to be shown. If this is not set, the latest version will be shown.

#### `docsUrl` [string]

The base url for all docs file. Set this field to `''` to remove the `docs` prefix of the documentation URL.
If unset, it is defaulted to `docs`.

#### `disableHeaderTitle` [boolean]

An option to disable showing the title in the header next to the header icon. Exclude this field to keep the header as normal, otherwise set to `true`.
Expand Down Expand Up @@ -246,6 +247,10 @@ Path to your web app manifest (e.g., `manifest.json`). This will add a `<link>`

An array of plugins to be loaded by Remarkable, the markdown parser and renderer used by Docusaurus. The plugin will receive a reference to the Remarkable instance, allowing custom parsing and rendering rules to be defined.

#### `noIndex` [boolean]

Boolean. If true, Docusaurus will politely ask crawlers and search engines to avoid indexing your site. This is done with a header tag and so only applies to docs and pages. Will not attempt to hide static resources. This is a best effort request. Malicious crawlers can and will still index your site.

#### `ogImage` [string]

Local path to an Open Graph image (e.g., `img/myImage.png`). This image will show up when your site is shared on Facebook and other websites/apps where the Open Graph protocol is supported.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ You can also include an optional description attribute to give more context to a
<p>
```

> The `<translate>` tag generally works well on pure strings. If you have a string like "Docusaurus currently provides support to help your website use [translations](${siteConfig.baseUrl}docs/${this.props.language}/translation.html)", wrapping the `<translation>` tag around that entire string will cause issues because of the markdown linking, etc. Your options are to not translate those strings, or spread a bunch of `<translate>` tags amongst the pure substrings of that string.
> The `<translate>` tag generally works well on pure strings. If you have a string like "Docusaurus currently provides support to help your website use [translations](${siteConfig.baseUrl}${siteConfig.docsUrl}/${this.props.language}/translation.html)", wrapping the `<translation>` tag around that entire string will cause issues because of the markdown linking, etc. Your options are to not translate those strings, or spread a bunch of `<translate>` tags amongst the pure substrings of that string.

## Gathering Strings to Translate

Expand Down
5 changes: 4 additions & 1 deletion v1/examples/basics/core/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const React = require('react');
class Footer extends React.Component {
docUrl(doc, language) {
const baseUrl = this.props.config.baseUrl;
return `${baseUrl}docs/${language ? `${language}/` : ''}${doc}`;
const docsUrl = this.props.config.docsUrl;
endiliey marked this conversation as resolved.
Show resolved Hide resolved
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
const langPart = `${language ? `${language}/` : ''}`;
return `${baseUrl}${docsPart}${langPart}${doc}`;
}

pageUrl(doc, language) {
Expand Down
78 changes: 37 additions & 41 deletions v1/examples/basics/pages/en/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,43 @@ const CompLibrary = require('../../core/CompLibrary.js');
const Container = CompLibrary.Container;
const GridBlock = CompLibrary.GridBlock;

const siteConfig = require(`${process.cwd()}/siteConfig.js`);

function docUrl(doc, language) {
return `${siteConfig.baseUrl}docs/${language ? `${language}/` : ''}${doc}`;
}

class Help extends React.Component {
render() {
const language = this.props.language || '';
const supportLinks = [
{
content: `Learn more using the [documentation on this site.](${docUrl(
'doc1.html',
language,
)})`,
title: 'Browse Docs',
},
{
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',
},
];

return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer documentContainer postContainer">
<div className="post">
<header className="postHeader">
<h1>Need help?</h1>
</header>
<p>This project is maintained by a dedicated group of people.</p>
<GridBlock contents={supportLinks} layout="threeColumn" />
</div>
</Container>
</div>
);
}
function Help(props) {
const {config: siteConfig, language = ''} = props;
const {baseUrl, docsUrl} = siteConfig;
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
const langPart = `${language ? `${language}/` : ''}`;
const docUrl = doc => `${baseUrl}${docsPart}${langPart}${doc}`;

const supportLinks = [
{
content: `Learn more using the [documentation on this site.](${docUrl(
'doc1.html',
)})`,
title: 'Browse Docs',
},
{
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',
},
];

return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer documentContainer postContainer">
<div className="post">
<header className="postHeader">
<h1>Need help?</h1>
</header>
<p>This project is maintained by a dedicated group of people.</p>
<GridBlock contents={supportLinks} layout="threeColumn" />
</div>
</Container>
</div>
);
}

module.exports = Help;
Loading