How to host google web fonts on my own server?

前端 未结 19 2065
闹比i
闹比i 2020-11-27 09:10

I need to use some google fonts on an intranet application. The clients may or may not have internet connection. Reading the license terms, it appears that its legally allo

19条回答
  •  半阙折子戏
    2020-11-27 09:22

    I used grunt-local-googlefont in a grunt task.

    module.exports = function(grunt) {
    
        grunt.initConfig({
           pkg: grunt.file.readJSON('package.json'),
    
            "local-googlefont" : {
                "opensans" : {
                    "options" : {
                        "family" : "Open Sans",
                        "sizes" : [
                            300,
                            400,
                            600
                        ],
                        "userAgents" : [
                            "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)",  //download eot
                            "Mozilla/5.0 (Linux; U; Android 4.1.2; nl-nl; GT-I9300 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", //download ttf
                            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1944.0 Safari/537.36" //download woff and woff2
                        ],
                        "cssDestination" : "build/fonts/css",
                        "fontDestination" : "build/fonts",
                        "styleSheetExtension" : "css",
                        "fontDestinationCssPrefix" : "fonts"
    
                    }
                }
            }
        });
    
        grunt.loadNpmTasks('grunt-local-googlefont');
     };
    

    Then, to retrieve them:

    grunt local-googlefont:opensans
    

    Note, I'm using a fork from the original, which works better when retrieving fonts with whitespaces in their names.

提交回复
热议问题