recordset.forEach(function (record) { importer.addPost({ id: record.ID, title: record.Name, name: record.Code, description: record.PageDescription, date: record.Published, status: 'publish', author: 'tranquangvinh', contentEncoded: record.Content, excerptEncoded: record.Summary, categories: [{ title: "Tin tức", slug: "tin-tuc" }] }); importer.addAttachment({ title: record.Name, author: 'tranquangvinh', description: record.PageDescription, parent: record.ID, attachmentURL: record.File }) });
async run() { let importer = new Wxr(); let posts = await this.getPosts(); for(let post of posts) { post.content = post.content.replace(NOT_SAFE_IN_XML, ''); post.summary = post.summary.replace(NOT_SAFE_IN_XML, ''); importer.addPost({ id: post.id, title: post.title, date: think.datetime(post.create_time), contentEncoded: post.content, excerptEncoded: post.summary, categories: post.cate }) } let cateList = await this.model('cate').select(); for(let cate of cateList) { importer.addCategory({ id: cate.id, title: cate.name, slug: cate.pathname }); } try { fs.writeFileSync( this.outputFile, importer.stringify() ) return this.outputFile; } catch (e) { throw new Error(e); } }