Giter Site home page Giter Site logo

Load local custom font about hugoplate HOT 4 CLOSED

alexgutjahr avatar alexgutjahr commented on June 13, 2024
Load local custom font

from hugoplate.

Comments (4)

tfsomrat avatar tfsomrat commented on June 13, 2024 1

here is a simple guideline for you. I am using sampoty font as an example

  1. store your fonts in the root static folder, you need to create this folder. store fonts like ./static/sampoty.woff.

then link the font in custom.scss

@font-face {
  font-family: "sampotyregular";
  src:
    url("../sampoty.woff2") format("woff2"),
    url("../sampoty.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
  1. If you want to use the custom font as Primary font. then use the font name in themes.json file
"fonts": {
    "font_family": {
      "primary": "sampotyregular",
      "primary_type": "sans-serif",
      "secondary": "Signika:wght@500;700",
      "secondary_type": "sans-serif"
    },
    "font_size": {
      "base": "16",
      "scale": "1.250"
    }
  }
  1. customize the google font link in style.html file. (I removed primary_font link from here)
googleFont.href = "https://fonts.googleapis.com/css2?{{with $sf}}family={{. | safeURL}}{{end}}&display=swap";

and you have successfully setup your custom font, along with google font.

from hugoplate.

tfsomrat avatar tfsomrat commented on June 13, 2024

Hey @alexgutjahr, thanks for your interest. Custom font needs to link in the CSS file. custom.scss could be a good way to link your fonts.

from hugoplate.

alexgutjahr avatar alexgutjahr commented on June 13, 2024

Thanks for the swift reply @tfsomrat, appreciate it! Also wanna say that your template is the best I've seen over the years, thanks for building it.

About the custom.scss I can load the font-face in there, how would I then reference the local woff2 file, or more specifically, where do you suggest the files should be stored so they are accessible to the stylesheets? I went with assets/fonts but was not able to reference the files successfully, i.e. when the page is built the fonts are not found.

Secondly, assuming that I can successfully load the font-face, How do I override just the secondary font? I assume theme.toml expects a Google font and will not work with custom fonts, will it? If not, where/how can I override just the secondary font? Thanks!

from hugoplate.

alexgutjahr avatar alexgutjahr commented on June 13, 2024

Works perfect, thank you!

from hugoplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.