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): siteMetadata #3042

Closed
slorber opened this issue Jul 9, 2020 · 3 comments
Closed

feat(v2): siteMetadata #3042

slorber opened this issue Jul 9, 2020 · 3 comments
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. mlh Major League Hacking Fellowship

Comments

@slorber
Copy link
Collaborator

slorber commented Jul 9, 2020

🚀 Feature

Currently, as far as I know, a site can't know which docusaurus version it is currently using

It would be useful to be able to get some metadata about the framework.

Algolia/DocSearch devs have expressed the need to be able to track which version of Docusaurus uses which version of DocSearch.

I think this does not belong to the site config: it is a new docusaurus context item that we should create.

const {siteMetadata} = useDocusaurusContext();

For now we could keep it simple and just add the version, as it's been asked by Algolia.

{
  docusaurusVersion: "2.0.0-alpha.58"
}

This could be enhanced later, and include all plugins versions, the site version, and other useful things that we'd find useful.

We could also add these data to docusaurus-plugin-debug , @SamChou19815 do you think of additional data that could be useful to display?

@slorber slorber added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. mlh Major League Hacking Fellowship labels Jul 9, 2020
@SamChou19815
Copy link
Contributor

We could also add these data to docusaurus-plugin-debug , @SamChou19815 do you think of additional data that could be useful to display?

I think it can be useful. The version information can also be included in all official plugins, and the debug plugin can help detect out-of-sync versions (e.g. core at alpha-58, theme-classic at alpha-56)

@slorber
Copy link
Collaborator Author

slorber commented Jul 10, 2020

Yes that's what I think too

The version information can also be included in all official plugins

For official plugins or not, I think we could do this in a generic way, to add plugin versions to this siteMetadata file:

  • if plugin is in node modules, read the version from its package.json
  • if plugin is a local js file, maybe fallback to the package.json version of the site (or null if no version specified)

The file could look like

{
  "docusaurusVersion": "2.0.0-alpha.58",
  "siteVersion": "1.0.0",
  "pluginVersions": {
    "docusaurus-plugin-pwa": "2.0.0-alpha.58",
    "custom-site-plugin": "1.0.0"
  }
}

I think we should use plugin name like docusaurus-plugin-pwa, and not plugin package name @docusaurus/plugin-pwa because local plugins don't necessarily have a package name, yet we could enforce them to have a name attribute.

Does someone want to work on this?

@SamChou19815
Copy link
Contributor

if plugin is in node modules, read the version from its package.json

Detecting existence of node_modules in plugin's resolved path might not be a good idea, since it might give surprising result for monorepo setup. For example, this is the resolved path for all plugins in docusaurus repo:

/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-content-docs/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-content-blog/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-content-pages/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-debug/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-theme-classic/src/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-theme-search-algolia/src/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-client-redirects/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-plugin-ideal-image/lib/index.js
/Users/sam/Desktop/workplace/docusaurus/packages/docusaurus-theme-live-codeblock/src/index.js

There are no node_modules in the path, but they clearly belong to some package.

Therefore, I think all we can reliably do is to recursively walk up along the plugin resolved path until we hit a directory that contains package.json, and try to resolve version info from there.

Then there comes to the question of local plugins. I think it will almost always be the case that they share the same package.json with the root project. If we detect this is the case, we probably should just say it's local without giving a confusing version.

I will probably try to work on it tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. mlh Major League Hacking Fellowship
Projects
None yet
Development

No branches or pull requests

2 participants