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

feat(v2): add scripts and stylesheets field to config #1831

Merged
merged 4 commits into from
Oct 12, 2019

Conversation

endiliey
Copy link
Contributor

Motivation

Add scripts and stylesheets field to docusaurus.config. for v1 parity and enable user to use external resources script or stylesheets

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

Add random scripts and stylesheets into config

  scripts: [
    'https://docusaurus.io/slash.js',
    {
      src:
        'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
      async: true,
    },
  ],
  stylesheets: [
    'https://docusaurus.io/style.css',
    {
      href: 'http://css.link',
      type: 'text/css',
    },
  ],

1

2

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 11, 2019
@endiliey endiliey changed the title Endiliey/scripts stylesheets feat(v2): add scripts and stylesheets field to config Oct 11, 2019
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 11, 2019

Deploy preview for docusaurus-2 ready!

Built with commit bff9eb6

https://deploy-preview-1831--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 11, 2019

Deploy preview for docusaurus-preview ready!

Built with commit bff9eb6

https://deploy-preview-1831--docusaurus-preview.netlify.com

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.

Nice! This will make it much easier to migrate.

<link rel="stylesheet" key={source} href={source} />
),
)}
{scripts &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we inject scripts here in V1? Putting scripts here blocks page rendering which is bad, unless they use async. Maybe we should allow injecting before </body>, but that'll be more complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep its done like this in v1

packages/docusaurus/src/client/App.js Outdated Show resolved Hide resolved
packages/docusaurus/src/client/App.js Outdated Show resolved Hide resolved
@endiliey endiliey merged commit ffd927d into master Oct 12, 2019
@endiliey endiliey deleted the endiliey/scripts-stylesheets branch October 12, 2019 02:54
@CMCDragonkai
Copy link

I followed the SO link here: https://stackoverflow.com/a/58349826/582917.

Is it possible to add in custom HTML tags like base tag into the head section?

@Josh-Cena
Copy link
Collaborator

@CMCDragonkai Please don't necropost—perfect way to get your question undiscoverable.

We don't have a first-class API for any tag, but you can get away with a plugin API:

// docusaurus.config.js
module.exports = {
  // ...
  plugins: [
    () => ({
      name: "inject-tag",
      injectHtmlTags() {
        return {
          headTags: [{ tagName: "base", attributes: { href: "https://www.example.com/" } }],
        };
      },
    }),
  ],
};

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.

None yet

6 participants