<commit_before>var path = require('path');
var Poet = require('poet');
var blogModel = require('../config/docs');

module.exports = function (app) {
  // init config
  var poet = Poet(app, {
    posts: path.normalize(__dirname + '../../../_posts/'),
    postsPerPage: 5,
    metaFormat: 'json'
  });

  poet.addRoute('/docs', function (req, res, next) {
    var posts = poet.helpers.getPosts();
    if (posts.length) {
      blogModel.posts = posts;
      res.render('posts/index', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/:post', function (req, res, next) {
    var post = poet.helpers.getPost(req.params.post);
    if (post) {
      blogModel.post = post;
      res.render('posts/post', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/tag/:tag', function (req, res, next) {
    var posts = poet.helpers.postsWithTag(req.params.tag);
    if (posts) {
      blogModel.posts = posts;
      blogModel.tag = req.params.tag;
      res.render('posts/tag', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/page/:page', function (req, res) {
    var page = req.params.page,
        lastPost = page * 3;
    blogModel.posts = poet.helpers.getPosts(lastPost - 3, lastPost);
    blogModel.page = page;
    res.render('posts/page', blogModel);
  });
  
  poet.addRoute('/docs/category/:category', function (req, res, next) {
    var posts = poet.helpers.postsWithCategory(req.params.category);
    if (posts) {
      blogModel.posts = posts;
      res.render('posts/category', blogModel);
    } else {
      res.send(404);
    }
  }).init(function (err, poet) {
    console.log('poet init: ', err || 'successful'); 
  });

  poet.watch();

  // rss route for poet
  app.get('/blog-rss', function (req, res) {
    // Only get the latest posts
    var posts = poet.helpers.getPosts(0, 7);
    res.setHeader('Content-Type', 'text/rss+xml');
    res.render('posts/rss', { posts: posts });
  });

  app.get('/blogs-search', function (req, res) {
    var key = req.query.key;
    var posts = poet.helpers.getPosts();

    blogModel.posts = [];

    posts.forEach(function(post) {
      title = post.title.toLowerCase();
      if (title.indexOf(key.toLowerCase()) !== -1) {
        blogModel.posts.push(post);
      }
    });

    blogModel.key = key;
    res.render('posts/search', blogModel);
  });
}
<commit_msg>add search for blog content<commit_after>var path = require('path');
var Poet = require('poet');
var blogModel = require('../config/docs');

module.exports = function (app) {
  // init config
  var poet = Poet(app, {
    posts: path.normalize(__dirname + '../../../_posts/'),
    postsPerPage: 5,
    metaFormat: 'json'
  });

  poet.addRoute('/docs', function (req, res, next) {
    var posts = poet.helpers.getPosts();
    if (posts.length) {
      blogModel.posts = posts;
      res.render('posts/index', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/:post', function (req, res, next) {
    var post = poet.helpers.getPost(req.params.post);
    if (post) {
      blogModel.post = post;
      res.render('posts/post', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/tag/:tag', function (req, res, next) {
    var posts = poet.helpers.postsWithTag(req.params.tag);
    if (posts) {
      blogModel.posts = posts;
      blogModel.tag = req.params.tag;
      res.render('posts/tag', blogModel);
    } else {
      res.send(404);
    }
  });

  poet.addRoute('/docs/page/:page', function (req, res) {
    var page = req.params.page,
        lastPost = page * 3;
    blogModel.posts = poet.helpers.getPosts(lastPost - 3, lastPost);
    blogModel.page = page;
    res.render('posts/page', blogModel);
  });
  
  poet.addRoute('/docs/category/:category', function (req, res, next) {
    var posts = poet.helpers.postsWithCategory(req.params.category);
    if (posts) {
      blogModel.posts = posts;
      res.render('posts/category', blogModel);
    } else {
      res.send(404);
    }
  }).init(function (err, poet) {
    console.log('poet init: ', err || 'successful'); 
  });

  poet.watch();

  // rss route for poet
  app.get('/blog-rss', function (req, res) {
    // Only get the latest posts
    var posts = poet.helpers.getPosts(0, 7);
    res.setHeader('Content-Type', 'text/rss+xml');
    res.render('posts/rss', { posts: posts });
  });

  app.get('/blogs-search', function (req, res) {
    var key = req.query.key;
    var posts = poet.helpers.getPosts();

    blogModel.posts = [];

    posts.forEach(function(post) {
      var title = post.title.toLowerCase();
      var content = post.content.toLowerCase();
      if (title.indexOf(key.toLowerCase()) !== -1) {
        blogModel.posts.push(post);
      } else if (content.indexOf(key.toLowerCase()) !== -1){
        blogModel.posts.push(post);
      } else {
      }
    });

    blogModel.key = key;
    res.render('posts/search', blogModel);
  });
}

{'fraction_non_alphanumeric': 0.17983159582999197, 'fraction_numerical': 0.007417802726543705, 'mean_word_length': 2.654945054945055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258164', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1692, 'n_words': 334}