Skip to content

Commit

Permalink
fix: build and publish woff and woff2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
anucreative committed Dec 19, 2023
1 parent cf82b39 commit 929b9a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ jobs:
yarn build:core
- aws-s3/sync:
from: packages/IconFont/fonts
to: s3://welcome-ui/public/fonts/icon-font/$ICON_FONT_HASH --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff2'
to: s3://welcome-ui/public/fonts/icon-font/$ICON_FONT_HASH --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff, welcome-icon-font.woff2'
arguments: |
--metadata GitCommit=$CIRCLE_SHA1 --delete
- aws-s3/sync:
from: packages/IconFont/fonts
to: s3://wttj-production/fonts/icon-font/$ICON_FONT_HASH --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff2'
to: s3://wttj-production/fonts/icon-font/$ICON_FONT_HASH --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff, welcome-icon-font.woff2'
arguments: |
--metadata GitCommit=$CIRCLE_SHA1 --delete
Expand Down
18 changes: 10 additions & 8 deletions packages/Core/src/utils/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type FontVariation = {
weight?: string
style?: string
isVariable?: boolean
extension?: string
extensions?: string[]
unicodeRange?: string
}

Expand All @@ -19,24 +19,26 @@ type Font = {

function getSource(
url: FontVariation['url'],
extension: FontVariation['extension'],
extensions: FontVariation['extensions'],
isVariable: FontVariation['isVariable']
) {
const formattedExtension = extension === 'ttf' ? 'truetype' : extension

/** variable icon font */
if (isVariable) {
return `url('${url}.${extension}') format('${formattedExtension}-variations');`
return extensions
.map((extension: string) => `url('${url}.${extension}') format('${extension}-variations');`)
.join(', ')
}

return `url('${url}.${extension}') format('${formattedExtension}')`
return extensions
.map((extension: string) => `url('${url}.${extension}') format('${extension}');`)
.join(', ')
}

function getFont({
name,
variation: {
display = 'swap',
extension = 'woff2',
extensions = ['woff2', 'woff'],
isVariable,
style,
unicodeRange,
Expand All @@ -47,7 +49,7 @@ function getFont({
return css`
@font-face {
font-family: ${name};
src: ${getSource(url, extension, isVariable)};
src: ${getSource(url, extensions, isVariable)};
font-display: ${display};
${weight &&
css`
Expand Down
2 changes: 1 addition & 1 deletion scripts/webfont-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const writeIconFont = files => {
dest: `${ICON_FONT_PATH}/fonts`,
fontName: FONT_NAME,
codepoints: newUnicodeMap,
types: ['woff2'],
types: ['woff', 'woff2'],
templateOptions: {
classPrefix: 'wui-icon-',
baseSelector: 'i',
Expand Down
4 changes: 2 additions & 2 deletions scripts/webfont-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ if [[ -f "$FONT_FILE" ]]; then

echo "Copying fonts to s3://welcome-ui/public/fonts/icon-font/$ICON_FONT_HASH/"

aws s3 sync $FONTS_DIR s3://welcome-ui/public/fonts/icon-font/$ICON_FONT_HASH/ --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff2'
aws s3 sync $FONTS_DIR s3://welcome-ui/public/fonts/icon-font/$ICON_FONT_HASH/ --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff, welcome-icon-font.woff2'

echo "Copying fonts to s3://wttj-production/fonts/icon-font/$ICON_FONT_HASH/"

aws s3 sync $FONTS_DIR s3://wttj-production/fonts/icon-font/$ICON_FONT_HASH/ --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff2'
aws s3 sync $FONTS_DIR s3://wttj-production/fonts/icon-font/$ICON_FONT_HASH/ --cache-control 'public, max-age=31536000' --exclude '*' --include 'welcome-icon-font.woff, welcome-icon-font.woff2'
else
echo "Font doesn't exist. Please run 'yarn webfont:build'"
exit 1
Expand Down

0 comments on commit 929b9a0

Please sign in to comment.