Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Normal CSS Files #112

Merged
merged 3 commits into from Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions scripts/google/packager-v1.js
Expand Up @@ -60,7 +60,6 @@ module.exports = function (id) {
font.subsets.forEach(subset => {
const cssSubset = []
font.weights.forEach(weight => {
const cssWeight = []
font.styles.forEach(style => {
// Some fonts may have variants 400, 400i, 700 but not 700i.
if (style in font.variants[weight]) {
Expand All @@ -74,15 +73,20 @@ module.exports = function (id) {
woff2Path: makeFontFilePath(subset, weight, style, "woff2"),
woffPath: makeFontFilePath(subset, weight, style, "woff"),
})
cssWeight.push(css)
cssSubset.push(css)

const cssStylePath = `${fontDir}/${subset}-${weight}-${style}.css`
fs.writeFileSync(cssStylePath, css)
if (style === "normal") {
const cssPath = `${fontDir}/${subset}-${weight}.css`
fs.writeFileSync(cssPath, css)

// Should only push normal variants into subset
cssSubset.push(css)
} else {
// If italic or else, define specific style CSS file
const cssStylePath = `${fontDir}/${subset}-${weight}-${style}.css`
fs.writeFileSync(cssStylePath, css)
}
}
})
const cssWeightPath = `${fontDir}/${subset}-${weight}.css`
fs.writeFileSync(cssWeightPath, cssWeight.join(""))
})
const cssSubsetPath = `${fontDir}/${subset}.css`
fs.writeFileSync(cssSubsetPath, cssSubset.join(""))
Expand Down
23 changes: 14 additions & 9 deletions scripts/google/packager-v2.js
Expand Up @@ -86,7 +86,6 @@ module.exports = function (id) {
const unicodeKeys = Object.keys(font.unicodeRange)

font.weights.forEach(weight => {
const cssWeight = []
font.styles.forEach(style => {
const cssStyle = []
unicodeKeys.forEach(subset => {
Expand All @@ -109,18 +108,24 @@ module.exports = function (id) {
unicodeRange: font.unicodeRange[subset],
})
cssStyle.push(css)
cssWeight.push(css)
}
})
// Write down CSS
if (style in font.variants[weight]) {
const cssStylePath = `${fontDir}/${weight}-${style}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))
if (style === "normal") {
const cssPath = `${fontDir}/${weight}.css`
fs.writeFileSync(cssPath, cssStyle.join(""))

// Generate index CSS
if (weight === "400") {
fs.writeFileSync(`${fontDir}/index.css`, cssStyle.join(""))
}
} else {
// If italic or else, define specific style CSS file
const cssStylePath = `${fontDir}/${weight}-${style}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))
}
}
})
const cssWeightPath = `${fontDir}/${weight}.css`
fs.writeFileSync(cssWeightPath, cssWeight.join(""))
if (weight === "400") {
fs.writeFileSync(`${fontDir}/index.css`, cssWeight.join(""))
}
})
}
49 changes: 31 additions & 18 deletions scripts/google/variable.js
Expand Up @@ -53,7 +53,6 @@ module.exports = function (id) {
const variableName = `${font.family}Variable`

// wghtOnly CSS Generation
const css = []
font.styles.forEach(style => {
const cssStyle = []
font.subsets.forEach(subset => {
Expand All @@ -69,20 +68,25 @@ module.exports = function (id) {
unicodeRange: font.unicodeRange[subset],
})
cssStyle.push(cssWght)
css.push(cssWght)
})
const cssStylePath = `${fontDir}/variable-${style}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))

// Write down CSS
if (style === "normal") {
const cssPath = `${fontDir}/variable.css`
fs.writeFileSync(cssPath, cssStyle.join(""))
} else {
// If italic or else, define specific style CSS file
const cssStylePath = `${fontDir}/variable-${style}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))
}
})
const cssPath = `${fontDir}/variable.css`
fs.writeFileSync(cssPath, css.join(""))

// full CSS Generation
if ("full" in fontVariable.variants) {
// Wdth requires a different CSS template (font-stretch)
if ("wdth" in fontVariable.axes) {
const css = []
font.styles.forEach(style => {
// Preserve the 'normal' style as a flag
const origStyle = style
if ("slnt" in fontVariable.axes && style === "normal") {
// SLNT has a different style linked to it.
Expand All @@ -105,15 +109,19 @@ module.exports = function (id) {
unicodeRange: font.unicodeRange[subset],
})
cssStyle.push(cssWght)
css.push(cssWght)
})
const cssStylePath = `${fontDir}/variable-full-${origStyle}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))

// Write down CSS
if (origStyle === "normal") {
const cssPath = `${fontDir}/variable-full.css`
fs.writeFileSync(cssPath, cssStyle.join(""))
} else {
// If italic or else, define specific style CSS file
const cssStylePath = `${fontDir}/variable-full-${origStyle}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))
}
})
const cssPath = `${fontDir}/variable-full.css`
fs.writeFileSync(cssPath, css.join(""))
} else {
const css = []
font.styles.forEach(style => {
const origStyle = style
if ("slnt" in fontVariable.axes && style === "normal") {
Expand All @@ -136,13 +144,18 @@ module.exports = function (id) {
unicodeRange: font.unicodeRange[subset],
})
cssStyle.push(cssWght)
css.push(cssWght)
})
const cssStylePath = `${fontDir}/variable-full-${origStyle}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))

// Write down CSS
if (origStyle === "normal") {
const cssPath = `${fontDir}/variable-full.css`
fs.writeFileSync(cssPath, cssStyle.join(""))
} else {
// If italic or else, define specific style CSS file
const cssStylePath = `${fontDir}/variable-full-${origStyle}.css`
fs.writeFileSync(cssStylePath, cssStyle.join(""))
}
})
const cssPath = `${fontDir}/variable-full.css`
fs.writeFileSync(cssPath, css.join(""))
}
}
}