client.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Configure accounts-ui.
  3. */
  4. Accounts.ui.config({
  5. passwordSignupFields: "USERNAME_ONLY"
  6. });
  7. // Routing.
  8. Router.configure({
  9. layoutTemplate: "layout"
  10. });
  11. Router.route("/", function () {
  12. this.render("page_home", { to: "contents" });
  13. });
  14. Router.route("/recommend", function () {
  15. let likedDocs;
  16. let recommended;
  17. if (isLoggedIn()) {
  18. let userId = Meteor.userId();
  19. recommended = [];
  20. let aWords, similar, wordsRegex;
  21. likedDocs = Websites.find({ plus: { $in: [userId] }}).fetch();
  22. likedDocs.forEach(function (liked) {
  23. aWords = liked.words.split(' ');
  24. wordsRegex = new RegExp(aWords.join(' .*'));
  25. let criteria = {
  26. _id: {$ne: liked._id},
  27. words: { $regex: wordsRegex }
  28. };
  29. similar = Websites.find(criteria).fetch();
  30. recommended.push({ liked, similar });
  31. });
  32. }
  33. else {
  34. recommended = null;
  35. }
  36. this.render("page_recommend", {
  37. to: "contents",
  38. data: { recommended }
  39. });
  40. });
  41. Router.route("/search/:search", function () {
  42. const search = this.params.search;
  43. this.render("page_search", {
  44. to: "contents",
  45. data: {
  46. search,
  47. result: Websites.find({ words: { $regex: new RegExp(search) } }).fetch()
  48. }
  49. });
  50. });
  51. Router.route("/site/:id", function () {
  52. const id = this.params.id;
  53. const doc = _.extend({ onPage: true }, Websites.findOne({ _id: id }));
  54. this.render("page_site", {
  55. to: "contents",
  56. data: function () {
  57. return doc;
  58. }
  59. });
  60. });