tancredi/fantasticon

Format-specific fontsUrl

dave-db opened this issue · 1 comments

It would be great to be able to dynamically change the value of fontsUrl based on the output format. For example, we're generating a dist/fonts.css file that is a sibling to the generated fonts, but also an .scss output on a different filepath. Similar to #126, we're setting a sass variable for the root path:

$icon-font-path: "../../dist/fonts" !default;
// ...
@font-face {
    font-family: ${{ name }}-font;
    src: {{{ fontSrc }}};
}

...and setting fontsUrl: '#{$icon-font-path}' in the fantasticon config.

Trouble is, by doing this, we then get the '#{$icon-font-path}' injected in the css output as well, which obviously doesn't work. If we remove the fontsUrl setting, the css output is fine, but then the scss doesn't have the correct url prefix. It would be great if we could set the fontsUrl conditionally, e.g.

// ...
formatOptions: {
    scss: {
      fontsUrl: '#{$icon-font-path}',
    },
}

On #126, a custom template is suggested as a solution here, but I can't see how we can use a template to intercept the fontSrc values as they're written (we're already using a custom template to set the $icon-font-path). Is there a way of intercepting/breaking down the value of fontSrc to allow us to conditionally set fontsUrl?

mdo commented

This would fix my problem in #126 fwiw. Would be great to have something like this.