From 6ca90610f4eb1936abac95308c2561621dc0e141 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Tue, 8 Aug 2017 13:46:11 -0700 Subject: [PATCH 1/2] Update headerLinks API --- lib/core/BlogPageLayout.js | 1 - lib/core/BlogPostLayout.js | 1 - lib/core/DocsLayout.js | 1 - lib/core/Site.js | 1 - lib/core/nav/HeaderNav.js | 118 ++++++++++++++++++++----------------- lib/write-translations.js | 13 ++-- website/siteConfig.js | 18 ++---- 7 files changed, 74 insertions(+), 79 deletions(-) diff --git a/lib/core/BlogPageLayout.js b/lib/core/BlogPageLayout.js index 771e4fc5ed..6bfebc6b25 100644 --- a/lib/core/BlogPageLayout.js +++ b/lib/core/BlogPageLayout.js @@ -28,7 +28,6 @@ const BlogPageLayout = React.createClass({ const page = this.props.metadata.page; return ( + + ); - } else { - updatedLink = updatedLink.replace(/\/VERSION\//, "/"); + } else if (link.languages) { + return ( + + ); + } else if (link.doc) { + let id; + if (!ENABLE_VERSIONING || this.props.version === "next") { + id = this.props.language + "-" + link.doc; + } else { + id = + this.props.language + + "-version-" + + (this.props.version || versions[0]) + + "-" + + link.doc; + } + console.log(id); + href = this.props.config.baseUrl + Metadata[id].permalink; + } else if (link.page) { + if (fs.existsSync(CWD + "/pages/en/" + link.page + ".js")) { + href = + siteConfig.baseUrl + this.props.language + "/" + link.page + ".html"; + } else { + href = siteConfig.baseUrl + link.page + ".html"; + } + } else if (link.href) { + href = link.href; } return ( -
  • - +
  • + {translation[this.props.language] - ? translation[this.props.language]["localized-strings"][link.text] - : link.text} - -
  • - ); - } - - makeExternalLinks(link) { - return ( -
  • - - {translation[this.props.language] - ? translation[this.props.language]["localized-strings"][link.text] - : link.text} + ? translation[this.props.language]["localized-strings"][link.label] + : link.label}
  • ); @@ -174,30 +182,32 @@ class HeaderNav extends React.Component { } renderResponsiveNav() { + const headerLinks = this.props.config.headerLinks; + // add language drop down to end if location not specified + let languages = false; + headerLinks.forEach(link => { + if (link.languages) { + languages = true; + } + }); + if (!languages) { + headerLinks.push({ languages: true }); + } + // add search bar to end if location not specified + let search = false; + headerLinks.forEach(link => { + if (link.search) { + search = true; + } + }); + if (!search && this.props.config.algolia) { + headerLinks.push({ search: true }); + } return (
    diff --git a/lib/write-translations.js b/lib/write-translations.js index b5ce9a35d8..826ae9b076 100755 --- a/lib/write-translations.js +++ b/lib/write-translations.js @@ -57,14 +57,11 @@ function execute() { } }); /* look through header links for text to translate */ - for (let i = 0; i < siteConfig.headerLinksInternal.length; i++) { - translations["localized-strings"][siteConfig.headerLinksInternal[i].text] = - siteConfig.headerLinksInternal[i].text; - } - for (let i = 0; i < siteConfig.headerLinksExternal.length; i++) { - translations["localized-strings"][siteConfig.headerLinksExternal[i].text] = - siteConfig.headerLinksExternal[i].text; - } + siteConfig.headerLinks.forEach(link => { + if (link.label) { + translations["localized-strings"][link.label] = link.label; + } + }); /* find sidebar category titles to translate */ Object.keys(sidebars).forEach(sb => { diff --git a/website/siteConfig.js b/website/siteConfig.js index 1be5f0061f..28db207244 100644 --- a/website/siteConfig.js +++ b/website/siteConfig.js @@ -26,19 +26,12 @@ const siteConfig = { users, editUrl: "https://github.com/facebookexperimental/docusaurus/edit/master/docs/", - headerLinksInternal: [ + headerLinks: [ + { doc: "installation", label: "Docs" }, + { page: "help", label: "Help" }, { - section: "docs", - href: "/docusaurus/docs/getting-started.html", - text: "Docs" - }, - { section: "help", href: "/docusaurus/LANGUAGE/help.html", text: "Help" } - ], - headerLinksExternal: [ - { - section: "github", href: "https://github.com/facebookexperimental/docusaurus", - text: "GitHub" + label: "GitHub" } ], headerIcon: "img/docusaurus.svg", @@ -55,8 +48,7 @@ const siteConfig = { colors: { primaryColor: "#2E8555", secondaryColor: "#205C3B", - prismColor: - "rgba(46, 133, 85, 0.03)" + prismColor: "rgba(46, 133, 85, 0.03)" } }; From 22cadc48fc391552b1d0269d6084edb68b0d20e9 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Tue, 8 Aug 2017 14:01:43 -0700 Subject: [PATCH 2/2] Clean up --- lib/core/nav/HeaderNav.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/core/nav/HeaderNav.js b/lib/core/nav/HeaderNav.js index 877d1dff61..375cea707a 100644 --- a/lib/core/nav/HeaderNav.js +++ b/lib/core/nav/HeaderNav.js @@ -128,7 +128,6 @@ class HeaderNav extends React.Component { "-" + link.doc; } - console.log(id); href = this.props.config.baseUrl + Metadata[id].permalink; } else if (link.page) { if (fs.existsSync(CWD + "/pages/en/" + link.page + ".js")) {