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: doc tags (same as blog tags) #3646

Merged
merged 35 commits into from
Aug 19, 2021
Merged

Conversation

isaac-philip
Copy link
Contributor

@isaac-philip isaac-philip commented Oct 27, 2020

Note: PR completed by @slorber

Breaking changes

  • Some theme components are refactored and you may need to upgrade/re-swizzle them
  • Some classNames have been refactored a bit
  • Blog tag custom permalinks are prefixed by /blog/tags/<myTag> (let me know if you have an use-case for unprefixing them, we can restore that behavior if really needed)

Motivation

Implement doc tags, similar to existing blog tags

  • Allow tags frontmatter
  • Create tag list page, ordered by letter
  • Create tag doc list page, displaying docs with a given tag
  • Add inline tag list to the doc page footer (above edit/updatedAt)
  • The docs tags page do not display any sidebar: this is expected because there is 0-n sidebar we could display for a versioned tag list

image

image

image

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

test + dogfood/peview

- Addition of plugin-content-docs

- Addition of DocTagsListPage in `docusaurus-theme-classic`

! Error exists for this commit towards the theme aspect and help required.

Commit towards facebook#3434
@facebook-github-bot
Copy link
Contributor

Hi @isaac-philip!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, 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.

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

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 27, 2020

✔️ [V2]

🔨 Explore the source changes: 58367bb

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

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

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.

I've commited various changes to your branch to help you get started.
My code is not production ready nor tested, but it's mostly to help you figure things out and create a nice PR.

I only handled the creation of the tas list page, you can proceed to create one specific page per tag in the same way.

Note each version has a:

  • set of docs
  • a tag list
  • a page per tag linking to the docs having it in the same version

Let me know if you need more help

Also, don't forget to sign the FB CLA.

Comment on lines 275 to 283
const tagsProp = mapValues(loadedVersion.tags, (tagValue) => ({
name: tagValue.name,
permalink: tagValue.permalink,
count: tagValue.docIds.length,
}));
const tagsPropPath = await createData(
`${docuHash(`tags-list-${loadedVersion.versionName}-prop`)}.json`,
JSON.stringify(tagsProp, null, 2),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is how you create a component prop as json object (should rather be moved to props.ts and have an explicit type)

packages/docusaurus-plugin-content-docs/src/index.ts Outdated Show resolved Hide resolved

async function createTagPage(tag: VersionTag) {
// TODO
console.log(`todo createTagPage for tag=${tag.name}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo: do something similar to create one page per tag

@@ -3,6 +3,7 @@ id: introduction
title: Introduction
description: Docusaurus was designed from the ground up to be easily installed and used to get your website up and running quickly.
slug: /
tags: [test-tag, myOtherTag]
Copy link
Collaborator

Choose a reason for hiding this comment

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

just an example

export type LoadedVersion = VersionMetadata & {
versionPath: string;
mainDocId: string;
docs: DocMetadata[];
tags: VersionTags;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the tags are per version, it's not just a global set of tags for all the docs of the site, there is one set of tag per version

website/docusaurus.config.js Outdated Show resolved Hide resolved
@slorber slorber marked this pull request as draft October 28, 2020 19:28
@slorber slorber changed the title [v2] tags to doc, same as tags to blog - [IN PROGRESS] feat(v2): doc tags (same as blog tags) Oct 28, 2020
@slorber
Copy link
Collaborator

slorber commented Oct 29, 2020

So finally was able to get a deploy preview to work (after fixing the bootstrap theme).

Note:

As you can see, each version should have its set of tags. "current" version has 2 tags, but alpha 66 do not have any tag. This is because only docs of "current" version have been tagged

@isaac-philip
Copy link
Contributor Author

Hey @slorber , thanks for this.
it is indeed helpful as I just had a glance.
Should help fix things this weekend and have it ready.
will comment 4 more queries if any.

@slorber
Copy link
Collaborator

slorber commented Nov 13, 2020

great

let me know if you need help to complete it

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 15, 2020
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

- individual doc tag page added to show docs for that specific tag
@github-actions
Copy link

github-actions bot commented May 27, 2021

⚡️ Lighthouse report for the changes in this PR:

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

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

@isaac-philip
Copy link
Contributor Author

still WIP but nearing a review,

next steps is to,

  • get all links

  • remove an es-lint error when committing

  • add the same page to bootstrap theme

  • add the content for the doc-page

@isaac-philip
Copy link
Contributor Author

Done with the two top items,

  1. get all links

  2. remove an es-lint error when committing

  3. add the same page to bootstrap theme

  4. add the content for the doc-page

@isaac-philip
Copy link
Contributor Author

Hello @slorber , require some guidance here please.

for now have the page as this
Screenshot 2021-06-14 at 8 13 32 PM
and need to make it like this,
Screenshot 2021-06-14 at 8 13 46 PM

that means the createTagPage within docusaurus-plugin-content-docs would need to save more information than current below, or can we reuse some existing files?

{
  "name": "myothertag",
  "permalink": "/docs/tags/my-other-tag",
  "docIds": [
    "deployment",
    "introduction"
  ],
  "allTagsPath": "/docs/tags"
}

that is more info in the docIds to be used in similar way how the image two renders using this below code,

<div className="margin-vert--xl">
      {items.map(({content: BlogPostContent}) => (
        <BlogPostItem
          key={BlogPostContent.metadata.permalink}
          frontMatter={BlogPostContent.frontMatter}
          metadata={BlogPostContent.metadata}
          truncated>
          <BlogPostContent />
        </BlogPostItem>
      ))}
</div>

Please guide, I checked but the DocContent item props etc I cannot figure out from where to utilize it?

@isaac-philip
Copy link
Contributor Author

@nam-hle can you suggest please?

@nam-hle
Copy link
Contributor

nam-hle commented Jun 27, 2021

Not sure what you need. Please explain more about your situation, perhaps because of my limited knowledge about the codebase.

# Conflicts:
#	packages/docusaurus-plugin-content-docs/src/docs.ts
#	packages/docusaurus-plugin-content-docs/src/index.ts
#	packages/docusaurus-plugin-content-docs/src/types.ts
#	packages/docusaurus-plugin-content-docs/src/versions.ts
#	website/docusaurus.config.js
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Aug 18, 2021
@slorber slorber added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Aug 18, 2021
@slorber slorber marked this pull request as ready for review August 18, 2021 17:16
@slorber
Copy link
Collaborator

slorber commented Aug 18, 2021

Thanks @isaac-philip, I've completed your PR and made some useful cleanups/refactors to avoid code duplication and swizzle theme comps more easily.

Unless someone has any comment I'll merge it tomorrow.

@isaac-philip
Copy link
Contributor Author

thanks @slorber !!

😇

@slorber slorber changed the title feat(v2): doc tags (same as blog tags) feat: doc tags (same as blog tags) Aug 19, 2021
@slorber slorber merged commit f9c79cb into facebook:main Aug 19, 2021
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: breaking change Existing sites may not build successfully in the new version. Description contains more details. 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

6 participants