Skip to content

Commit

Permalink
Resolving merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansal3096 committed Aug 29, 2018
2 parents 083d2aa + 5542ace commit 299c504
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<p align="center">Docusaurus</p>
<a href="https://docusaurus.io"><img src="/website/static/img/slash-introducing.png" alt="Docusaurus"></a>
<a href="https://docusaurus.io"><img src="/website/static/img/slash-introducing.svg" alt="Docusaurus"></a>
</h1>

<p align="center">
Expand Down
12 changes: 10 additions & 2 deletions docs/guides-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ If you want to add additional custom translation strings, or override any of the
```json
{
"localized-strings": {
"id": "string",
"id2": "string2"
"docs": {
"id": {
"title": "string1",
"sidebar_label": "string2"
},
"version-0.0.1-id": {
"title": "string3",
"sidebar_label": "string4"
}
}
},
"pages-strings" : {
"id3": "string3",
Expand Down
46 changes: 18 additions & 28 deletions lib/core/DocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const path = require('path');
const React = require('react');
const url = require('url');

const utils = require('./utils.js');
const Container = require('./Container.js');
const Doc = require('./Doc.js');
const DocsSidebar = require('./DocsSidebar.js');
const OnPageNav = require('./nav/OnPageNav.js');
const Site = require('./Site.js');
const translation = require('../server/translation.js');
const docs = require('../server/docs.js');
const {idx, getGitLastUpdated} = require('./utils.js');

// component used to generate whole webpage for docs, including sidebar/header/footer
class DocsLayout extends React.Component {
Expand All @@ -37,21 +37,21 @@ class DocsLayout extends React.Component {
render() {
const metadata = this.props.metadata;
const content = this.props.children;
const i18n = translation[this.props.metadata.language];
const i18n = translation[metadata.language];
const id = metadata.localized_id;
const defaultTitle = metadata.title;
let DocComponent = Doc;
if (this.props.Doc) {
DocComponent = this.props.Doc;
}
let updateTime;
if (this.props.config.enableUpdateTime) {
const filepath = docs.getFilePath(metadata);
updateTime = utils.getGitLastUpdated(filepath);
updateTime = getGitLastUpdated(filepath);
}
const title = i18n
? translation[this.props.metadata.language]['localized-strings'][
this.props.metadata.localized_id
] || this.props.metadata.title
: this.props.metadata.title;

const title =
idx(i18n, ['localized-strings', 'docs', id, 'title']) || defaultTitle;
const hasOnPageNav = this.props.config.onPageNav === 'separate';
return (
<Site
Expand All @@ -72,7 +72,7 @@ class DocsLayout extends React.Component {
content={content}
config={this.props.config}
source={metadata.source}
hideTitle={this.props.metadata.hide_title}
hideTitle={metadata.hide_title}
title={title}
version={metadata.version}
language={metadata.language}
Expand All @@ -86,15 +86,10 @@ class DocsLayout extends React.Component {
metadata.previous_id
)}>
{' '}
{i18n
? translation[this.props.metadata.language][
'localized-strings'
][metadata.previous_id] ||
translation[this.props.metadata.language][
'localized-strings'
].previous ||
'Previous'
: metadata.previous_title || 'Previous'}
{idx(i18n, ['localized-strings', metadata.previous_id]) ||
idx(i18n, ['localized-strings', 'previous']) ||
metadata.previous_title ||
'Previous'}
</a>
)}
{metadata.next_id && (
Expand All @@ -104,15 +99,10 @@ class DocsLayout extends React.Component {
metadata.localized_id,
metadata.next_id
)}>
{i18n
? translation[this.props.metadata.language][
'localized-strings'
][metadata.next_id] ||
translation[this.props.metadata.language][
'localized-strings'
].next ||
'Next'
: metadata.next_title || 'Next'}{' '}
{idx(i18n, ['localized-strings', metadata.next_id]) ||
idx(i18n, ['localized-strings', 'next']) ||
metadata.next_title ||
'Next'}{' '}
</a>
)}
Expand All @@ -127,7 +117,7 @@ class DocsLayout extends React.Component {
</Container>
{hasOnPageNav && (
<nav className="onPageNav">
<OnPageNav rawContent={this.props.children} />
<OnPageNav rawContent={content} />
</nav>
)}
</div>
Expand Down
7 changes: 4 additions & 3 deletions lib/core/Redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
const React = require('react');
const Head = require('./Head.js');
const translation = require('../server/translation.js');
const {idx} = require('./utils.js');

// Component used to provide same head, header, footer, other scripts to all pages
class Redirect extends React.Component {
render() {
const tagline = translation[this.props.language]
? translation[this.props.language]['localized-strings'].tagline
: this.props.config.tagline;
const tagline =
idx(translation, [this.props.language, 'localized-strings', 'tagline']) ||
this.props.config.tagline;
const title = this.props.title
? `${this.props.title} · ${this.props.config.title}`
: (!this.props.config.disableTitleTagline &&
Expand Down
7 changes: 4 additions & 3 deletions lib/core/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ const Head = require('./Head.js');
const Footer = require(`${process.cwd()}/core/Footer.js`);
const translation = require('../server/translation.js');
const constants = require('./constants');
const {idx} = require('./utils.js');

const CWD = process.cwd();

// Component used to provide same head, header, footer, other scripts to all pages
class Site extends React.Component {
render() {
const tagline = translation[this.props.language]
? translation[this.props.language]['localized-strings'].tagline
: this.props.config.tagline;
const tagline =
idx(translation, [this.props.language, 'localized-strings', 'tagline']) ||
this.props.config.tagline;
const title = this.props.title
? `${this.props.title} · ${this.props.config.title}`
: (!this.props.config.disableTitleTagline &&
Expand Down
31 changes: 20 additions & 11 deletions lib/core/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,29 @@ describe('utils', () => {
});

test('getPath', () => {
expect(utils.getPath('/docs/en/versioning.html', true)).toBe(
'/docs/en/versioning'
);
expect(utils.getPath('/en/users.html', true)).toBe('/en/users');
expect(utils.getPath('/docs/en/asd/index.html', true)).toBe('/docs/en/asd');
expect(utils.getPath('/en/help/index.html', true)).toBe('/en/help');
expect(utils.getPath('/en/help.a.b.c.d.e.html', true)).toBe(
'/en/help.a.b.c.d.e'
);
expect(utils.getPath('/en/help.js', true)).toBe('/en/help');
// does not change/transform path
expect(utils.getPath('/en/users.html', false)).toBe('/en/users.html');
expect(utils.getPath('/docs/en/versioning.html', false)).toBe(
'/docs/en/versioning.html'
);
expect(utils.getPath('/en/users.html', false)).toBe('/en/users.html');
expect(utils.getPath(undefined, false)).toBeUndefined();
expect(utils.getPath(null, false)).toBeNull();

// transform to pretty/clean path
const cleanPath = pathStr => utils.getPath(pathStr, true);
expect(cleanPath('/en/users')).toBe('/en/users');
expect(cleanPath('/docs/versioning.html')).toBe('/docs/versioning');
expect(cleanPath('/en/users.html')).toBe('/en/users');
expect(cleanPath('/docs/en/asd/index.html')).toBe('/docs/en/asd/');
expect(cleanPath('/en/help/index.html')).toBe('/en/help/');
expect(cleanPath('/index.html')).toBe('/');
expect(cleanPath('/react/index.html')).toBe('/react/');
expect(cleanPath('/en/help.a.b.c.d.e.html')).toBe('/en/help.a.b.c.d.e');
expect(cleanPath('/en/help.js')).toBe('/en/help.js');
expect(cleanPath('/test.md')).toBe('/test.md');
expect(cleanPath('/blog/7.0.0')).toBe('/blog/7.0.0');
expect(cleanPath('/test/5.html.2')).toBe('/test/5.html.2');
expect(cleanPath('/docs/en/5.2')).toBe('/docs/en/5.2');
});

test('removeExtension', () => {
Expand Down
11 changes: 5 additions & 6 deletions lib/core/nav/HeaderNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const readMetadata = require('../../server/readMetadata.js');

readMetadata.generateMetadataDocs();
const Metadata = require('../metadata.js');
const utils = require('../utils.js');
const {idx, getPath} = require('../utils.js');

const extension = siteConfig.cleanUrl ? '' : '.html';

Expand Down Expand Up @@ -56,7 +56,7 @@ class LanguageDropDown extends React.Component {
}
return (
<li key={lang.tag}>
<a href={utils.getPath(href, this.props.cleanUrl)}>{lang.name}</a>
<a href={getPath(href, this.props.cleanUrl)}>{lang.name}</a>
</li>
);
});
Expand Down Expand Up @@ -188,7 +188,7 @@ class HeaderNav extends React.Component {
}
href =
this.props.config.baseUrl +
utils.getPath(Metadata[id].permalink, this.props.config.cleanUrl);
getPath(Metadata[id].permalink, this.props.config.cleanUrl);

const {id: currentID, sidebar} = this.props.current;
docItemActive = currentID && currentID === id;
Expand Down Expand Up @@ -220,12 +220,11 @@ class HeaderNav extends React.Component {
(link.blog && this.props.current.blogListing) ||
(link.page && link.page === this.props.current.id),
});
const i18n = translation[this.props.language];
return (
<li key={`${link.label}page`} className={itemClasses}>
<a href={href} target={link.external ? '_blank' : '_self'}>
{translation[this.props.language]
? translation[this.props.language]['localized-strings'][link.label]
: link.label}
{idx(i18n, ['localized-strings', 'links', link.label]) || link.label}
</a>
</li>
);
Expand Down
30 changes: 16 additions & 14 deletions lib/core/nav/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,50 @@ const classNames = require('classnames');

const siteConfig = require(`${process.cwd()}/siteConfig.js`);
const translation = require('../../server/translation.js');
const utils = require('../utils.js');
const {getPath, idx} = require('../utils.js');

class SideNav extends React.Component {
// return appropriately translated category string
getLocalizedCategoryString(category) {
const categoryString = translation[this.props.language]
? translation[this.props.language]['localized-strings'][category] ||
category
: category;
const categoryString =
idx(translation, [
this.props.language,
'localized-strings',
'categories',
category,
]) || category;
return categoryString;
}

// return appropriately translated label to use for doc/blog in sidebar
getLocalizedString(metadata) {
let localizedString;
const i18n = translation[this.props.language];
const id = metadata.localized_id;
const sbTitle = metadata.sidebar_label;

if (sbTitle) {
localizedString = i18n
? i18n['localized-strings'][sbTitle] || sbTitle
: sbTitle;
localizedString =
idx(i18n, ['localized-strings', 'docs', id, 'sidebar_label']) ||
sbTitle;
} else {
const id = metadata.original_id || metadata.localized_id;
localizedString = i18n
? i18n['localized-strings'][id] || metadata.title
: metadata.title;
localizedString =
idx(i18n, ['localized-strings', 'docs', id, 'title']) || metadata.title;
}
return localizedString;
}

// return link to doc in sidebar
getLink(metadata) {
if (metadata.permalink) {
const targetLink = utils.getPath(metadata.permalink, siteConfig.cleanUrl);
const targetLink = getPath(metadata.permalink, siteConfig.cleanUrl);
if (targetLink.match(/^https?:/)) {
return targetLink;
}
return siteConfig.baseUrl + targetLink;
}
if (metadata.path) {
return `${siteConfig.baseUrl}blog/${utils.getPath(
return `${siteConfig.baseUrl}blog/${getPath(
metadata.path,
siteConfig.cleanUrl
)}`;
Expand Down
21 changes: 13 additions & 8 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ function extractBlogPostBeforeTruncate(content) {
return content.split(TRUNCATE_MARKER)[0];
}

function removeExtension(path) {
return path.replace(/\.[^/.]+$/, '');
function removeExtension(pathStr) {
return pathStr.replace(/\.[^/.]+$/, '');
}

function getPath(path, cleanUrl = false) {
if (cleanUrl) {
return path.endsWith('/index.html')
? path.replace(/\/index.html$/, '')
: removeExtension(path);
function getPath(pathStr, cleanUrl = false) {
if (!pathStr || !cleanUrl || !pathStr.endsWith('.html')) {
return pathStr;
}
return path;
return pathStr.endsWith('/index.html')
? pathStr.replace(/index\.html$/, '')
: removeExtension(pathStr);
}

function idx(target, path) {
return path.reduce((obj, key) => obj && obj[key], target);
}

function getGitLastUpdated(filepath) {
Expand All @@ -46,4 +50,5 @@ module.exports = {
getGitLastUpdated,
getPath,
removeExtension,
idx,
};
2 changes: 1 addition & 1 deletion lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function generateMetadataDocs() {

// metadata for english files
const docsDir = path.join(CWD, '../', getDocsPath());
let files = glob.sync(`${CWD}/../${getDocsPath()}/**`);
let files = glob.sync(`${docsDir}/**`);
files.forEach(file => {
const extension = path.extname(file);

Expand Down
Loading

0 comments on commit 299c504

Please sign in to comment.