Last active
October 5, 2016 19:37
-
-
Save KagamiChan/3e3f17650287ac7e456a5865e6d12e59 to your computer and use it in GitHub Desktop.
jekyll fontmin plugin prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Fontmin = require('fontmin'); | |
var fs = require('fs') | |
var _ = require('lodash') | |
var srcPath = './SourceHanSansSC-Regular.ttf'; // 字体源文件 | |
var destPath = 'assets/webfont'; // 输出路径 | |
// var text = '中国' | |
var text | |
data = fs.readFileSync('./content.txt','utf8') | |
text = _.filter(data, function(e1,i,arr){return arr.indexOf(e1) === i}).join('')+"(),。“‘”’!?《》……·—" | |
// console.log(text.length) | |
// console.log(text) | |
// 初始化 | |
var fontmin = new Fontmin() | |
.src(srcPath) // 输入配置 | |
.use(Fontmin.glyph({ // 字型提取插件 | |
text: text // 所需文字 | |
})) | |
.use(Fontmin.ttf2eot()) // eot 转换插件 | |
.use(Fontmin.ttf2woff()) // woff 转换插件 | |
.use(Fontmin.ttf2svg()) // svg 转换插件 | |
.use(Fontmin.css()) // css 生成插件 | |
.dest(destPath); // 输出配置 | |
// 执行 | |
fontmin.run(function (err, files, stream) { | |
if (err) { // 异常捕捉 | |
console.error(err); | |
} | |
console.log('done'); // 成功 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
Jekyll::Hooks.register :site, :post_write do |site| | |
content = "" | |
for p in site.pages | |
content = content + Nokogiri::HTML(p.content).text.gsub(/\w/,"").scan(/\p{Han}|\p{Hiragana}|\p{Katakana}/).join(' ') | |
end | |
File.write('content.txt', content) | |
system 'node font.js' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment