hugo-theme-codex icon indicating copy to clipboard operation
hugo-theme-codex copied to clipboard

Make `baseof.html` more modular

Open kentnek opened this issue 5 years ago • 12 comments

I think we can make the baseof.html more modular by splitting into several partials that powerusers like me might modify, e.g. meta.html, favicon.html, styles.html, etc. you get the idea. Some examples are:

partials/base/title.html

This partial would hold the <title> element, for people to customize the website's title.

partials/base/favicon.html

Nowadays including a single favicon.ico is probably not enough for all devices. The best practice would be use a favicon generator to generate multiple sizes and a webmanifest file, so the icon would look crisp in all scenarios.

I personally use realfavicongenerator to help me prepare the icon package, and I'd put this chunk in baseof.html to configure:

<!-- Icons -->
<link rel="shortcut icon" href="{{ "favicon.ico" | relURL }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ "apple-touch-icon.png" | relURL }}">
<link rel="icon" type="image/png" sizes="192x192" href="{{ "favicon-192x192.png" | relURL }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ "favicon-32x32.png" | relURL }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ "favicon-16x16.png" | relURL }}">
<link rel="manifest" href="{{ "site.webmanifest" | relURL }}">
<link rel="mask-icon" href="{{ "safari-pinned-tab.svg" | relURL }}" color="#FF3DB4">
<meta name="theme-color" content="#ffffff">

If we have the partial favicon.html, I can just replace the existing line

<link rel="shortcut icon" type="image/png" href="/favicon.ico" />

with that chunk without needing to clone the baseof.html file.

kentnek avatar Jun 24 '20 08:06 kentnek

Yes I think this is a good solution for use cases I haven't thought about. Makes the theme more extensible.

jakewies avatar Jun 24 '20 13:06 jakewies

Okay I'll work on this then.

kentnek avatar Jun 24 '20 15:06 kentnek

While looking at docuapi I see that they have this cool concept of "hooks". Basically they are partials that are inserted at strategic locations. I'd personally create a post-end (end of post to add in custom comment widgets).

@jakewies if you like this idea too I can implement this along side this PR as they are both related to refactoring baseof.html.

kentnek avatar Jul 14 '20 16:07 kentnek

Definitely!

jakewies avatar Jul 14 '20 17:07 jakewies

I'm running into the same issue / want today, albeit a slightly different use case — I want a simple emoji to be my favicon

@kentnek are you still working on this? if not, I can PR in the addition for append_head or such

wilsonehusin avatar Oct 12 '20 00:10 wilsonehusin

@wilsonehusin oh please feel free to tackle it. I'm currently busy with real life so I can't work on this at the moment. Thank you!

kentnek avatar Oct 13 '20 08:10 kentnek

I've raised the PR (#131) I personally do not have any use case for hooks, so I decided not to implement it immediately, unless you have other thoughts on this, @jakewies.

wilsonehusin avatar Oct 14 '20 02:10 wilsonehusin

Thanks @wilsonehusin I will make sure to take a peak. I have a lot of stuff to tackle for this project, been very busy IRL.

jakewies avatar Oct 14 '20 15:10 jakewies

no problem @jakewies -- it's a one-liner change so perhaps it can be some entertainment on a tough day :D

anyhow, thanks for the wonderful work! truly appreciate that you open source the product :)

wilsonehusin avatar Oct 14 '20 16:10 wilsonehusin

Thank you @wilsonehusin for #131 !

Would you be interested and also working on a few other partials? If you haven't come across the need in your own work, then not to worry. Just curious. I seee that #46 aims to address a few other parts of the base template like title.

jakewies avatar Oct 18 '20 14:10 jakewies

I'll stop by again when I come across some other use cases, I don't have anything in mind at the moment though 🙂

wilsonehusin avatar Oct 18 '20 15:10 wilsonehusin

No worries! I will keep this Issue open for future newcomers who might want to make some contributions.

jakewies avatar Oct 18 '20 15:10 jakewies