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

Add a placeholder to inject tags into <head> #345

Open
tastapod opened this issue Oct 18, 2023 · 4 comments
Open

Add a placeholder to inject tags into <head> #345

tastapod opened this issue Oct 18, 2023 · 4 comments

Comments

@tastapod
Copy link

tastapod commented Oct 18, 2023

I have two use cases for meta tags:

  • making a page hidden: <meta name="robots" content="noindex,nofollow">
  • adding non-Google analytics: <script src="https://cdn.usefathom.com/script.js" ...></script>

The simplest solution would be to have something like an empty partials/custom-head.html that the theme invokes in the <head> part of the _default/baseof.html template.

Some themes put placeholders everywhere, which provides a clean way to customise the theme without having to copy and edit the whole baseof.html, which might change dramatically between versions of the theme.

I am happy to roll a PR if you are interested.

@Vimux
Copy link
Owner

Vimux commented Oct 27, 2023

The simplest solution would be to have something like an empty partials/custom-head.html that the theme invokes in the part of the _default/baseof.html template.

I am against empty partials. Yes, other themes use them, but it doesn't seem preferable. We need to look at other solutions: it could be a block, putting the head below the title in a separate partial, or something else. I can say for sure that an empty partial solution does not seem sensible.

  • making a page hidden: <meta name="robots" content="noindex,nofollow">
  • adding non-Google analytics: <script src="https://cdn.usefathom.com/script.js" ...></script>

Speaking of analytics, why not just override the _internal analytics template? Yes, the solution is sub-optimal to say the least, but it works. It is unlikely that you will be using Google Analytics anyway. Noindex is a bit more complicated because there's no suitable template, so in this case you'll probably have to override _internal/schema.html. Or put them all in one.

Choosing the right way requires careful consideration. It does not seem sensible to use an empty partial. Rewriting one of the internal templates is suggested as a quick solution.

@tastapod
Copy link
Author

I don't understand your reluctance to have deliberate seams in a template so your users can adapt it to their needs.

Your counter is to override completely inappropriate templates, which you admit is a hack.

I am currently overriding the Twitter template to inject HTML tags, which we both agree is a terrible idea but is the only option you are giving me.

Please rethink your arbitrary view on placeholder partials for customising content, which is the entire point of user overrides.

In the meantime I am left with two options:

  1. Override a random unrelated internal partial, which sucks.
  2. Copy the entire page to edit two lines, which means I miss out on any future improvements you make to the template.

Or of course 3, use a different template, which I would rather not do!

Thanks,
Daniel

@Vimux
Copy link
Owner

Vimux commented Nov 1, 2023

Your counter is to override completely inappropriate templates, which you admit is a hack.

I never said that. For me, as a maintainer, an empty layout file as a head section extender is also a sub-optimal solution. I've also suggested two alternatives, but this is not an exhaustive list. Ideally, the plan is to complete a list, experiment, and then choose the one solution that suits best.

And just as a quick solution, as clearly mentioned at the end of the previous comment, I suggested overriding the internal template.

I am currently overriding the Twitter template to inject HTML tags, which we both agree is a terrible idea but is the only option you are giving me.

Again, I never said that. And file selection is important. The twitter_cards.html file gets updated quite often.

@tastapod
Copy link
Author

tastapod commented Nov 1, 2023

I don't understand what is "suboptimal" about having clearly signposted places for your users to customise key parts of an HTML page, using an idiom that is common in other Hugo templates.

Still, I'm not going to argue, it's your template and you don't want to provide a common facility that your users will find useful. I think it is great that you are doing the work to create a template in the first place.

I will look for another template that makes this easier for me, which is a shame because really like your widgets idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants