-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Changes from 4 commits
5a56c62
388a915
b346d0f
e36f990
04b9870
fb42b18
04850b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
if (this.props.title) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a comment here saying something like:
|
||
title = <h1>{this.props.title}</h1>; | ||
} | ||
return ( | ||
<div className="post"> | ||
<header className="postHeader"> | ||
{editLink} | ||
<h1>{this.props.title}</h1> | ||
{title} | ||
</header> | ||
<article> | ||
<MarkdownBlock>{this.props.content}</MarkdownBlock> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. These stuff can remain. Pass |
||
// 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 = i18n | ||
? translation[this.props.metadata.language]['localized-strings'][ | ||
this.props.metadata.localized_id | ||
] || this.props.metadata.title | ||
: this.props.metadata.title; | ||
} | ||
return ( | ||
<Site | ||
config={this.props.config} | ||
|
@@ -46,14 +58,7 @@ class DocsLayout extends React.Component { | |
content={content} | ||
config={this.props.config} | ||
source={metadata.source} | ||
title={ | ||
i18n | ||
? translation[this.props.metadata.language][ | ||
'localized-strings' | ||
][this.props.metadata.localized_id] || | ||
this.props.metadata.title | ||
: this.props.metadata.title | ||
} | ||
title={docTitle} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in the |
||
version={metadata.version} | ||
language={metadata.language} | ||
/> | ||
|
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:
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 astrue
as it is a non-empty string.