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): plugins injectHtmlTags + configureWebpack should receive content loaded #5037

Merged
merged 5 commits into from
Jun 22, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Jun 22, 2021

Motivation

Plugin lifecycles that are triggered after we loaded the plugin content should permit to access that plugin content.

The following should work:

module.exports = function (context, options) {
  return {
    name: 'docusaurus-plugin',
    loadContent: async () => {
      return {remoteHeadTags: await fetchHeadTagsFromAPI()};
    },
    injectHtmlTags({content}) {
      return {
        headTags: content.remoteHeadTags,       
      };
    },
  };
};

Also injecting the content in the configureWebpack lifecycle, as we compute the mdx/remark config by using the loaded content for resolving relative file path links to URLs. This permits to avoid an unelegant side-effect we previously had in loadContent:

        // TODO annoying side effect!
        Object.values(docs).forEach((loadedDoc) => {
          const {source, permalink} = loadedDoc;
          sourceToPermalink[source] = permalink;
        });

Mentioned in #4923 (comment)

Test Plan

test + dogfood in internal plugins

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jun 22, 2021
@slorber slorber requested a review from lex111 as a code owner June 22, 2021 14:58
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 22, 2021
@slorber
Copy link
Collaborator Author

slorber commented Jun 22, 2021

cc @jsamr is this what you had in mind?

@jsamr
Copy link
Contributor

jsamr commented Jun 22, 2021

@slorber Absolutely 👌 Thank you!

@netlify
Copy link

netlify bot commented Jun 22, 2021

✔️ [V2]

🔨 Explore the source changes: 548fa95

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60d1fe30213eff00079caa43

😎 Browse the preview: https://deploy-preview-5037--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 22, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 64
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5037--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jun 22, 2021

Size Change: 0 B

Total Size: 569 kB

ℹ️ View Unchanged
Filename Size
website/build/assets/css/styles.********.css 87.8 kB
website/build/assets/js/main.********.js 385 kB
website/build/blog/2017/12/14/introducing-docusaurus/index.html 65.8 kB
website/build/docs/introduction/index.html 235 B
website/build/index.html 30.5 kB

compressed-size-action

@slorber slorber merged commit 119c6d1 into master Jun 22, 2021
@slorber slorber deleted the slorber/plugin-lifecyle-receive-content branch August 17, 2021 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants