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

Enhancement: Option to remove/customize repo counts #2307

Closed
4 tasks done
blakegearin opened this issue Feb 17, 2021 · 6 comments
Closed
4 tasks done

Enhancement: Option to remove/customize repo counts #2307

blakegearin opened this issue Feb 17, 2021 · 6 comments
Labels
change request Issue requests a new feature or improvement

Comments

@blakegearin
Copy link

blakegearin commented Feb 17, 2021

  • I've read the [contribution guidelines][1] and agree with them

I want to suggest an idea and checked that ...

  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... the documentation does not mention anything about my idea
  • ... there are no open or closed issues that are related to my idea

Description

By default, star & fork counts are displayed on sites where repo_url is defined in mkdocs.yml for GitHub and GitLab repositories that are open-source.

I'd like to have the ability to turn off the counts.

Use Cases

  • Could remove a call, helping with load times
  • It would prevent having to make a repository private (only way currently to remove counts)
    • Update: Not a viable option for GitHub Free users
  • I think my sites look cleaner without the counts (subjective)
  • Sites with 0 stars·0 forks are sad (subjective) 🙁

Screenshots / Mockups

# mkdocs.yml

repo_name: owner/project
repo_url: https://github.com/owner/project
repo_counts: false
edit_uri: ''

Open to other flag names besides repo_counts 🙂

Looks like this section is now changed in Insiders. Perhaps it would be low effort while doing this enhancement to add more options besides on/off, such as specifying a subset of counts:

# mkdocs.yml

repo_name: owner/project
repo_url: https://github.com/owner/project
repo_counts: 
  - tag
  - stars
edit_uri: ''
@squidfunk
Copy link
Owner

squidfunk commented Feb 18, 2021

Thanks for suggesting! Most users seem to love this feature, so I think it won't make sense to introduce an option to disable it. However, if many people need it, we can add a flag. Let's let the issue sit here for a while and see if a significant fraction of users want this feature.

For the time being, you can use template overrides to achieve the same thing. Using Material 7 beta (#2290), you can patch the partials/source.html template and just remove the data-md-component attribute, which is used to mount the loading logic. Furthermore, loading time is not impacted, as the data is fetched after DOMContentLoaded and is cached in session storage for subsequent page views.

@squidfunk squidfunk added the change request Issue requests a new feature or improvement label Feb 18, 2021
@blakegearin
Copy link
Author

For the time being, you can use template overrides to achieve the same thing. Using Material 7 beta (#2290), you can patch the partials/source.html template and just remove the data-md-component attribute, which is used to mount the loading logic.

Thanks for specifying this! I found that data-md-component and class="md-source" had to be removed. The class being removed caused the text size to shrink, so had to add the style back

GitHub: raw source.html
Mine (working):

<!-- theme/source.html -->

{% import "partials/language.html" as lang with context %}

<a
  href="{{ config.repo_url }}"
  title="{{ lang.t('source.link.title') }}"
  style="display: block; font-size: .65rem; line-height: 1.2; white-space: nowrap; -webkit-backface-visibility: hidden; backface-visibility: hidden; transition: opacity 250ms;"
>
  <div class="md-source__icon md-icon">
    {% set icon = config.theme.icon.repo or "fontawesome/brands/git-alt" %}
    {% include ".icons/" ~ icon ~ ".svg" %}
  </div>
  <div class="md-source__repository">
    {{ config.repo_name }}
  </div>
</a>
# For reference, this implementation requires custom_dir in mkdocs.yml

theme:
  name: 'material'
  custom_dir: 'theme'

Regarding one of my original points:

It would prevent having to make a repository private (only way currently to remove counts)

Making a repo private isn't feasible for GitHub Free users, as it deletes their site 🙁

GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

Source: GitHub Docs

So the implementation outlined is the only current way to remove it

@squidfunk
Copy link
Owner

squidfunk commented Feb 19, 2021

@blakegearin when you're using 7.0.0 (i.e. the latest master), removing data-md-component is sufficient, you don't have to remove .md-source. I just tested this again, and the repository metrics are not loaded. From 7.0.0 on, all JavaScript logic is tied to data-md-* attributes, not to classes.

@blakegearin
Copy link
Author

Ah, yes, I was able to upgrade from 6.2.8 and now I'm seeing that behavior line up. Thanks!

For anyone wanting to do the same thing here are the commands I had to run:

# check version
python3 -m pip show mkdocs-material

# upgrade to latest commit
python3 -m pip install --upgrade git+https://github.com/squidfunk/mkdocs-material.git

@blakegearin blakegearin changed the title Enhancement: Option to remove repo counts Enhancement: Option to remove/customize repo counts Feb 19, 2021
@squidfunk
Copy link
Owner

I decided not to go down this road for now. There doesn't seem to be a huge interest from other users and disabling this logic is as easy as overriding the partial and removing the data-md-component attribute. For this reason, I'm closing this issue. If in the future this proofs to be crucial, we can revisit it.

llarsson added a commit to elastisys/welkin that referenced this issue Feb 15, 2022
As per the linked comment, removes the GitHub star counter, to avoid an
unnecessary call to the GitHub API.

squidfunk/mkdocs-material#2307 (comment)
@AirTechWick
Copy link

Trying to follow along #2307 (comment) I seem to be having a little trouble setting this up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change request Issue requests a new feature or improvement
Projects
None yet
Development

No branches or pull requests

3 participants