Skip to content

Show profile of all contributors to a doc page #6218

Open

Description

@pranay01

Have you read the Contributing Guidelines on issues?

Description

More details here
#6194 (comment)

Has this been requested on Canny?

No response

Motivation

We want to show the picture of contributors to our docs so that users get more motivation to contribute to the doc

API design

No response

Have you tried building it?

No

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.

Activity

  1. added
    feature
    status: needs triage
    on Dec 29, 2021
  2. removed
    status: needs triage
    on Dec 29, 2021
  3. Josh-Cena commented on Dec 29, 2021

    @Josh-Cena
    Collaborator

    So I think displaying the pictures of all contributors is going to be too opinionated. However, we can do this:

    • Instead of including the last update author & time, we include all authors and their last update timestamps in the metadata;
    • You can wrap the doc container component to render the list of authors beneath the main content, e.g. by querying the GitHub API and getting their profile pictures.
  4. Josh-Cena commented on Dec 30, 2021

    @Josh-Cena
    Collaborator

    @slorber Let's talk about how the API will look like. Our DocMetadata type has the shape:

    type DocMetadataBase = LastUpdateData & {
      id: string;
      version: VersionName;
      title: string;
      //...
    };

    Should we add another field

    type NewDocMetadataBase = DocMetadataBase & {
      updateHistory: Array<{author: string, time: number, formattedTime: string}>
    }

    to the metadata but preserve the existing lastUpdatedAt and lastUpdatedBy metadata (make it safe for existing swizzled components & works well with existing options showLastUpdate*), or should we release this as a breaking change, change LastUpdateData to a generic UpdateHistory field, and move the determination of what to display to the theme side?

  5. slorber commented on Dec 30, 2021

    @slorber
    Collaborator

    I'd rather have an updateHistory breaking change instead of duplicating fields

    Note it seems looking up for the git history might have performance implications, we can try this on our own site first maybe and see, eventually providing an option to control how much we look back into the history. Is it worth it to include all history entries? Probably not, as that would lead to multiple times the same author, so it's not really an history anymore but rather the last unique users that updated a doc.

    Also the git author is a string, and it does not necessarily match your github username (in your case it's author: "Joshua Chen" => I guess GitHub is matching on the email too, so we probably want to include the user email in this author type.

  6. Josh-Cena commented on Dec 30, 2021

    @Josh-Cena
    Collaborator

    Yes, we need to figure out how GitHub matches git usernames with users. For a while I used username Josh-Cena, and my avatars etc. are still loaded correctly, so I think email also plays a part.

    About duplicated authors, I don't know if the full history is useful to keep, but in any case we can first go with filtering out unique author names

  7. slorber commented on Dec 30, 2021

    @slorber
    Collaborator

    This command does not seem too slow to run locally: git log --format=%ct,%an,%ae 🤷‍♂️ but it's hard to tell for a lot of files.

    Maybe we should first write a way to log lifecycle execution duration of all plugins to be able to measure the impact?

    About duplicated authors, I don't know if the full history is useful to keep, but in any case we can first go with filtering out unique author names

    That would also be a lot of data to send to the frontend for each file, probably not worth it or at least not something to do by default

  8. Josh-Cena commented on Dec 30, 2021

    @Josh-Cena
    Collaborator

    Isn't this data tree-shakable if unused?

  9. slorber commented on Dec 30, 2021

    @slorber
    Collaborator

    Isn't this data tree-shakable if unused?

    If this is imported/required it won't be tree-shaked even if it's not rendered

    IE if it's part of docs metadata it will add weight, so you'd rather find a way to limit the json size.

    It's also possible to pass the component an optional json module as props, but that's quite similar in terms of tradeoffs anyway

  10. Josh-Cena commented on Feb 10, 2022

    @Josh-Cena
    Collaborator

    From #3592, the following would be helpful:

    • ability to specify maximum number of last contributors from 1 to 5 (hardcoded: 1)
    • ability to specify the handle by which user is represented (hardcoded: name + surname)
      • as possible value it would be nice to have GitHub username, email or one of names used alone
    • ability to display user avatar or profile picture from GitHub (or Gravatar) with a nice fallback
  11. TheCatLady commented on Feb 10, 2022

    @TheCatLady
    Contributor

    Yes, we need to figure out how GitHub matches git usernames with users. For a while I used username Josh-Cena, and my avatars etc. are still loaded correctly, so I think email also plays a part.

    GitHub doesn't match on username at all, only email address (of which a GitHub user can have multiple associated with their account): https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-user-account/managing-email-preferences/setting-your-commit-email-address

  12. changed the title [-]Show profile of all contributors to a doc page in docusaurus[/-] [+]Show profile of all contributors to a doc page[/+] on Mar 25, 2022
  13. added
    domain: content plugin
    on Mar 29, 2022
  14. osamajandali commented on Aug 16, 2022

    @osamajandali

    I've mocked that in a UI design..
    image
    We can get the last 3-7 contributor and have the others on request when clicking on "N contributors"

  15. tobiasbueschel commented on Jan 28, 2023

    @tobiasbueschel

    I've mocked that in a UI design..

    Love the mockup, great work @osamajandali 👏 Are you thinking that the pop-up window would also indicate who was the original creator of the page and timestamps when contributions were made?

    I also wanted to ask if anyone has already started implementing this? And whether it would become part of core docusaurus or a standalone module instead?

  16. atar-axis commented on Oct 17, 2023

    @atar-axis

    Is this still under development? We would love that too!

  17. milldr commented on Dec 28, 2023

    @milldr

    👍 also interested in this feature

  18. hanarotg commented on Feb 13, 2024

    @hanarotg

    any updates? I'm looking forward to this feature

  19. slorber commented on Feb 13, 2024

    @slorber
    Collaborator

    Technically this can now be implemented in userland thanks to the v3.1 parseFrontMatter hook:
    https://docusaurus.io/blog/releases/3.1#parsefrontmatter-hook

    It notably allows you to automatically add a frontMatter.authors field to your docs
    (in case defining the list of authors manually is not an option)

    async function getAuthors(filePath: string) {
      // Do whatever you want here to create a list of authors for each file
      // you can read Git history if you want, or any other source
      return [
        {name: "Seb",picture: "https://github.com/slorber.png"},
        {name: "Joshua",picture: "https://github.com/Josh-Cena.png"}
      ]
    } 
    
    const config: Config = {
      markdown: {
        parseFrontMatter: async (params) => {
          const result = await params.defaultParseFrontMatter(params);
          const authors = await getAuthors(params.filePath);
          return {
            ...result,
            frontMatter: {
              ...result.frontMatter,
              authors,
            }
          }
        }
      },
    };
    
    export default config;

    Then you can swizzle the doc component you want and render that front matter:

    yarn docusaurus swizzle @docusaurus/theme-classic DocItem/Footer --wrap --typescript

    import React from 'react';
    import Footer from '@theme-original/DocItem/Footer';
    import type FooterType from '@theme/DocItem/Footer';
    import type { WrapperProps } from '@docusaurus/types';
    import { useDoc } from '@docusaurus/theme-common/internal';
    
    type Props = WrapperProps<typeof FooterType>;
    
    export default function FooterWrapper(props: Props): JSX.Element {
      const doc = useDoc();
    
      const authors = (doc.frontMatter as any).authors as {
        name: string;
        picture: string;
      }[];
    
      return (
        <>
          <div style={{marginTop: 20, marginBottom: 20}}>
            Authors:
            <ul>
              {authors.map((author, i) => (
                <li key={i} style={{display: "flex",flexDirection: "row", alignItems: "center", padding: 5}}>
                  <img
                    src={author.picture}
                    style={{ width: 40, height: 40, borderRadius: 40,  marginRight: 10}}
                  />
                  <span>{author.name}</span>
                </li>
              ))}
            </ul>
    
          </div>
          <Footer {...props} />
        </>
      );
    }

    Result:

    CleanShot 2024-02-13 at 11 43 58

    Runnable sandbox: https://stackblitz.com/edit/github-revkph?file=src%2Ftheme%2FDocItem%2FFooter%2Findex.tsx,docusaurus.config.ts


    Considering it is possible to implement in userland thanks to existing Docusaurus primitives, if we ever add this feature to Docusaurus core, this would only be an "opinionated shortcut" to the above solution.

    By opinionated I mean: limited to reading history on Git (and not other VCS), and displaying the authors in some predefined place such as the footer. This also means our opinions won't please everyone.

    For this reason, there's no reason to rush implementing this feature officially. I'd rather see a few successful userland implementations first, so that we understand the common denominator of the solutions, which would help us craft a good opinionated solution that please a maximum number of users.


    This is also related to #8657 which asks us to render some extra metadata in the blog post footer. Similarly parseFrontMatter can be used.

  20. uc-kywong commented on Jul 14, 2025

    @uc-kywong

    Why not create Authors component?

    Install npm i js-yaml-loader.

    We can reuse the blog/authors.yml.

    ky:
      name: keiyin-wong
      title: Software Engineer
      url: https://github.com/keiyin-wong
      image_url: https://github.com/keiyin-wong.png
      socials:
        github: keiyin-wong

    Create src/components/Authors/index.js

    import authorsGlobal from "js-yaml-loader!../../../blog/authors.yml";
    import React from "react";
    
    export default function Authors({ authors }) {
      if (!authors || authors.length === 0) {
        return <div style={{marginTop: 20, marginBottom: 20}}>No authors found.</div>;
      }
    
      // Filter authors based on the authors parameter (list of author keys)
      const filteredAuthors = authors.map(authorKey => {
        const authorData = authorsGlobal[authorKey];
        if (!authorData) {
          console.warn(`Author key "${authorKey}" not found in authors.yml`);
          return null;
        }
        return {
          key: authorKey,
          ...authorData
        };
      }).filter(Boolean); // Remove null entries
    
      if (filteredAuthors.length === 0) {
        return <div style={{marginTop: 20, marginBottom: 20}}>No valid authors found.</div>;
      }
    
      return (
        <div style={{marginTop: 20, marginBottom: 20}}>
          <b>Authors:</b>
          <div className={'row'}>
            {filteredAuthors.map((author, i) => (
              <div className={'col col--6'} key={i} style={{display: 'flex', alignItems: 'center'}}>
                <img
                  src={author.image_url}
                  style={{ width: 40, height: 40, borderRadius: 40,  marginRight: 10}}
                />
                <div>
                  <a href={author.url} target={"_blank"}>{author.name}</a>
                  <div><small>{author.title}</small></div>
                </div>
              </div>
            ))}
          </div>
        </div>
      );
    }

    Register it in src/theme/MDXComponents.js

    import React from 'react';
    // Import the original mapper
    import MDXComponents from '@theme-original/MDXComponents';
    import Authors from '@site/src/components/Authors';
    
    export default {
      // Re-use the default mapping
      ...MDXComponents,
      Authors
    };

    Use it in the mdx, different topics different authors

    <Authors authors={["ky"]} />
    
    # Docusaurus Documentation
    
    ## Section A1
    
    <Authors authors={["ky"]} />
    
    ```java
    public static void main(String[] args) {
        System.out.println("Hello, Docusaurus!");
    }
    ```
    
    This is a simple Java program that prints "Hello, Docusaurus!" to the console.
    
    ---
    
    ## Section A2
    
    <Authors authors={["ky"]} />
    
    ```javascript
    function greet() {
        console.log("Hello, Docusaurus!");
    }
    greet();
    ```
    
    This is a simple JavaScript function that prints "Hello, Docusaurus!" to the console.
    
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain: content pluginfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions