Skip to content

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

Merged
endiliey merged 4 commits into
masterfrom
endiliey/scripts-stylesheets
Oct 12, 2019
Merged

feat(v2): add scripts and stylesheets field to config#1831
endiliey merged 4 commits into
masterfrom
endiliey/scripts-stylesheets

Conversation

@endiliey

Copy link
Copy Markdown
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

@endiliey endiliey requested a review from yangshun as a code owner October 11, 2019 05:34
@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

docusaurus-bot commented Oct 11, 2019

Copy link
Copy Markdown
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit bff9eb6

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

@docusaurus-bot

docusaurus-bot commented Oct 11, 2019

Copy link
Copy Markdown
Contributor

Deploy preview for docusaurus-preview ready!

Built with commit bff9eb6

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

@yangshun yangshun left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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

Comment thread packages/docusaurus/src/client/App.js Outdated
Comment thread packages/docusaurus/src/client/App.js Outdated
@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
Copy Markdown

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
Copy Markdown
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.

6 participants