Example #1
0
 function updatePreviewSummary () {
   var teaserHtml = getHtml(teaser);
   var editorNoteHtml = getHtml(editorNote);
   var introductionHtml = getHtml(introduction);
   var bodyHtml = getHtml(body);
   var summarized = articleSummarizationService.summarize({
     summary: summary.value(),
     teaserHtml: teaserHtml,
     introductionHtml: introductionHtml
   });
   var parts = [teaserHtml, editorNoteHtml || '', introductionHtml, bodyHtml];
   var readingTime = estimate.text(parts.join(' '));
   var publication = datetimeService.field(moment().add(4, 'days'));
   var article = {
     publication: publication,
     commentCount: 0,
     slug: slug.value(),
     readingTime: readingTime,
     titleHtml: getHtmlTitle(),
     tags: getTags(),
     author: {
       displayName: viewModel.authorDisplayName
     },
     summaryHtml: summarized.html
   };
   var vm = { articles: [article] };
   taunus.partial(previewSummary, 'articles/columns', vm);
 }
Example #2
0
function toJSON (source) {
  var text = [source.teaserHtml, source.bodyHtml].join(' ');
  var article = source.toJSON();

  article.readingTime = estimate.text(text);
  article.permalink = '/articles/' + article.slug;

  if (source.populated('comments')) {
    article.commentThreads = article.comments.sort(byPublication).reduce(threads, []);
    article.commentCount = article.comments.length;
  }

  if (source.populated('prev')) {
    article.prev = relevant(article.prev);
  } else {
    delete article.prev;
  }
  if (source.populated('next')) {
    article.next = relevant(article.next);
  } else {
    delete article.next;
  }
  if (source.populated('related')) {
    article.related = article.related.map(relevant);
  } else {
    delete article.related;
  }

  delete article.__v;
  delete article.sign;
  delete article.teaser;
  delete article.body;
  delete article.comments;
  return article;
}
Example #3
0
function toJSON (source, options) {
  var o = options || {};
  var text = [source.teaserHtml, source.introductionHtml, source.bodyHtml].join(' ');
  var article = source.toJSON();

  article.permalink = '/articles/' + article.slug;
  article.publication = datetimeService.field(article.publication);
  article.updated = datetimeService.field(article.updated);
  article.readingTime = estimate.text(text);
  article.gitHref = url.resolve(gitWeb, `${moment(article.created).format('YYYY/MM-DD')}--${article.slug}`);

  if (source.populated('author')) {
    article.author = {
      displayName: article.author.displayName,
      slug: article.author.slug,
      twitter: article.author.twitter,
      website: article.author.website
    };
    if (source.author.email) {
      article.author.avatar = userService.getAvatar(source.author);
    }
  } else {
    delete article.author;
  }

  commentService.hydrate(article, source);

  if (source.populated('prev')) {
    article.prev = relevant(article.prev);
  } else {
    delete article.prev;
  }
  if (source.populated('next')) {
    article.next = relevant(article.next);
  } else {
    delete article.next;
  }
  if (source.populated('related')) {
    article.related = article.related.map(relevant);
  } else {
    delete article.related;
  }

  if (o.id === false) {
    delete article._id;
  }
  if (o.summary !== true) {
    delete article.summaryHtml;
  }
  if (o.meta) {
    delete article.teaserHtml;
    delete article.editorNoteHtml;
    delete article.introductionHtml;
    delete article.bodyHtml;
  }
  delete article.__v;
  delete article.sign;
  delete article.teaser;
  delete article.introduction;
  delete article.body;
  delete article.titleMarkdown;
  delete article.summary;
  delete article.summaryText;
  delete article.comments;
  delete article.hn;
  delete article.echojs;
  delete article.tweet;
  delete article.fb;
  delete article.email;
  return article;
}