Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Interface
  • Options
  • Basic usage

Was this helpful?

Export as PDF
  1. Reference
  2. Parsers

to-css-font-import

This parser helps you create CSS @font-face rules to import your font files.

Interface

interface parser {
  name: 'to-css-font-import';
  output: {
    type: 'file';
    filePath: string;
  };
  options?: {
    formats?: Array<'woff' | 'woff2' | 'ttf' | 'otf' | 'eot'>;
    fontsPath?: string;
    includeFontWeight?: boolean;
    genericFamily?: string;
    fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
  };
}

Options

Parameter
Required
Type
Default
Description

formats

false

Array<string>

['woff', 'woff2']

The list of formats to import.

fontsPath

false

string

The path of font's directory.

includeFontWeight

false

boolean

Allow to include the font-weight property in the result.

genericFamily

false

string

The generic font family will be applied after the main font family.

fontDisplay

false

string

swap

How your font face is displayed based on whether and when it is downloaded and ready to use.

Basic usage

{
  "font": {
    "interRegular": {
      "$type": "font",
      "$value": {
        "default": {
          "family": "Inter",
          "postScriptName": "Inter Regular",
          "weight": "regular",
          "style": "normal",
          "files": [
            {
              "format": "ttf",
              "url": "https://static.specifyapp.com/sdtf-seeds/inter-regular.ttf",
              "provider": "Specify"
            }
          ]
        }
      }
    },
    "interMedium": {
      "$type": "font",
      "$value": {
        "default": {
          "family": "Inter",
          "postScriptName": "Inter Medium",
          "weight": "medium",
          "style": "normal",
          "files": [
            {
              "format": "ttf",
              "url": "https://static.specifyapp.com/sdtf-seeds/inter-medium.ttf",
              "provider": "Specify"
            }
          ]
        }
      }
    },
    "interBold": {
      "$type": "font",
      "$value": {
        "default": {
          "family": "Inter",
          "postScriptName": "Inter Bold",
          "weight": "bold",
          "style": "normal",
          "files": [
            {
              "format": "ttf",
              "url": "https://static.specifyapp.com/sdtf-seeds/inter-bold.ttf",
              "provider": "Specify"
            }
          ]
        }
      }
    },
    "firaCodeRegular": {
      "$type": "font",
      "$value": {
        "default": {
          "family": "Fira Code",
          "postScriptName": "Fira Code Regular",
          "weight": "regular",
          "style": "normal",
          "files": [
            {
              "format": "ttf",
              "url": "https://static.specifyapp.com/sdtf-seeds/fira-code-regular.ttf",
              "provider": "Specify"
            }
          ]
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Generate font imports",
      "parsers": [
        {
          "name": "to-css-font-import",
          "output": {
            "type": "file",
            "filePath": "public/fonts.css"
          },
          "options": {
            "fontsPath": "assets/fonts/"
          }
        }
      ]
    }
  ]
}
public/fonts.css
@font-face {
	font-family: 'Fira Code';
	src: url('assets/fonts/Fira Code.woff') format('woff'), url('assets/fonts/Fira Code.woff2') format('woff2');
	font-display: swap;
	font-weight: regular;
}
@font-face {
	font-family: 'Inter';
	src: url('assets/fonts/Inter.woff') format('woff'), url('assets/fonts/Inter.woff2') format('woff2');
	font-display: swap;
	font-weight: bold;
}
@font-face {
	font-family: 'Inter';
	src: url('assets/fonts/Inter.woff') format('woff'), url('assets/fonts/Inter.woff2') format('woff2');
	font-display: swap;
	font-weight: medium;
}
@font-face {
	font-family: 'Inter';
	src: url('assets/fonts/Inter.woff') format('woff'), url('assets/fonts/Inter.woff2') format('woff2');
	font-display: swap;
	font-weight: regular;
}
Previousto-css-text-styleNextto-flutter

Last updated 1 year ago

Was this helpful?