Turn audio into a shareable video. forked from nypublicradio/audiogram

fonts.js 1.0KB

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