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

Is it possible to also make the meta tags in the theme pluggable as well? #530

Closed
simkimsia opened this issue Mar 24, 2022 · 10 comments
Closed
Labels
enhancement New feature or request

Comments

@simkimsia
Copy link
Contributor

Describe the problem/need and solution

Context
I need to add a different HTML meta head element because i am not using google analytics. I want to use plausible

Problem / Idea
Allow theme user to plugin custom meta head element as and when they need it?

Solution
Perhaps follow #470 and make it more pluggable?

Benefit
There are several options available for people to do this:

  1. make their own theme (very drastic)
  2. fork this theme and add their own hardcoded meta element (less drastic than 1 but still pretty drastic)
  3. allow tailoring of this theme via a pluggable design (i prefer this)

This would benefit the people trying to have more tailoring within the chosen sphinx-book-theme.

  1. requires maintenance
  2. also require maintenance to at least make sure fork keeps pace with upstream
  3. least intrusive and keeps flexibility scoped to just meta head elements

Guide for implementation

Just allow users to write their own html meta and the theme just inserts it. that way, minimum effort on dev and maximum flexibility

Tasks and updates

No response

@simkimsia simkimsia added the enhancement New feature or request label Mar 24, 2022
@welcome
Copy link

welcome bot commented Mar 24, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@choldgraf
Copy link
Member

Would sphinxext-opengraph work for you? That's how I've done custom metadata before...

@pradyunsg
Copy link
Member

You can also explicitly set metadata using .. meta:: on each page.

@simkimsia
Copy link
Contributor Author

Thank you @choldgraf and @pradyunsg I will start with pradyunsg suggestion because it seems less intrusive. so the meta:: is in the frontmatter of each .md page? assume i am using jupyter-book.

Any documentation on this? I. tried to search by metadata but don't find it. https://jupyterbook.org/start/create.html?highlight=metadata

separately i realized my question was wrongly phrased

I now realized the desire to swap out google analytics with plausible means i need to insert a script tag not a meta tag in head. Apologies. Directionally, my question is the same. How do i insert custom elements in the head such as a different analytics provider script tag?

@pradyunsg
Copy link
Member

pradyunsg commented Mar 25, 2022

What exactly do you want to inject?

See https://pradyunsg.me/furo/customisation/injecting/, which is from the documentation of a different theme -- it discusses the mechanisms that Sphinx provides for injecting code into any arbitrary theme.

@choldgraf
Copy link
Member

Also if you're using jupyter book, you can inject scripts via these docs too https://jupyterbook.org/advanced/html.html#custom-css-or-javascript

@simkimsia
Copy link
Contributor Author

i need to insert a javascript snippet in the head. Not to add new javascript code per se. So the injecting custom-css-or-javascript doesn't seem to be applicable. i might be wrong of course

Also I read the custom code injecting for furo, I'm sorry to say I'm at a loss as to how I can use that for my case.

image

@simkimsia
Copy link
Contributor Author

simkimsia commented Mar 26, 2022

According to this https://www.sphinx-doc.org/en/master/templating.html#working-with-the-builtin-templates there's this thing called extrahead which appears to be how sphinx allows additional stuff into the head element.

I know sphinx-book-theme inherits (?) from pydata-sphinx-theme so i found this https://github.com/pydata/pydata-sphinx-theme/blob/3c11db8b4e4b764a5bdb2460a44a7f68cb54e26b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html#L11

Is there a way to add more script tags into the extrahead?

@simkimsia
Copy link
Contributor Author

Would it be better if i fork this theme to add the javascript snippet?

@simkimsia
Copy link
Contributor Author

Closing this to consolidate under executablebooks/meta#726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants