/
templates.js
283 lines (213 loc) · 11.4 KB
/
templates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
const _ = require(`lodash`)
exports.packageJson = _.template(
`{
"name": "fontsource-<%= fontId %>",
"version": "3.0.0",
"description": "<%= fontName %> font in NPM glory.",
"main": "index.css",
"keywords": [
"fontsource",
"font",
"font family",
"google fonts",
"<%= fontName %>",
"<%= fontId %>",
"css",
"front-end",
"web",
"typeface"
],
"author": "Lotus <declininglotus@gmail.com>",
"license": "MIT",
"homepage": "https://github.com/fontsource/fontsource/tree/master/packages/<%= fontId %>#readme",
"repository": {
"type": "git",
"url": "https://github.com/fontsource/fontsource.git",
"directory": "packages/<%= fontId %>"
}
}
`
)
exports.fontFace = _.template(
`/* <%= fontId %>-<%= subset %>-<%= weight %>-<%= style %>*/
@font-face {
font-family: '<%= fontName %>';
font-style: <%= style %>;
font-display: swap;
font-weight: <%= weight %>;
src:<% _.forEach(locals, function(localName) { %>
local('<%= localName %>'),<% });
%>
url('<%= woff2Path %>') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('<%= woffPath %>') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
`
)
exports.fontFaceUnicode = _.template(
`/* <%= fontId %>-<%= subset %>-<%= weight %>-<%= style %>*/
@font-face {
font-family: '<%= fontName %>';
font-style: <%= style %>;
font-display: swap;
font-weight: <%= weight %>;
src: url('<%= woff2Path %>') format('woff2'), url('<%= woffPath %>') format('woff');
unicode-range: <%= unicodeRange %>;
}
`
)
exports.fontFaceVariable = _.template(
`/* <%= fontId %>-<%= subset %>-variable-<%= type %>-<%= style %> */
@font-face {
font-family: '<%= fontName %>';
font-style: <%= style %>;
font-display: swap;
font-weight: <%= weight %>;
src: url('<%= woff2Path %>') format('woff2');
unicode-range: <%= unicodeRange %>;
}
`
)
exports.fontFaceVariableWdth = _.template(
`/* <%= fontId %>-<%= subset %>-variable-<%= type %>-<%= style %> */
@font-face {
font-family: '<%= fontName %>';
font-style: <%= style %>;
font-display: swap;
font-weight: <%= weight %>;
font-stretch: <%= wdth %>;
src: url('<%= woff2Path %>') format('woff2');
unicode-range: <%= unicodeRange %>;
}
`
)
exports.readme = _.template(
`# Fontsource <%= fontName %>
[![npm version](https://badge.fury.io/js/fontsource-<%= fontId %>.svg)](https://www.npmjs.com/package/fontsource-<%= fontId %>) [![Generic badge](https://img.shields.io/badge/fontsource-passing-brightgreen)](https://github.com/fontsource/fontsource) [![Monthly downloads](https://badgen.net/npm/dm/fontsource-<%= fontId %>)](https://github.com/fontsource/fontsource) [![Total downloads](https://badgen.net/npm/dt/fontsource-<%= fontId %>)](https://github.com/fontsource/fontsource) [![GitHub stars](https://img.shields.io/github/stars/DecliningLotus/fontsource.svg?style=social&label=Star)](https://github.com/fontsource/fontsource/stargazers)
The CSS and web font files to easily self-host the “<%= fontName %>” font. Please visit the main [Fontsource monorepo](https://github.com/fontsource/fontsource) to view more details on this package.
## Installation
Fontsource assumes you are using a bundler, such as Webpack, to load in CSS. Solutions like [CRA](https://create-react-app.dev/), [Gatsby](https://www.gatsbyjs.org/) and [Next.js](https://nextjs.org/) are prebuilt examples that are compatible.
\`\`\`javascript
yarn add fontsource-<%= fontId %> // npm install fontsource-<%= fontId %>
\`\`\`
Then within your app entry file or site component, import it in. For example in Gatsby, you could choose to import it into a layout template (\`layout.js\`), page component (\`index.js\`), or \`gatsby-browser.js\`.
\`\`\`javascript
import "fontsource-<%= fontId %>" // Defaults to weight 400 with all styles included.
\`\`\`
Fontsource allows you to select weights and even individual styles, allowing you to cut down on payload sizes to the last byte! Utilizing the CSS unicode-range selector, all language subsets are accounted for.
\`\`\`javascript
import "fontsource-<%= fontId %>/500.css" // All styles included.
import "fontsource-<%= fontId %>/900-normal.css" // Select either normal or italic.
\`\`\`
Alternatively, the same solutions could be imported via SCSS!
\`\`\`scss
@import "~fontsource-<%= fontId %>/index.css";
@import "~fontsource-<%= fontId %>/300-italic.css";
\`\`\`
_These examples may not reflect actual compatibility. Please refer below._
Supported variables:
- Weights: \`[<%= weights %>]\`
- Styles: \`[<%= styles %>]\`
Finally, you can reference the font name in a CSS stylesheet, CSS Module, or CSS-in-JS.
\`\`\`css
body {
font-family: "<%= fontName %>";
}
\`\`\`
## Additional Options
In the rare case you need to individually select a language subset and not utilize the CSS unicode-range selector, you may specify the import as follows. This is especially not recommended for languages, such as Japanese, with a large amount of characters.
\`\`\`javascript
import "fontsource-<%= fontId %>/latin-ext.css" // All weights and styles included.
import "fontsource-<%= fontId %>/cyrillic-ext-500.css" // All styles included.
import "fontsource-<%= fontId %>/greek-900-normal.css" // Select either normal or italic.
\`\`\`
- Supported subsets: \`[<%= subsets %>]\`
## Licensing
It is important to always read the license for every font that you use.
Most of the fonts in the collection use the SIL Open Font License, v1.1. Some fonts use the Apache 2 license. The Ubuntu fonts use the Ubuntu Font License v1.0.
[Google Fonts License Attributions](https://fonts.google.com/attribution)
## Other Notes
Font version (provided by source): \`<%= version %>\`.
Feel free to star and contribute new ideas to this repository that aim to improve the performance of font loading, as well as expanding the existing library we already have. Any suggestions or ideas can be voiced via an [issue](https://github.com/fontsource/fontsource/issues).
`
)
exports.readmeVariable = _.template(
`# Fontsource <%= fontName %>
[![npm version](https://badge.fury.io/js/fontsource-<%= fontId %>.svg)](https://www.npmjs.com/package/fontsource-<%= fontId %>) [![Generic badge](https://img.shields.io/badge/fontsource-passing-brightgreen)](https://github.com/fontsource/fontsource) [![Monthly downloads](https://badgen.net/npm/dm/fontsource-<%= fontId %>)](https://github.com/fontsource/fontsource) [![Total downloads](https://badgen.net/npm/dt/fontsource-<%= fontId %>)](https://github.com/fontsource/fontsource) [![GitHub stars](https://img.shields.io/github/stars/DecliningLotus/fontsource.svg?style=social&label=Star)](https://github.com/fontsource/fontsource/stargazers)
The CSS and web font files to easily self-host the “<%= fontName %>” font. Please visit the main [Fontsource monorepo](https://github.com/fontsource/fontsource) to view more details on this package.
## Installation
Fontsource assumes you are using a bundler, such as Webpack, to load in CSS. Solutions like [CRA](https://create-react-app.dev/), [Gatsby](https://www.gatsbyjs.org/) and [Next.js](https://nextjs.org/) are prebuilt examples that are compatible.
\`\`\`javascript
yarn add fontsource-<%= fontId %> // npm install fontsource-<%= fontId %>
\`\`\`
Then within your app entry file or site component, import it in. For example in Gatsby, you could choose to import it into a layout template (\`layout.js\`), page component (\`index.js\`), or \`gatsby-browser.js\`.
\`\`\`javascript
import "fontsource-<%= fontId %>" // Defaults to weight 400 with all styles included.
\`\`\`
Fontsource allows you to select weights and even individual styles, allowing you to cut down on payload sizes to the last byte! Utilizing the CSS unicode-range selector, all language subsets are accounted for.
\`\`\`javascript
import "fontsource-<%= fontId %>/500.css" // All styles included.
import "fontsource-<%= fontId %>/900-normal.css" // Select either normal or italic.
\`\`\`
Alternatively, the same solutions could be imported via SCSS!
\`\`\`scss
@import "~fontsource-<%= fontId %>/index.css";
@import "~fontsource-<%= fontId %>/300-italic.css";
\`\`\`
_These examples may not reflect actual compatibility. Please refer below._
Supported variables:
- Weights: \`[<%= weights %>]\`
- Styles: \`[<%= styles %>]\`
Finally, you can reference the font name in a CSS stylesheet, CSS Module, or CSS-in-JS.
\`\`\`css
body {
font-family: "<%= fontName %>";
}
\`\`\`
## Variable Fonts
This particular typeface supports [variable fonts](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide).
Begin by importing both the variable and fallback font for non-compatible browsers.
\`\`\`js
import "fontsource-<%= fontId %>/400.css" // Weight 400
\`\`\`
Select either a stripped down weights only variant of the font or a full feature variant that contains all the variable axes.
\`\`\`js
import "fontsource-<%= fontId %>/variable.css" // Contains ONLY variable weights and no other axes. Both normal and italic.
import "fontsource-<%= fontId %>/variable-normal.css" // Normal variant.
import "fontsource-<%= fontId %>/variable-italic.css" // Italic variant.
// Or
import "fontsource-<%= fontId %>/variable-full.css" // This contains ALL variable axes. Font files are larger. Both normal and italic.
import "fontsource-<%= fontId %>/variable-full-normal.css" // Normal variant.
import "fontsource-<%= fontId %>/variable-full-italic.css" // Italic variant.
\`\`\`
Note a \`full\` or \`italic\` variant may NOT exist if there are no additional axes other than weight.
Followed by the CSS using the @supports tag, which checks whether the browser is capable of utilising variable fonts. Fallback fonts and their relevant CSS should be used outside the block, whilst all variable options should be used within the @supports block and utilising the font-variation-settings tag.
\`\`\`css
h1 {
font-family: <%= fontName %>;
font-weight: 400;
}
@supports (font-variation-settings: normal) {
h1 {
font-family: <%= fontName %>Variable;
font-variation-settings: "wght" 400;
}
}
\`\`\`
_To view the available variable axes that may be included in the font, click [here](https://fonts.google.com/variablefonts). The meanings of all axes and the restrictions associated with them are explained there._
## Additional Options
In the rare case you need to individually select a language subset and not utilize the CSS unicode-range selector, you may specify the import as follows. This is especially not recommended for languages, such as Japanese, with a large amount of characters.
\`\`\`javascript
import "fontsource-<%= fontId %>/latin-ext.css" // All weights and styles included.
import "fontsource-<%= fontId %>/cyrillic-ext-500.css" // All styles included.
import "fontsource-<%= fontId %>/greek-900-normal.css" // Select either normal or italic.
\`\`\`
- Supported subsets: \`[<%= subsets %>]\`
## Licensing
It is important to always read the license for every font that you use.
Most of the fonts in the collection use the SIL Open Font License, v1.1. Some fonts use the Apache 2 license. The Ubuntu fonts use the Ubuntu Font License v1.0.
[Google Fonts License Attributions](https://fonts.google.com/attribution)
## Other Notes
Font version (provided by source): \`<%= version %>\`.
Feel free to star and contribute new ideas to this repository that aim to improve the performance of font loading, as well as expanding the existing library we already have. Any suggestions or ideas can be voiced via an [issue](https://github.com/fontsource/fontsource/issues).
`
)