nodeclub/bin/fix_at_problem.js
2016-04-20 01:43:35 +08:00

19 lines
485 B
JavaScript

// 一次性脚本
// 修复之前重复编辑帖子会导致重复 @someone 的渲染问题
var TopicModel = require('../models').Topic;
TopicModel.find({content: /\[{2,}@/}).exec(function (err, topics) {
topics.forEach(function (topic) {
topic.content = fix(topic.content);
console.log(topic.id);
topic.save();
});
});
function fix(str) {
str = str.replace(/\[{1,}(\[@\w+)(\]\(.+?\))\2+/, function (match_text, $1, $2) {
return $1 + $2;
});
return str;
}