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(content-docs): version path & prefix configuration options #8737

Closed
wants to merge 4 commits into from

Conversation

Jersyfi
Copy link

@Jersyfi Jersyfi commented Mar 5, 2023

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

My personal motivation for modifying the docusaurus-plugin-content-docs plugin is to have more flexibility in the file structure. With this feature it is possible to group all files in one folder without having them in the project root folder.

Test Plan

I have added a test folder called versioned-site-with-custom-path with the versionPath and versionPrefix options set and all files grouped together. In this state the tests are simple and I need your opinion if any changes are needed.

image

Test links

Deploy preview: https://deploy-preview-8737--docusaurus-2.netlify.app/

Options

  • versionPath
    type: string | undefined
    default: undefined
  • versionPrefix
    type: boolean
    default: true

Mofified Documentation

Path: website/docs/api/plugins/plugin-content-docs.mdx
Deploy preview: https://deploy-preview-8737--docusaurus-2.netlify.app/docs/api/plugins/@docusaurus/plugin-content-docs/

Related issues/PRs

#8061

Jersyfi added 3 commits March 5, 2023 13:59
Added options to customize the path and the prefix of the versioned files
@facebook-github-bot
Copy link
Contributor

Hi @Jersyfi!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link

netlify bot commented Mar 5, 2023

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit d8d5810
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/64059a8602ce9a00087cc09e
😎 Deploy Preview https://deploy-preview-8737--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Mar 5, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟢 90 🟢 97 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 70 🟢 100 🟢 100 🟢 100 🟢 90 Report

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 6, 2023
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@@ -34,6 +34,8 @@ Accepted fields:
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `path` | `string` | `'docs'` | Path to the docs content directory on the file system, relative to site directory. |
| `versionPath` | `string` | `''` | Path to versioned files on filesystem, relative to site dir. |
Copy link
Author

Choose a reason for hiding this comment

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

TODO

Found that i missed changing the versionPath default value from '' to undefined.
image

? fileOrDir
: `${pluginId}_${fileOrDir}`;
}

/** `[siteDir]/community_versioned_docs/version-1.0.0` */
/** `[versionPath]/[pluginId?]_versioned_docs/version-1.0.0` */
Copy link
Author

@Jersyfi Jersyfi Mar 6, 2023

Choose a reason for hiding this comment

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

Change the following comment word.
versionPath -> (versionSiteDir or versionDir)

`version-${versionName}`,
);
}

/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
/** `[versionPath]/[pluginId?]_versioned_sidebars/version-1.0.0-sidebars.json` */
Copy link
Author

@Jersyfi Jersyfi Mar 6, 2023

Choose a reason for hiding this comment

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

Change the following comment word.
versionPath -> (versionSiteDir or versionDir)

/** `community` => `[siteDir]/community_versions.json` */
export function getVersionsFilePath(siteDir: string, pluginId: string): string {
return path.join(siteDir, addPluginIdPrefix(VERSIONS_JSON_FILE, pluginId));
/** `community` => `[versionPath]/community_versions.json` */
Copy link
Author

@Jersyfi Jersyfi Mar 6, 2023

Choose a reason for hiding this comment

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

Change the following comment word.
versionPath -> (versionSiteDir or versionDir)

@Jersyfi Jersyfi changed the title Version path & prefix configuration for plugin content docs feat(content-docs): version path & prefix configuration options Mar 6, 2023
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Looks like a good first draft

That probably solves your use-case, but I think this API is a bit awkward and not the most flexible either.

Reading the docs, it's not so clear to me what versionPrefix even is 😅

I'd prefer if we worked on designing the API we want first before doing the implementation.

For now, I think this API is more flexible than yours and less confusing:

[
  "@docusaurus/plugin-content-docs",
  {
    id: "ios",
    path: "./ios-docs/v-next",
    versionPath: ({version}) => `./ios-docs/v-${version.toLowerCase().replace(".","-"}`,
  },
];

Note: we already have a version config map so we could also reuse it to allow configuring the fs path?

There's a bit of confusion between version route path and fs path unfortunately 🤪

See https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#ex-config

module.exports = {
  plugins: [
    [
      '@docusaurus/plugin-content-docs',
      {
        path: 'docs',
        versions: {
          current: {
            path: 'ios-2.0.0',
          },
          '1.0.0': {
            path: 'ios-1.0.0',
          },
        },
      },
    ],
  ],
};

We should discuss the tradeoffs of various design options we have (probably in the other issue so others can participate) and agree on something before implementing it.

@Jersyfi
Copy link
Author

Jersyfi commented Apr 24, 2023

Closing the PR as there is no time for further changes.

@Jersyfi Jersyfi closed this Apr 24, 2023
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.

3 participants