Skip to content

Commit

Permalink
DEV: Use woff2 for all fonts (#20)
Browse files Browse the repository at this point in the history
We are changing to use woff2 instead of ttf for all our
fonts. This is supported on all browsers we support
(see https://caniuse.com/woff2) and it's faster and a
smaller file size.

This results in an Xkb total size reduction for fonts
we package with Discourse.
  • Loading branch information
martin-brennan authored Jan 30, 2025
1 parent ee34607 commit 73865ca
Show file tree
Hide file tree
Showing 82 changed files with 59 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Gemfile.lock
.DS_Store
120 changes: 58 additions & 62 deletions lib/discourse_fonts.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module DiscourseFonts
VERSION = "0.0.17"
VERSION = "0.0.18"

def self.path_for_fonts
File.expand_path("../../vendor/assets/fonts", __FILE__)
Expand All @@ -21,11 +21,11 @@ def self.fonts
stack: "Open Sans, Arial, sans-serif",
variants: [
{
filename: "OpenSans-Regular.ttf",
format: "truetype",
filename: "OpenSans-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "OpenSans-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "OpenSans-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
Expand All @@ -40,16 +40,16 @@ def self.fonts
name: "Roboto",
stack: "Roboto, Arial, sans-serif",
variants: [
{ filename: "Roboto-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Roboto-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Roboto-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Roboto-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Lato",
stack: "Lato, Arial, sans-serif",
variants: [
{ filename: "Lato-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Lato-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Lato-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Lato-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
Expand All @@ -71,34 +71,38 @@ def self.fonts
name: "NotoSansJP",
stack: "NotoSansJP, Arial, sans-serif",
variants: [
{ filename: "NotoSansJP-Regular.otf", weight: 400 },
{ filename: "NotoSansJP-Bold.otf", weight: 700 }
{
filename: "NotoSansJP-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "NotoSansJP-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Montserrat",
stack: "Montserrat, Arial, sans-serif",
variants: [
{
filename: "Montserrat-Regular.ttf",
format: "truetype",
filename: "Montserrat-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "Montserrat-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Montserrat-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "RobotoCondensed",
stack: "RobotoCondensed, Arial, sans-serif",
variants: [
{
filename: "RobotoCondensed-Regular.ttf",
format: "truetype",
filename: "RobotoCondensed-Regular.woff2",
format: "woff2",
weight: 400
},
{
filename: "RobotoCondensed-Bold.ttf",
format: "truetype",
filename: "RobotoCondensed-Bold.woff2",
format: "woff2",
weight: 700
}
]
Expand All @@ -108,13 +112,13 @@ def self.fonts
stack: "SourceSansPro, Arial, sans-serif",
variants: [
{
filename: "SourceSansPro-Regular.ttf",
format: "truetype",
filename: "SourceSansPro-Regular.woff2",
format: "woff2",
weight: 400
},
{
filename: "SourceSansPro-Bold.ttf",
format: "truetype",
filename: "SourceSansPro-Bold.woff2",
format: "woff2",
weight: 700
}
]
Expand All @@ -123,82 +127,74 @@ def self.fonts
name: "Oswald",
stack: "Oswald, Arial, sans-serif",
variants: [
{ filename: "Oswald-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Oswald-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Oswald-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Oswald-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Raleway",
stack: "Raleway, Arial, sans-serif",
variants: [
{
filename: "Raleway-Regular.ttf",
format: "truetype",
weight: 400
},
{ filename: "Raleway-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Raleway-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Raleway-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "RobotoMono",
stack: "RobotoMono, Arial, sans-serif",
variants: [
{
filename: "RobotoMono-Regular.ttf",
format: "truetype",
filename: "RobotoMono-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "RobotoMono-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "RobotoMono-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Poppins",
stack: "Poppins, Arial, sans-serif",
variants: [
{
filename: "Poppins-Regular.ttf",
format: "truetype",
weight: 400
},
{ filename: "Poppins-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Poppins-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Poppins-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "NotoSans",
stack: "NotoSans, Arial, sans-serif",
variants: [
{
filename: "NotoSans-Regular.ttf",
format: "truetype",
filename: "NotoSans-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "NotoSans-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "NotoSans-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "RobotoSlab",
stack: "RobotoSlab, Arial, sans-serif",
variants: [
{
filename: "RobotoSlab-Regular.ttf",
format: "truetype",
filename: "RobotoSlab-Regular.woff2",
format: "woff2",
weight: 400
},
{ filename: "RobotoSlab-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "RobotoSlab-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Merriweather",
stack: "Merriweather, Arial, sans-serif",
variants: [
{
filename: "Merriweather-Regular.ttf",
format: "truetype",
filename: "Merriweather-Regular.woff2",
format: "woff2",
weight: 400
},
{
filename: "Merriweather-Bold.ttf",
format: "truetype",
filename: "Merriweather-Bold.woff2",
format: "woff2",
weight: 700
}
]
Expand All @@ -207,30 +203,30 @@ def self.fonts
name: "Ubuntu",
stack: "Ubuntu, Arial, sans-serif",
variants: [
{ filename: "Ubuntu-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Ubuntu-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Ubuntu-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Ubuntu-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "PTSans",
stack: "PTSans, Arial, sans-serif",
variants: [
{ filename: "PTSans-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "PTSans-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "PTSans-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "PTSans-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "PlayfairDisplay",
stack: "PlayfairDisplay, Arial, sans-serif",
variants: [
{
filename: "PlayfairDisplay-Regular.ttf",
format: "truetype",
filename: "PlayfairDisplay-Regular.woff2",
format: "woff2",
weight: 400
},
{
filename: "PlayfairDisplay-Bold.ttf",
format: "truetype",
filename: "PlayfairDisplay-Bold.woff2",
format: "woff2",
weight: 700
}
]
Expand All @@ -239,24 +235,24 @@ def self.fonts
name: "Nunito",
stack: "Nunito, Arial, sans-serif",
variants: [
{ filename: "Nunito-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Nunito-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Nunito-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Nunito-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Lora",
stack: "Lora, Arial, sans-serif",
variants: [
{ filename: "Lora-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Lora-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Lora-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Lora-Bold.woff2", format: "woff2", weight: 700 }
]
},
{
name: "Mukta",
stack: "Mukta, Arial, sans-serif",
variants: [
{ filename: "Mukta-Regular.ttf", format: "truetype", weight: 400 },
{ filename: "Mukta-Bold.ttf", format: "truetype", weight: 700 }
{ filename: "Mukta-Regular.woff2", format: "woff2", weight: 400 },
{ filename: "Mukta-Bold.woff2", format: "woff2", weight: 700 }
]
},
{ name: "Helvetica", stack: "Helvetica, Arial, sans-serif" }
Expand Down
Binary file removed vendor/assets/fonts/Lato-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Lato-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Lato-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Lato-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Lora-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Lora-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Lora-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Lora-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Merriweather-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Merriweather-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Merriweather-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Merriweather-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Montserrat-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Montserrat-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Montserrat-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Montserrat-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Mukta-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Mukta-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Mukta-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Mukta-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/NotoSans-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/NotoSans-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/NotoSans-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/NotoSans-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/NotoSansJP-Bold.otf
Binary file not shown.
Binary file added vendor/assets/fonts/NotoSansJP-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/NotoSansJP-Regular.otf
Binary file not shown.
Binary file added vendor/assets/fonts/NotoSansJP-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Nunito-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Nunito-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Nunito-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Nunito-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/OpenSans-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/OpenSans-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/OpenSans-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/OpenSans-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Oswald-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Oswald-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Oswald-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Oswald-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/PTSans-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/PTSans-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/PTSans-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/PTSans-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/PlayfairDisplay-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/PlayfairDisplay-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/PlayfairDisplay-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/PlayfairDisplay-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Poppins-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Poppins-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Poppins-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Poppins-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Raleway-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Raleway-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Raleway-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Raleway-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Roboto-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Roboto-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Roboto-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Roboto-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoCondensed-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoCondensed-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoCondensed-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoCondensed-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoMono-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoMono-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoMono-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoMono-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoSlab-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoSlab-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/RobotoSlab-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/RobotoSlab-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/SourceSansPro-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/SourceSansPro-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/SourceSansPro-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/SourceSansPro-Regular.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Ubuntu-Bold.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Ubuntu-Bold.woff2
Binary file not shown.
Binary file removed vendor/assets/fonts/Ubuntu-Regular.ttf
Binary file not shown.
Binary file added vendor/assets/fonts/Ubuntu-Regular.woff2
Binary file not shown.

0 comments on commit 73865ca

Please sign in to comment.