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

Request for custom web fonts support #7

Closed
B-Interactive opened this issue Feb 9, 2023 · 2 comments
Closed

Request for custom web fonts support #7

B-Interactive opened this issue Feb 9, 2023 · 2 comments

Comments

@B-Interactive
Copy link

B-Interactive commented Feb 9, 2023

Hugo is still pretty new territory for me, so please let me know if I've approached this the wrong way. That said, I have hunted for an official way, or best practice for making use of web fonts, but standard method seems to be entirely missing.

That is, it seems it's open to theme developers to implement this, should they choose to.

At the moment, in order to make updating the theme simpler, I've resorted to overriding only the head.html partial. I modify it to point to paige/myLinks.html and paige/myStyle.html, instead of the original paige/links.html and paige/style.html partials respectively.

{{ partial "paige/myLinks.html" $page }}
{{ partial "paige/myStyle.html" $page }}

Having created those files, they then reference the original partials, so any theme updates to those are sustained, but it still permits me to include my custom additions:

paige/myLinks.html

{{ $page := . }}
{{ partial "paige/links.html" $page }}

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">

paige/myStyle.html

{{ $page := . }}
{{ partial "paige/style.html" $page }}

<style>
    body, html {
        font-family: 'Roboto', sans-serif;
    }
</style>

Whilst this is working, theme updates to /themes/paige/layouts/partials/paige/head.html will be missed unless I manually review it each time. I wonder you might consider a more elegant way to reference web fonts with theme support, within config.toml / .yaml, etc.

@willfaught
Copy link
Owner

Hi, @B-Interactive! Thanks for your question.

See https://github.com/willfaught/paige#include. You'll want to create a partials/paige/head-last.html file with your web font tags. partials/paige/head.html will include head-last.html at the end of the head tag if it exists. That way you don't have to override theme code, and you get all the updates automatically.

Please let me know if the include section in the readme was unclear about how it works, or why you'd want to use it. It's a work in progress.

@B-Interactive
Copy link
Author

Ah! That's exactly what I needed, that's great!

I come from WordPress, so I'm looking for ways to hook in code, and there it is, laid out beautifully, thank you.

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

No branches or pull requests

2 participants