const eng = ['a','b','c','d','e','f','g','h','i','j'];
//文件名Base64后 根据算法从编码中取10位作为新文件名 function getNewNameBase64(fileName){ var fi_bs64 = Buffer.from(fileName).toString('base64')//转成base64编码 var arr = fi_bs64.split(""); var len = arr.length; var fis = ""; for(var i=1;i<=10;i++){ var s1 = arr[Math.floor(len/(2*i))]; if(s1=='/'||s1=='+'){ var eng_index = Math.floor(Math.random()*10+1); s1 = eng[eng_index-1]; } fis = fis + s1; } return fis; } /** * fitler hexo's post, auto generate `abbrlink` * * @param log * @param data */ function filterPost(log, data) { if (!data.abbrlink) { data.abbrlink = getNewNameBase64(data.title); log.i("Generate abbrlink [%s] for post [%s]", data.abbrlink, data.source); } } hexo.extend.filter.register('before_post_render', function (data) { if (data.layout === 'post') { filterPost(this.log, data); } return data; });
生产的文件格式如下:
1 2 3 4 5 6 7 8 9
INFO Generated: pages/KP6qyyyLLL.html INFO Generated: pages/eejFFWWWWW.html INFO Generated: pages/DWujXduull.html INFO Generated: pages/sphaII00ll.html INFO Generated: pages/525Cmmbbbb.html INFO Generated: pages/5q5FaaYYYY.html INFO Generated: pages/pYjduulllG.html INFO Generated: pages/iXjnbpdddd.html INFO Generated: pages/5S50ll2222.html