Search code examples
fontssasscompass-sass

Compass @font-face can't find font file


My compass directory looks something like this:

root_of_directory
  sass
    screen.scss
  stylesheets
    fonts
      goudysto.ttf
    screen.css

and then the mixin for font-face looks like this:

@include font-face("goudysto", font-files("goudysto.ttf", "truetype"));

The output in the console says this:

GET file:///fonts/goudysto.ttf net::ERR_FILE_NOT_FOUND 

This is the outputted css

    @font-face {
     font-family: "goudysto";
     src: url('/fonts/goudysto.ttf') format('truetype');
    }

Can anyone tell me why this is happening?

*UPDATE -- config.rb *

require 'compass/import-once/activate'
# Require any additional compass plugins here.

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
fonts_dir = "stylesheets/fonts"

# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed

# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false


# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass

Solution

  • Set the fonts_dir in config.rb like this:

    fonts_dir = "stylesheets/fonts"
    

    Edit: Also, as mentioned in the comments, make sure to uncomment # relative_assets = true and use relative paths in config.rb ...