Hey folks,
Pretty new to Hugo, and having a lot of fun, but finding it a little impossible to properly link some typeface files within my build. I have the files in static/fonts, and linked as such in my css file:
@font-face {
font-family: GortonRegular;
src: local('GortonDigitalRegular'),
url('/fonts/GortonDigitalRegular.otf') format("opentype");
}
Have tried every variation of pathing, but canβt seem to get the public files to find my typefaces. Repo is here , for reference.
Help!
Arif
March 1, 2024, 9:34am
2
Not related to your question. But you need to add the public folder in your .gitignore
file.
In your repo, you have this (in public/main.css
):
@font-face {
font-family: GortonRegular;
src: url("fonts/GortonDigitalRegular.otf");
}
So, the CSS is referring to public/fonts/main.css
. Which doesnβt exist. Iβm not going to delve deeper, as your site structure is not what is recommended:
Each Hugo project is a directory, with subdirectories that contribute to the content, structure, behavior, and presentation of your site.
Please remove public
from your repo and move the stuff under themes
(like static
etc) to where it should be.
You have two problems:
You are serving your site from a subdirectory, and URLs beginning with / are relative to the server root, not the site root.
The font-family value in your font-face declaration does not match the font-family that you set for the body element.
Fix:
diff --git a/themes/nosoapradio-theme/assets/css/main.css b/themes/nosoapradio-theme/assets/css/main.css
index 482c8ee..77472c8 100644
--- a/themes/nosoapradio-theme/assets/css/main.css
+++ b/themes/nosoapradio-theme/assets/css/main.css
@@ -1,7 +1,7 @@
@font-face {
font-family: GortonRegular;
src: local('GortonDigitalRegular'),
- url('/fonts/GortonDigitalRegular.otf') format("opentype");
+ url('/nosoapradio/fonts/GortonDigitalRegular.otf') format("opentype");
}
html body {
@@ -17,7 +17,7 @@ html body {
body {
background-color: ivory;
- font-family: 'GortonDigitalRegular', monospace;
+ font-family: 'GortonRegular', monospace;
}
/* Globals */
@@ -277,7 +277,7 @@ td:last-child {
.blinking {
animation: 2s blink ease infinite;
-
+
}
@keyframes blink {
@@ -323,4 +323,4 @@ td:last-child {
50% {
opacity: 1;
}
-}
\ No newline at end of file
+}
Joe, this worked beautifully, thank you.
To your first point - this makes sense, I think I got a little confused figuring out where Hugo pulls the main index.html file from.
Iβm wondering if this is the same issue causing relative links on single pages to be broken (seen here , with the image and audio)?
Yes, but prepending everything with the subdirectory is fragile, as is your content directory structure.
Instead of this:
content/projects/
βββ audio/
β βββ hellodummy1.mp3
βββ img/
β βββ hellodummy.png
βββ hellodummy.md
Do this:
content/projects/
βββ hellodummy/
βββ cover.png
βββ index.md <-- leaf bundle
βββ track.mp3
Now the image and track are page resources, so you can do:
{{ with .Resources.GetMatch "track.*" }}
<audio class="card-audio" controls>
<source src="{{ .RelPermalink }}" type="{{ .MediaType.Type }}">
</audio>
{{ end }}
and
{{ with .Resources.GetMatch "cover.*" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
With the approach above, if you name the page resources properly/consistently, you wonβt need to reference them in front matter.
1 Like
Joe, once again an elegant (and quick) solution. Thanks!
Last related question! I currently have two static pages linked in the top nav, βInfoβ and βSubmissionsβ. Theyβre just set as markdown files in the Content folder, what is the best way to organize those and link in the menu without having them show up as Projects? Something like this?
content/projects/
βββ projects/
βββ hellodummy/
βββ cover.png
βββ index.md
βββ track.mp3
βββ info/
βββ cover.png
βββ index.md
βββ track.mp3
βββ submissions/
βββ cover.png
βββ index.md
βββ track.mp3
And then Iβd be able to pull in the resources the same way, and can just link to /info and /submissions, respectively?
That sounds right. Give it a try. Experimentation is a great way to learn.
1 Like
system
Closed
March 3, 2024, 2:15pm
10
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.