Skip to content

Conversation

@FabioRosado
Copy link
Contributor

Hello, first of all, thank you for the awesome theme!

This PR is an attempt at a fix #385 so we can support the new google ids if they are in use. Please let me know if this looks good or would you rather change the if logic?

I need to look at the tests that we currently have in the project. Once I understand what is happening, I will mark this PR as ready for review 😄 👍

@FabioRosado FabioRosado marked this pull request as draft April 14, 2021 21:07
@choldgraf
Copy link
Collaborator

At a first glance this looks great to me :-)

@jorisvandenbossche
Copy link
Member

Yes, looks good to me as well

@OriolAbril OriolAbril mentioned this pull request Apr 17, 2021
6 tasks
@FabioRosado
Copy link
Contributor Author

Thank you for your comments! I've added two tests, but they are rather dependent on the place where the script will be placed in the page. Hopefully this will be alright, if not I can find a different way to do it or if you have a better idea 😄

@choldgraf
Copy link
Collaborator

I think this looks great, wanna mark your PR as "ready for review" when you think it's good to go?

@jorisvandenbossche I'm curious what you think about putting template logic like this into Python functions that we then call from the HTML template. In this way, we can test more coverage of functionality like this, because the codecov would catch the Python lines (while it won't catch the template lines)

@FabioRosado FabioRosado marked this pull request as ready for review April 17, 2021 17:30
@FabioRosado
Copy link
Contributor Author

Oops thank you for the comment forgot about that, marked it as ready now 😄
As you mention putting the logic in python functions I realised that you mentioned this in the issue, I can refactor this and do it just need to have a look how to do such (should be easy enough I take)

@choldgraf
Copy link
Collaborator

choldgraf commented Apr 17, 2021

In case it helps, check out here for where we do similar stuff w other functions:

context["generate_nav_html"] = generate_nav_html

And then it is called in the template here

{{ generate_nav_html("navbar", maxdepth=1, collapse=True, includehidden=True, titles_only=True) }}

@FabioRosado
Copy link
Contributor Author

Thank you @choldgraf for pointing me in the right direction. I've updated the PR with your suggestion, could I check with you if this is what you had in mind?

Initially, I tried to format the strings in a nicer way, but some were longer than 88 characters so some of them look a bit weird 😄

)
else:
script = (
"<script async "
Copy link
Collaborator

Choose a reason for hiding this comment

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

wanna just make these f-strings? like:

script = f"""
<script async ...>
  stuff
  {id}
  stuff
</script>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies for another push, I've missed this comment. That sounds good, the only issue is that the script will have a lot of white space on the final HTML page, but that should be alright

)
return align_options[align]

def generate_google_analytics_script(kind, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

what role does kind play here? I don't see it used (if unused, can we just remove and use a single arg for id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the comment, I was following the pattern when testing things and forgot to remove it. Your comment also made me realise that we don't really need kwargs here since we are passing the id only so thank you for that as well 😄

@choldgraf choldgraf changed the title Google analytics Support new+old Google analytics Apr 25, 2021
@choldgraf choldgraf merged commit c249adb into pydata:master Apr 25, 2021
@choldgraf
Copy link
Collaborator

This looks great, thanks very much @FabioRosado :-)

@FabioRosado FabioRosado deleted the google-analytics branch April 26, 2021 10:36
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.

Support new-style google analytics IDs

3 participants