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

Only show authors' email addresses if so configured in git-authors #6494

Merged
merged 1 commit into from Dec 12, 2023

Conversation

fghaas
Copy link
Contributor

@fghaas fghaas commented Dec 12, 2023

Honour the git-authors plugin's option to render the authors' names as links pointing to their email address:

  • If the git-authors plugin is enabled and its show_email_address option is not set, or is set to true1, render the author's name as a mailto: link.
  • If the git-authors plugin is enabled and its show_email_address option is set to false, render the author's name in plain text with no link.
  • If the git-authors plugin is not enabled (or not installed), don't show author information.

Footnotes

  1. The current default for show_email_address in the plugin is true. If that default ever changes in the future, then the logic for showing the mailto: link would change accordingly.

@fghaas fghaas changed the title show email addresses Only show authors' email addresses if so configured in git-authors Dec 12, 2023
Copy link
Owner

@squidfunk squidfunk left a comment

Choose a reason for hiding this comment

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

Minor cosmetic changes, otherwise good!

<a href="mailto:{{ author.email }}">
{{- author.name -}}
</a>
{%- if show_email_address %}<a href="mailto:{{ author.email }}">{{- author.name -}}</a>{%- else -%}{{- author.name -}}{% endif -%}
Copy link
Owner

Choose a reason for hiding this comment

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

This is not really readable. Please adhere to the surrounding formatting, so move things onto separate lines. There's also no need to put show_email_address in a separate variable I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that, updated.

@@ -54,9 +55,11 @@
</span>
<nav>
{% for author in authors %}
<a href="mailto:{{ author.email }}">
{%- if git_authors.config.show_email_address %}
Copy link
Owner

Choose a reason for hiding this comment

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

One more spot: We don't need whitespace control here. Please remove the - on all tags that you added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that include the one instance of {{- author.name -}} that I duplicated? In other words, should the hyphens be dropped from that one as well?

Copy link
Owner

@squidfunk squidfunk Dec 12, 2023

Choose a reason for hiding this comment

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

Yes. The following line is the only line where this is necessary, because we want the , to stick to the author name, but this is a line you did not touch, which is why I meant to remove them from all lines you touched.

{%- if loop.revindex > 1 %}, {% endif -%}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I am not so sure about that. If I drop all instances of - that I introduced here, then if show_email_address is true, I end up with

    <nav>
      
        
          <a href="mailto:john.doe@example.com">John Doe</a>
        , 
        
          <a href="mailto:jane.doe@example.com">Jane Doe</a>
        
    </nav>

And I'm pretty sure we don't want that comma on its own line, because it gets rendered as

John Doe , Jane Doe

... and the thus-appearing extra whitespace before the comma is extraneous.

As the patch is currently proposed, what we end up with is

    <nav>
        
          <a href="mailto:john.doe@example.com">John Doe</a>, 
          <a href="mailto:jane.doe@example.com">Jane Doe</a>
    </nav>

... which is what we want, I think. Would you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed 7f0cdd2 which is the most minimal patch that I can think of, with no whitespace management added at all. But that introduces the extra space before the comma, no matter if we're rendering a link or not. So please do not merge that as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That fixes things only for show_email_address: false; but still breaks (i.e. introduces the extraneous whitespace) for the default of show_email_address: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does the right thing, regardless of how show_email_address is set:

       {% for author in authors %}
+        {%- if git_authors.config.show_email_address %}
         <a href="mailto:{{ author.email }}">
           {{- author.name -}}
         </a>
+        {%- else -%}
+          {{- author.name -}}
+        {% endif -%}
         {%- if loop.revindex > 1 %}, {% endif -%}
       {% endfor %}

Okay if I update my topic branch with that?

Copy link
Owner

@squidfunk squidfunk Dec 12, 2023

Choose a reason for hiding this comment

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

I'm sure you don't need all of those whitespace control characters, but okay, let's keep the whitespace control. I'll look into in the future. We should keep whitespace control to a minimum, and only use it where absolutely necessary.

Copy link
Contributor Author

@fghaas fghaas Dec 12, 2023

Choose a reason for hiding this comment

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

I sympathise with that, but if you instruct me to "remove the - on all tags that [I] added" and simultaneously "we want the , to stick to the author name", I can only do one xor the other. :)

Copy link
Owner

Choose a reason for hiding this comment

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

Haha yeah, sorry for that. Entirely my fault. I'm sorry for the back and forth. Is it okay to merge now?

Honour the git-authors plugin's setting to render the authors' names
as links pointing to their email address:

* If the git-authors plugin is enabled and its show_email_address
  option is not set, or is set to true, render the author's name as a
  "mailto:" link.
* If the git-authors plugin is enabled and its show_email_address
  option is set to false, render the author's name in plain text with
  no link.
* If the git-authors plugin is not enabled (or not installed), don't
  show author information.
fghaas added a commit to fghaas/cleura-docs that referenced this pull request Dec 12, 2023
What will probably become mkdocs-material 9.5.3 gives us the ability
to again render authors' names without them turning into "mailto:"
links. Thus, require that as the minimum version. Since it is now
mkdocs-material that natively renders author information, we no longer
need the theme override for main.html.

References:
https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-authors
squidfunk/mkdocs-material#6494
@fghaas
Copy link
Contributor Author

fghaas commented Dec 12, 2023

Is it okay to merge now?

Well I'd still been trying to wrap my head around how to add tests for this, hence the Draft mode. I've looked at what I think is the relevant part of the docs, but most of those recommendations don't seem to apply here since neither mkdocs-material's own docs nor the examples repo use git-authors.

I've tested it against the repo I co-maintain (citynetwork/docs#257) and there all our tests pass. Is that sufficient?

@squidfunk
Copy link
Owner

Yes, that should be fine. Thanks!

@squidfunk squidfunk marked this pull request as ready for review December 12, 2023 16:34
@squidfunk squidfunk merged commit 9b98c77 into squidfunk:master Dec 12, 2023
fghaas added a commit to fghaas/cleura-docs that referenced this pull request Dec 12, 2023
What will probably become mkdocs-material 9.5.3 gives us the ability
to again render authors' names without them turning into "mailto:"
links. Thus, require that as the minimum version. Since it is now
mkdocs-material that natively renders author information, we no longer
need the theme override for main.html.

References:
https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-authors
squidfunk/mkdocs-material#6494
fghaas added a commit to fghaas/cleura-docs that referenced this pull request Dec 25, 2023
mkdocs-material 9.5.3 gives us the ability to again render authors'
names without them turning into "mailto:" links. Thus, require that as
the minimum version. Since it is now mkdocs-material that natively
renders author information, we no longer need the theme override for
main.html.

References:
https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-authors
squidfunk/mkdocs-material#6494
@fghaas fghaas deleted the show-email-addresses branch December 29, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants