-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Add hide_title metadata that hides the title text on the top of the doc #540
Conversation
@MisterTea Did you run prettier before submitting this PR? |
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.
Hi @MisterTea. Thanks for the PR. I have a couple of questions/suggestions.
It looks like hide_title
would be part of the doc header metadata as discussed here: https://docusaurus.io/docs/en/doc-markdown.html
- Can you update the docs for this new field? https://github.com/facebook/Docusaurus/blob/master/docs/api-doc-markdown.md
- Run
npm run prettier
to make sure the code is formatted correctly. - Then I have some code comments inline...
lib/core/DocsLayout.js
Outdated
@@ -23,6 +23,15 @@ class DocsLayout extends React.Component { | |||
if (this.props.Doc) { | |||
DocComponent = this.props.Doc; | |||
} | |||
let docTitle = i18n |
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.
Someone might put
hide_title: false
in the doc header.
So, how about instead we do the converse here:
let docTitle = null;
// If the attribute does not exist or is set to false, we set a title.
if (!this.props.metadata.hide_title || this.props.metadata.hide_title.toLowerCase() === 'false') {
docTitle = ....
}
lib/core/Doc.js
Outdated
@@ -60,11 +60,18 @@ class Doc extends React.Component { | |||
</a> | |||
); | |||
} | |||
|
|||
let title = null; | |||
if (this.props.title) { |
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.
Maybe a comment here saying something like:
// this.props.title could be set to null if hide_title was set in the doc metadata
@yangshun Can you look at this too? I think it is right, but just wanted to make sure I wasn't missing anything here. |
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.
Nice work @MisterTea ! I left some inline comments on how the code can be simplified. We should try as much not to change too much of the existing logic and it seems like it's possible for this feature to do so.
docs/api-doc-markdown.md
Outdated
@@ -13,6 +13,8 @@ Documents use the following markdown header fields that are enclosed by a line ` | |||
|
|||
`title`: The title of your document. If this field is not present, the document's `title` will default to its `id`. | |||
|
|||
`hide_title`: Whether to hide the title at the top of each documentation page. If this is `null` or set to anything besides `false`, the title will be displayed. |
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.
It's better if this field was restricted to a boolean value for simplicity. That way, we can shorten the description to the first sentence and do less checks in our code.
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.
@yangshun How do you control what a user might enter in the metadata for the doc though? Someone could put:
hide_title: 'blahblah'
How do we treat that?
Or are you saying that just the fact that hide_title
is explicitly put in the metadata it is always truthy, no matter the associated string?
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 I mean we will just determine the value based on whether it's truthy/falsy if a non-true
/false
value was provided. It'll be too much of a hassle to do type checks manually.
I believe Front matter supports boolean values (I will have to check on that though).
If a use puts 'blahblah'
, it will be treated as true
as it is a non-empty string.
lib/core/Doc.js
Outdated
@@ -60,11 +60,17 @@ class Doc extends React.Component { | |||
</a> | |||
); | |||
} | |||
|
|||
let title = null; | |||
// this.props.title could be set to null if hide_title was set in the doc metadata |
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.
The title
value should be kept independent of the showing/hiding logic. What you can do is to pass in the prop hideTitle
into this component from the parent.
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.
You can also inline the conditional rendering logic into JSX since it's very short:
{this.props.hideTitle && <h1>{this.props.title}</h1>}
lib/core/DocsLayout.js
Outdated
@@ -23,6 +23,18 @@ class DocsLayout extends React.Component { | |||
if (this.props.Doc) { | |||
DocComponent = this.props.Doc; | |||
} | |||
let docTitle = null; |
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.
These stuff can remain. Pass this.props.metadata.hide_title
as a prop to <DocComponent>
/<Doc>
instead to simplify things.
lib/core/DocsLayout.js
Outdated
this.props.metadata.title | ||
: this.props.metadata.title | ||
} | ||
title={docTitle} |
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.
Pass in the hideTitle
prop here - hideTitle={metadata.hide_title}
I think this new way is a lot cleaner, thanks. Let me know what you think! |
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.
Thanks for the quick changes! LGTM, will let @JoelMarcey have a final look and merge
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.
Awesome! Thanks.
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 are missing a !
, aren't we?
lib/core/Doc.js
Outdated
return ( | ||
<div className="post"> | ||
<header className="postHeader"> | ||
{editLink} | ||
<h1>{this.props.title}</h1> | ||
{this.props.hideTitle && <h1>{this.props.title}</h1>} |
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.
Wait. Shouldn't this be
!this.props.hideTitle
We only want to show this if we don't have hideTitle, right?
Good catch! My bad for typing incorrect example code >_<
…On Wed, Apr 11, 2018, 5:47 PM Joel Marcey ***@***.***> wrote:
***@***.**** requested changes on this pull request.
I think we are missing a !, aren't we?
------------------------------
In lib/core/Doc.js
<#540 (comment)>:
> return (
<div className="post">
<header className="postHeader">
{editLink}
- <h1>{this.props.title}</h1>
+ {this.props.hideTitle && <h1>{this.props.title}</h1>}
Wait. Shouldn't this be
!this.props.hideTitle
We only want to show this if we don't have hideTitle, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#540 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQRHZwrdavxSGEiCElV951Hkcy-ee38ks5tnqQigaJpZM4TNlRI>
.
|
I went ahead and made the update. I think we are good now. |
I'll give it a thorough test later (:
On Apr 11, 2018 5:53 PM, "Joel Marcey" <notifications@github.com> wrote:
*@JoelMarcey* approved this pull request.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#540 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQRHQSfgHWfrkwe4etqil7Z0fwwHXFHks5tnqWigaJpZM4TNlRI>
.
|
I was going to test it locally right now ;) |
Seems to work 👍 |
Motivation
Optionally hide the title from the top of the doc so people can customize the title
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Running with this on my test site
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.)