Created
March 1, 2018 14:55
-
-
Save lengshuiyulangcn/27ee0e58fb266800cad2a315ef7d3dc5 to your computer and use it in GitHub Desktop.
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
const nem = require("nem-sdk").default; | |
const address = "TAYFYAEQEV7URQSZZ3J3TRT3N6EYW2PEXTMWLL67"; | |
const fs = require("hexo-fs"); | |
const path = require("path"); | |
hexo.extend.filter.register('after_init', function(){ | |
var normal_endpoint = nem.model.objects.create("endpoint")(nem.model.nodes.defaultTestnet, nem.model.nodes.defaultPort); | |
nem.com.requests.account.transactions.incoming(normal_endpoint, address).then((res) => { | |
res.data.map(( d )=>{ | |
if(d.transaction.message.payload){ | |
var timeStamp = (new Date(d.transaction.timeStamp * 1000 + Date.UTC(2015, 2, 29, 0, 6, 25, 0))).toISOString() | |
timeStamp = timeStamp.replace('T', ' ').replace('.000Z', ' ') | |
var data = nem.utils.format.hexToUtf8( d.transaction.message.payload ) | |
var title = data.split("\n")[0].replace(/#/g, "") | |
data = data.split("\n").slice(1,-1).join("\n") | |
data = "---\n"+ "title: "+ title + "\n" +"date: " + timeStamp + "\n" + "tags: [] \n" + "---\n\n" + data | |
fs.writeFileSync(path.join('source/_posts/', d.meta.hash.data+".md"), data ) | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment