"

Custom fonts in Quarto slides published via GitHub pages

I spent a good chunk of yesterday doing battle with a custom font that I needed to import from a directory rather than from Google Fonts into a #quartoPub presentation.
Author
Affiliation

Building Stories with Data

Published

October 1, 2022

Worked fine locally, but could not get it to work on GitHub Pages.

The solution? Give the font two paths.

CSS code snippet demonstrating font-face usage. Shows local and GitHub Pages setup for 'brandon-text' font. Includes comments explaining path adjustments for correct font loading on GitHub. Syntax highlighted for clarity.


// to work locally...
@font-face {
  font-family: 'brandon-text';
  src: url("/fonts/BrandonText-Regular.ttf") 
    format('truetype');
}


// to create a url that will work on GitHub Pages...
/* My root directory is hdsi_rug; GitHub Pages seems to delete that part of the path string, so specifying it again within a new path works. The font isn't stored here, but this tricks GitHub Pages into looking in the right place! */ 

@font-face {
  font-family: 'brandon-text';
  src: url("/hdsi_rug/fonts/BrandonText-Regular.ttf") 
    format('truetype');
}

The next thing to fix was that the footer got moved back to its default Quarto position when the slides are inside an iframe.

So, enter “footer.css” where I needed to edit the footer attributes inside the section which applies when width < 800px (e.g., inside the iframe).

CSS code snippet for responsive footer design, activated on screens with max-width of 800px. The footer is fixed at the bottom, centred, spans full width, and has a font size of 14px. Notably labelled 'Main culprit!' for positioning adjustment.


@media screen and (max-width: 800px) {
    // Replicate any footer adjustements in here
  
    .reveal .footer {
      display: block;
      position: fixed;
      /* v Main culprit! v */
      bottom: 0px;
      width: 100%;
      margin: 0 auto;
      text-align: center;
      font-size: 14px;
      z-index: 2;
    }

    // More CSS here
  
}

Finally, I wasted time editing my custom css file in the GH repo, not realising that the Quarto rendered html doc reads from a different css file, deep inside the entrails of the repo.

Really pleased with the end result - but yikes! Every day a school daywww.cararthompson.com/talks/hdsi_rug/

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2022. “Custom Fonts in Quarto Slides Published via GitHub Pages.” October 1, 2022. https://www.cararthompson.com/posts/2022-10-01-i-spent-a-good-chunk/.