-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Fixing Issue 305 - broken links because of language #316
Conversation
Let me know if double having is intentional
@richardzcode Hi! Yep the build failed because prettier issues thus far. Did you run https://gist.github.com/JoelMarcey/215ea77e546496ab5758bcc86fe4152c |
My fault. I did run prettier but did not check what prettier changed... Let me try again. |
....and tests passed :) |
😁 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richardzcode I really like this pull request. I understand what you are trying to do here, and I think it makes sense.
I have some feedback/questions.
One key thing is that I think you need to rebase to the latest in master
because some of the code I see in your PR is stuff that you are bringing back that has been removed in other PRs.
I want to think about this some more, and maybe let some of the other core team have a look as well. I may try to run this on a couple of our other sites too to make sure we are not breaking anyone horribly.
But I am impressed. <3 👍
lib/server/readMetadata.js
Outdated
@@ -81,8 +68,7 @@ function readSidebar() { | |||
|
|||
// split markdown header | |||
function splitHeader(content) { | |||
// New line characters need to handle all operating systems. | |||
const lines = content.split(/\r?\n/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to keep the content.split(/\r?\n/);
so we can continue to support, Windows, right? This was just added in #304 by @neilsutcliffe
lib/core/nav/HeaderNav.js
Outdated
? this.props.language + '/versions.html' | ||
: 'versions.html'); | ||
return ( | ||
<div className="fixedHeaderContainer"> | ||
<div className="headerWrapper wrapper"> | ||
<header> | ||
<a href={this.props.baseUrl}> | ||
{siteConfig.headerIcon && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to remove the siteConfig.headerIcon check? It was just added in #312.
@@ -149,28 +132,19 @@ function processMetadata(file) { | |||
metadata.title = metadata.id; | |||
} | |||
|
|||
if (languages.length === 1 && !siteConfig.useEnglishUrl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, siteConfig.useEnglishUrl
is a config option (that is not documented, unfortunately - but I will document it if we agree), that allows one to override the default of /docs/doc.html
with something like /docs/en/doc.hmtl
.
Are you thinking we shouldn't allow this override any longer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my mistake. should keep this override. should we use this override, or just have a languages.js with only 'en' enabled. It is a separate question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal opinion is that we document and use the override to keep a clean separation between sites that have translations and sites that do not. If you have a language.js
file, then translations will be enabled. If you want the /docs/en
format, but no translations, you can use this override.
Seem reasonable?
lib/server/readMetadata.js
Outdated
@@ -194,6 +170,8 @@ function processMetadata(file) { | |||
|
|||
// process metadata for all docs and save into core/metadata.js | |||
function generateMetadataDocs() { | |||
console.log('Generating Metadata for Docs....'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may not be fully rebased to the latest master. I know this was removed on purpose because the logs were too noisy in #291
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
lib/server/readMetadata.js
Outdated
@@ -345,6 +322,13 @@ function generateMetadataBlog() { | |||
const metadatas = []; | |||
|
|||
let files = glob.sync(CWD + '/blog/**/*.*'); | |||
if (!files || files.length == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. This was also removed in #291
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
lib/server/server.js
Outdated
@@ -122,6 +120,8 @@ function execute(port) { | |||
|
|||
/****************************************************************************/ | |||
|
|||
console.log('server.js triggered...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here too: #291
const siteConfig = require(CWD + '/siteConfig.js'); | ||
const translate = require('./translate.js'); | ||
const versionFallback = require('./versionFallback.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this is removed because it is unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this one is not used.
@@ -23,15 +24,12 @@ function execute(port) { | |||
const glob = require('glob'); | |||
const chalk = require('chalk'); | |||
const translate = require('./translate.js'); | |||
const versionFallback = require('./versionFallback'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this is removed because it is unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is unused.
lib/server/server.js
Outdated
@@ -523,6 +518,7 @@ function execute(port) { | |||
}); | |||
|
|||
app.listen(port); | |||
console.log('listening on port: ' + port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here too: #291
@ericnakagawa @ericvicenti @hramos - maybe have a quick look at this too to make sure I am not missing anything key here. I like the PR. |
Thank you @JoelMarcey for the thorough review! Not sure what went wrong with my rebase. Now corrected. I'll be extra careful next time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I am going to go with this. Thanks so much for this -- this definitely wasn't an easy task.
This reverts commit 7dc6c6c.
I had to revert this actually -- I just noticed a link in docusaurus.io that was broken. Let me check out why. |
@richardzcode Hi. Sorry I had to revert this. However, I cherry-picked your pull request locally and am running some tests on it. I am finding some things, which I will comment inline. |
const join = path.join; | ||
|
||
const languages_js = join(CWD, 'lanauages.js'); | ||
const translation_js = join(CWD, 'translation.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be const translation_js = './translation.js;
since this file is in the same directory as env.js
, not as part of the current process' working directory.
|
||
const join = path.join; | ||
|
||
const languages_js = join(CWD, 'lanauages.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was spelled wrong :)
languages.js
} | ||
const langPart = env.translation.enabled ? this.props.language + '-' : ''; | ||
const versionPart = | ||
env.translation.enabled && this.props.version !== 'next' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be env.versioning.enabled
, not env.translation.enabled
.
@@ -443,21 +425,25 @@ function execute() { | |||
str | |||
); | |||
} | |||
|
|||
// write to base level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking there is something funny going on in this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I am not 100% sure yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a change I made in order to generate default pages from English pages. Original code was to copy English pages to one level above. However those pages has {language} property as 'en' which causes links wrong. So I made the change to generate instead. Couldn't think of a problem it would cause, but let me run some tests first.
Sorry about the mistakes. Let me run some more tests. Should I continue fix on this PR? Or it should be handled separately? |
No apologies necessary :) I really appreciate the work here. I think we are close. Since I merged this one already, it's hard to bring back. Maybe a new PR with the fixes in it would be best. Is that ok? |
@richardzcode When I try to build docusaurus locally using
And that is because at some point |
sure. Working on it. |
I think I know what's going on in HeaderNav.js. This line:
Because we are generating default pages with language=''. When translation enabled, langPart would become '-doc1' etc. which does not exist in Metadata. But I am confused why my local test doesn't have the problem... |
@richardzcode Are you testing on your own personal site? Or are you testing on the Docusaurus site itself? |
@JoelMarcey Testing on my own site. You are right. I should test on Docusaurus site. |
Need this because of facebook#316
Motivation
This is to fix #305
The root cause of the problem is using 'en' as default language regardless of translation enabled or not.
However 'en' and no translation are two different cases. The fix has two major parts:
language
property as an indication of no translation.For readability I've created a new file
env.js
which encapsulate simple translation and versioning logic. So other places can just callenv.translation.enabled
to check.I try to keep the changes minimal but sill has to modify quite a few files.
Test Plan
I've tested run server and generate locally.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)