Skip to content

feat: doc tags (same as blog tags) - #3646

Merged
slorber merged 35 commits into
meta:mainfrom
isaac-philip:docs_get_tags
Aug 19, 2021
Merged

slorber merged 35 commits into
meta:mainfrom
isaac-philip:docs_get_tags

Conversation

@isaac-philip

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

Copy link
Copy Markdown
Contributor

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 meta#3434
@facebook-github-bot

Copy link
Copy Markdown
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 [email protected]. Thanks!

@docusaurus-bot

docusaurus-bot commented Oct 27, 2020 •

Copy link
Copy Markdown
Contributor

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

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


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

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

Comment thread website/docs/introduction.md Outdated
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just an example

versionPath: string;
mainDocId: string;
docs: DocMetadata[];
tags: VersionTags;

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

Comment thread website/docusaurus.config.js 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

slorber commented Oct 29, 2020

Copy link
Copy Markdown
Collaborator

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

slorber commented Nov 13, 2020

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented May 27, 2021 •

Copy link
Copy Markdown

⚡️ 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@nam-hle can you suggest please?

@nam-hle

nam-hle commented Jun 27, 2021

Copy link
Copy Markdown
Contributor

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

slorber commented Aug 18, 2021

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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 meta:main Aug 19, 2021
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* [v2] tags to doc, same as tags to blog - [IN PROGRESS]

- 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 meta#3434

* docs: make tags list page work

* temp: disable onBrokenLinks

* theme bootstrap: create DocTagsListPage

* DocTagsPage added and functionality too

- individual doc tag page added to show docs for that specific tag

* Added all Docs Tags Link

* add some shared tag utils

* move tag tests to _dogfooding

* fix type

* fix some tests

* fix blog test

* refactor blog post tags handling

* better yaml tag examples

* better dogfood md files

* refactor and factorize theme tag components

* finish DocTagDocListPage

* Extract DocItemFooter + add inline tag list

* minor fix

* better typings

* fix versions.test.ts tests

* add tests for doc tags

* fix tests

* test toTagDocListProp

* move shared theme code to tagUtils

* Add new theme translation keys

* move common theme code to tagUtils + add tests

* update-code-translations should handle theme-common

* update french translation

* revert add translation

* fix pluralization problem in theme.docs.tagDocListPageTitle

* add theme component configuration options

* add more tags tests

* add documentation for docs tagging

Co-authored-by: slorber <[email protected]>
sparanoid pushed a commit to sparanoid/docusaurus that referenced this pull request Oct 12, 2026
* [v2] tags to doc, same as tags to blog - [IN PROGRESS]

- 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 meta#3434

* docs: make tags list page work

* temp: disable onBrokenLinks

* theme bootstrap: create DocTagsListPage

* DocTagsPage added and functionality too

- individual doc tag page added to show docs for that specific tag

* Added all Docs Tags Link

* add some shared tag utils

* move tag tests to _dogfooding

* fix type

* fix some tests

* fix blog test

* refactor blog post tags handling

* better yaml tag examples

* better dogfood md files

* refactor and factorize theme tag components

* finish DocTagDocListPage

* Extract DocItemFooter + add inline tag list

* minor fix

* better typings

* fix versions.test.ts tests

* add tests for doc tags

* fix tests

* test toTagDocListProp

* move shared theme code to tagUtils

* Add new theme translation keys

* move common theme code to tagUtils + add tests

* update-code-translations should handle theme-common

* update french translation

* revert add translation

* fix pluralization problem in theme.docs.tagDocListPageTitle

* add theme component configuration options

* add more tags tests

* add documentation for docs tagging

Co-authored-by: slorber <[email protected]>
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.

6 participants