Skip to content
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 customize highlight.theme custom path support #517

Merged

Conversation

huang-x-h
Copy link
Contributor

@huang-x-h huang-x-h commented Mar 19, 2018

Motivation

Add customize highlight.theme custom path support. Fixes #428

eg:

  highlight: {
    theme: '/somepath/solarized-dark.min.css',
  },
  separateCss: ['solarized-dark'],

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Test success on local

Related PRs

N/A

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 19, 2018
@JoelMarcey
Copy link
Contributor

@huang-x-h Hi. Sorry for the delay here. I am currently on vacation. I will have a thorough review of this as soon as I can.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @huang-x-h ! Please have a look at the suggestions in the comments. If you would not be available to fix this, just let us know and we can take over 😄

lib/core/Head.js Outdated
const highlightTheme = highlightConfig.theme || 'default';

if (highlight.theme.indexOf('/') > -1) {
highlight = highlight.theme;
Copy link
Contributor

@yangshun yangshun Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good idea to let the theme be either a string or a URL as this leads to confusing configuration. It's better to add a new field in highlight object called themeUrl and the code here uses it directly instead of building up the URL from the version and theme. Do remember to add this new URL to the siteConfig documentation.

Define a new variable highlightThemeURL instead. Don't reassign a value of a different type to the highlight variable.

// Use user-provided themeUrl if it exists, else construct one from version and theme.
let highlightThemeURL = highlight.themeUrl || `//cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlight.version}/styles/${highlight.theme}.min.css`;

// Use highlightThemeURL in the `<link>`.

lib/core/Head.js Outdated
const highlightVersion = highlightConfig.version || highlightDefaultVersion;
const highlightTheme = highlightConfig.theme || 'default';

if (highlight.theme.indexOf('/') > -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a very strong check. There's no guarantee that themes cannot have slashes in it in the future. Refer to comment below about using a themeUrl field as a check.

lib/core/Head.js Outdated
const highlightTheme = highlightConfig.theme || 'default';

if (highlight.theme.indexOf('/') > -1) {
highlight = highlight.theme;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a new variable highlightURL instead. Don't reassign a value of a different type to the highlight variable.

@@ -33,12 +33,6 @@ class Site extends React.Component {
(this.props.url || 'index.html');
let docsVersion = this.props.version || 'current';

const highlightDefaultVersion = '9.12.0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing this 👍

@huang-x-h huang-x-h force-pushed the feature-highlight-support-custom branch from aa713dc to fa36d9d Compare April 16, 2018 02:39
@huang-x-h
Copy link
Contributor Author

@yangshun thank you for your review, it's fixed.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoelMarcey Please have a final look

Copy link
Contributor

@JoelMarcey JoelMarcey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Should go out in the next release!

@JoelMarcey JoelMarcey merged commit aa32ff4 into facebook:master Apr 19, 2018
@huang-x-h huang-x-h deleted the feature-highlight-support-custom branch May 3, 2018 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants