|
@@ -0,0 +1,50 @@
|
|
1
|
+var fonts = require("../lib/settings/").fonts;
|
|
2
|
+
|
|
3
|
+var bySlug = {};
|
|
4
|
+
|
|
5
|
+fonts.forEach(function(font, i){
|
|
6
|
+
|
|
7
|
+ var extension = "",
|
|
8
|
+ split = font.file.split(".");
|
|
9
|
+
|
|
10
|
+ // Use existing extension if there is one
|
|
11
|
+ if (split.length > 1){
|
|
12
|
+ extension = "." + split.pop();
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ bySlug[font.slug = "custom-" + i + extension] = font;
|
|
16
|
+
|
|
17
|
+});
|
|
18
|
+
|
|
19
|
+function sendCSS(req, res) {
|
|
20
|
+ res.set("Content-Type", "text/css")
|
|
21
|
+ .send(fonts.map(declaration).join("\n\n"));
|
|
22
|
+}
|
|
23
|
+
|
|
24
|
+function sendFont(req, res) {
|
|
25
|
+
|
|
26
|
+ var font = bySlug[req.params.font];
|
|
27
|
+
|
|
28
|
+ if (font && font.file) {
|
|
29
|
+ return res.sendFile(font.file);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ res.status(500).send("Cannot GET " + req.baseUrl);
|
|
33
|
+
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+function declaration(font, i) {
|
|
37
|
+ return [
|
|
38
|
+ "@font-face {",
|
|
39
|
+ " font-family: '" + font.family + "';",
|
|
40
|
+ " src: url('/fonts/" + font.slug + "');",
|
|
41
|
+ font.weight ? " font-weight: " + font.weight + ";" : "",
|
|
42
|
+ font.style ? " font-style: " + font.style + ";" : "",
|
|
43
|
+ "}"
|
|
44
|
+ ].filter(function(d){ return d; }).join("\n");
|
|
45
|
+}
|
|
46
|
+
|
|
47
|
+module.exports = {
|
|
48
|
+ css: sendCSS,
|
|
49
|
+ font: sendFont
|
|
50
|
+};
|