pinclub/pinclub

View on GitHub
bin/fix_at_problem.js

Summary

Maintainability
A
0 mins
Test Coverage
// 一次性脚本
// 修复之前重复编辑帖子会导致重复 @someone 的渲染问题
var TopicModel = require('../models').Topic;

function fix(str) {
    str = str.replace(/\[{1,}(\[@\w+)(\]\(.+?\))\2+/, function (match_text, $1, $2) {
        return $1 + $2;
    });
    return str;
}

TopicModel.find({content: /\[{2,}@/}).exec(function (err, topics) {
  topics.forEach(function (topic) {
    topic.content = fix(topic.content);
    console.log(topic.id);
    topic.save();
  });
});