How can I add a font to a theme and how to declare it via @font-face
in assets/style.css
? I thought I could add it to public/fonts
and then declare
@font-face {
font-family: "Signika";
src: url("/fonts/Signika-Regular.woff2") format("woff2");
}
but that doesn’t work.
Then I found a paragraph about static files in the documentation but it didn’t help me because there is no example.
In the end my solution was:
- Host the font on an own server.
- Add a
style
element with @font-face
to the html by using (Administration) Settings → Configuration → Advanced → Customizations → JavaScript
var style = document.createElement('style');
document.head.appendChild(style);
style.textContent = `
@font-face {
font-family: "Signika";
src: url("<url_on_self_hosted_server>") format("woff2");
font-weight: normal;
font-style: normal;
}
`;
- Apply the font via CSS (PeerTube settings or Theme plugin)
body#custom-css header span.instance-name {
font-family: "Signika", "Source Sans Pro", sans-serif;
}
zxc
3
I had the same problem, and I agree, the static files documentation wasn’t very clear.
I appear that the static folder should be created in your theme-folder at the root level.
When you add your font there, you can access it via /static/… in your @font-face.
For me it lookes like this:
@font-face {
font-family: 'URWDINSemiCond Regular';
src: url('/static/fonts/urwdin/URWDINSemiCond-Regular.woff2') format('woff2')
font-weight: normal;
font-style: normal;
}
1 « J'aime »