-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
templates.js
140 lines (114 loc) · 4.97 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
const _ = require(`lodash`)
exports.packageJson = _.template(
`{
"name": "fontsource-<%= fontId %>",
"version": "3.1.0",
"description": "<%= fontName %> font in NPM glory.",
"main": "index.css",
"keywords": [
"fontsource",
"font",
"font family",
"<%= 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.packageJsonRebuild = _.template(
`{
"name": "<%= name %>",
"version": "<%= version %>",
"description": "<%= fontName %> font in NPM glory.",
"main": "index.css",
"keywords": [
"fontsource",
"font",
"font family",
"<%= 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:
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.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/fontsource/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 normal variant.
\`\`\`
Fontsource allows you to select font subsets, weights and even individual styles, allowing you to cut down on payload sizes to the last byte! The default selection above, however, sticks to the Latin subset including all weights and styles.
\`\`\`javascript
import "fontsource-<%= fontId %>/latin-ext.css" // All weights with normal style included.
import "fontsource-<%= fontId %>/cyrillic-ext-500.css" // Weight 500 with normal style.
import "fontsource-<%= fontId %>/greek-900-italic.css" // Italic variant.
\`\`\`
Alternatively, the same solutions could be imported via SCSS!
\`\`\`scss
@import "~fontsource-<%= fontId %>/index.css"; // Weight 400.
@import "~fontsource-<%= fontId %>/vietnamese-300-italic.css";
\`\`\`
_These examples may not reflect actual compatibility. Please refer below._
Supported variables:
- Subsets: \`[<%= subsets %>]\`
- 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 %>";
}
\`\`\`
## 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.
Font [Source](<%= source %>) and [License](<%= license %>).
## 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).
`
)