Takes an array `posts` of sorted posts and returns
a sorted array with all categories

@params {Array} posts
@returns {Array}
557083
function getCategories (posts) {
  var categories = posts.reduce(function (categories, post) {
    if (!post.category) return categories;
    return categories.concat(post.category);
  }, []);

  return _.unique(categories).sort();
}
607044
def get_categories(self):
        
        posts = self.get_posts(include_draft=True)
        result = {}
        for post in posts:
            for category_name in set(post.categories):
                result[category_name] = result.setdefault(
                    category_name,
                    Pair(0, 0)) + Pair(1, 0 if post.is_draft else 1)
        return list(result.items())
1312926
private function addHierarchyOfSingularCrumbs( $post ) {
		$post_type = get_post_type_object( $post->post_type );
		if ( $post_type && $post_type->has_archive ) {
			$this->addCrumb(
				$this->label('post_type', $post_type->label ),
				get_post_type_archive_link( $post_type->name )
			);
		}
		if ( is_post_type_hierarchical( $post_type->name ) ) {
			$ancestors = array_reverse( get_post_ancestors( $post ) );
			if ( $ancestors ) {
				$ancestor_posts = get_posts( [
					'post_type' => $post_type->name,
					'include'   => join(',', $ancestors )
				] );
				foreach ( $ancestors as $ancestor ) {
					foreach ( $ancestor_posts as $ancestor_post ) {
						if ( $ancestor == $ancestor_post->ID ) {
							$this->addCrumb( $ancestor_post->post_title, get_permalink( $ancestor_post ) );
						}
					}
				}
			}
		} else {
			$post_type_taxonomies = get_object_taxonomies( $post_type->name, false );
			if ( is_array( $post_type_taxonomies ) && count( $post_type_taxonomies ) ) {
				foreach ( $post_type_taxonomies as $tax_slug => $taxonomy ) {
					if ( $taxonomy->hierarchical ) {
						$terms = get_the_terms( $post->ID, $tax_slug );
						if ( $terms ) {
							$term = array_shift( $terms );
							if ( $term->parent != 0 ) {
								$ancestors = array_reverse( get_ancestors( $term->term_id, $tax_slug ) );
								foreach ( $ancestors as $ancestor_id ) {
									$ancestor = get_term( $ancestor_id, $tax_slug );
									$this->addCrumb( $ancestor->name, get_term_link( $ancestor, $tax_slug ) );
								}
							}
							$this->addCrumb( $term->name, get_term_link( $term, $tax_slug ) );
							break;
						}
					}
				}
			}
		}
	}
1148420
function ctc_get_posts() {

		// Base arguments
		$args = array(
			'orderby'         	=> $this->ctc_instance['orderby'],
			'order'           	=> $this->ctc_instance['order'],
			'numberposts'     	=> $this->ctc_instance['limit'],
			'suppress_filters'	=> false // keep WPML from showing posts from all languages: http://bit.ly/I1JIlV + http://bit.ly/1f9GZ7D
		);

		// Group argument
		if ( 'all' != $this->ctc_instance['category'] ) {
			$args['category'] = $this->ctc_instance['category']; // ID
		}

		// Get posts
		$posts = get_posts( $args );

		// Return filtered
		return apply_filters( 'ctc_posts_widget_get_posts', $posts );

	}
1052818
def _format(self, posts):
        
        if posts.__class__ == Post:
            # format a single post
            return posts.dict()
        formated_posts = []
        for post in posts:
            formated_posts.append(post.dict())
        return formated_posts
964941
function sortComments(comments) {
    var moduleComments = [];
    var typeComments = [];
    var varComments = [];
    var methodComments = [];
    var typelessComments = [];

    comments.forEach(function (comment) {
        if(comment.type) {
            switch(comment.type) {
                case exports.COMMENT_TYPES.MODULE:
                    moduleComments.push(comment);
                    break;
                case exports.COMMENT_TYPES.METHOD:
                    methodComments.push(comment);
                    break;
                case exports.COMMENT_TYPES.TYPE:
                    typeComments.push(comment);
                    break;
                case exports.COMMENT_TYPES.VARIABLE:
                    varComments.push(comment);
                    break;
            }
        } else {
            typelessComments.push(comment);
        }
    });

    return moduleComments.concat(typeComments.concat(varComments.concat(methodComments.concat(typelessComments))));
}
934739
def retrieve_posts(dir)
      site.posts.docs.concat(PostReader.new(site).read_posts(dir))
      site.posts.docs.concat(PostReader.new(site).read_drafts(dir)) if site.show_drafts
    end
832200
function ctc_get_posts() {

		$posts = array();

		// Base arguments
		$args = array(
			'post_type'			=> 'attachment',
			'post_status'		=> 'inherit', // for attachments
			'post_mime_type'	=> 'image',
			'posts_per_page'	=> $this->ctc_instance['limit'],
			'orderby'			=> $this->ctc_instance['orderby'],
			'order'				=> $this->ctc_instance['order'],
			'no_found_rows'		=> true // faster
		);

		// All Galleries - get images attached to Gallery posts/pages
		if ( 'all' == $this->ctc_instance['post_id'] || empty( $this->ctc_instance['post_id'] ) ) {
			$args['post_parent__in'] = ctc_gallery_posts_ids(); // get all Gallery post IDs into array
		}

		// Specififc Gallery - get images used in shortcodes on post/page
		// Getting IDs from shortcode attributes since post may have images not attached to it
		else {

			// Get data for one post
			$posts = ctc_gallery_posts( array(
				'post_id' => $this->ctc_instance['post_id']
			) );

			// Use ID's from shortcode attributes
			if ( ! empty( $posts[$this->ctc_instance['post_id']]['image_ids'] ) ) {
				$args['post__in'] = $posts[$this->ctc_instance['post_id']]['image_ids'];
			}

		}

		// Get gallery images
		if ( ! empty( $args['post_parent__in'] ) || ! empty( $args['post__in'] ) ) { // if have something to search for
			$images_query = new WP_Query( $args );
			$posts = ! empty( $images_query->posts ) ? $images_query->posts : array();
		}

		// Return filtered
		return apply_filters( 'ctc_gallery_widget_get_posts', $posts );

	}
1204848
def get_posts(self, include_draft=False, filter_functions=None):
        

        def posts_generator(path):
            """Loads valid posts one by one in the given path."""
            if os.path.isdir(path):
                for file in os.listdir(path):
                    filename, ext = os.path.splitext(file)
                    format_name = get_standard_format_name(ext[1:])
                    if format_name is not None and re.match(
                            r'\d{4}-\d{2}-\d{2}-.+', filename):
                        # the format is supported and the filename is valid,
                        # so load this post
                        post = Post()
                        post.format = format_name
                        post.meta, post.raw_content = FileStorage.read_file(
                            os.path.join(path, file))
                        post.rel_url = filename.replace('-', '/', 3) + '/'
                        post.unique_key = '/post/' + post.rel_url
                        yield post

        posts_path = os.path.join(current_app.instance_path, 'posts')
        result = filter(lambda p: include_draft or not p.is_draft,
                        posts_generator(posts_path))
        result = self._filter_result(result, filter_functions)

        return sorted(result, key=lambda p: p.created, reverse=True)
859026
function getPost(post) {
  if (!post || !post.body) return {};


  let postQuery = getPostQuery(post.body);
  let postIntro = postQuery.intro || getPostIntro(post.body);

  Object.assign(post, {
    intro: postIntro,
    query: postQuery,
    create_time: formatTime(post.created_at),
    update_time: formatTime(post.updated_at)
  })

  return post;
}
1305297
function posts (content, contentType) {
  let output = {}
  const allFiles = content.filter(each => each.dir.includes(`/${contentType}`))
  const index = allFiles.filter(each => each.base === 'index.md')[0]
  index.attr.forEach(each => {
    allFiles.forEach(file => {
      if (file.name === each) {
        output[each] = file
      }
    })
  })
  return output
}
515021
function getTags (posts) {
  var tags = posts.reduce(function (tags, post) {
    if (!post.tags || !Array.isArray(post.tags)) return tags;
    return tags.concat(post.tags);
  }, []);

  return _.unique(tags).sort();
}
136765
def blog__get_posts(
      order: nil,
      language: nil,
      category_permalink: nil,
      category_permalink_AND: false,
      category_id: nil,
      category_id_AND: false,
      tag_permalink: nil,
      tag_permalink_AND: false,
      tag_id: nil,
      tag_id_AND: false,
      search: nil,
      page: nil,
      per_page: nil
    )
      posts = LatoBlog::Post.published.joins(:post_parent).where('lato_blog_post_parents.publication_datetime <= ?', DateTime.now)

      # apply filters
      order = order && order == 'ASC' ? 'ASC' : 'DESC'
      posts = _posts_filter_by_order(posts, order)
      posts = _posts_filter_by_language(posts, language)
      if category_permalink || category_id
        posts = posts.joins(:categories)
        posts = _posts_filter_by_category_permalink(posts, category_permalink, category_permalink_AND)
        posts = _posts_filter_category_id(posts, category_id, category_id_AND)
      end
      if tag_permalink || tag_id
        posts = posts.joins(:tags)
        posts = _posts_filter_by_tag_permalink(posts, tag_permalink, tag_permalink_AND)
        posts = _posts_filter_tag_id(posts, tag_id, tag_id_AND)
      end
      posts = _posts_filter_search(posts, search)

      # take posts uniqueness
      posts = posts.uniq(&:id)

      # save total posts
      total = posts.length

      # manage pagination
      page = page&.to_i || 1
      per_page = per_page&.to_i || 20
      posts = core__paginate_array(posts, per_page, page)

      # return result
      {
        posts: posts && !posts.empty? ? posts.map(&:serialize) : [],
        page: page,
        per_page: per_page,
        order: order,
        total: total
      }
    end
1359886
public function getPostsByCategory($category)
    {
        if (false === array_key_exists($category, $this->categoryIndex)) {
            return [];
        }

        $postNames = $this->categoryIndex[$category];

        return $this->getPostsByName($postNames);
    }
162419
def community_posts_list(self, filter_by=None, sort_by=None, **kwargs):
        ""
        api_path = "/api/v2/community/posts.json"
        api_query = {}
        if "query" in kwargs.keys():
            api_query.update(kwargs["query"])
            del kwargs["query"]
        if filter_by:
            api_query.update({
                "filter_by": filter_by,
            })
        if sort_by:
            api_query.update({
                "sort_by": sort_by,
            })
        return self.call(api_path, query=api_query, **kwargs)
399724
def posts_from(response)
      response.fetch('posts', EMPTY_ARRAY).map do |post_hash|
        Post.from_hash(post_hash)
      end
    end
671802
function sortPostsByPublishedDate (pPosts) {
    if (! (pPosts instanceof Array) ) {
        throw new MeowError ("pPosts is not an array");
    }

    pPosts.sort(function (pFirst, pSecond) {
        pFirst = pFirst || {};
        pSecond = pSecond || {};
        var pFirstPublishedDate  = pFirst['published-date'],
            pSecondPublishedDate = pSecond['published-date'];

        if (moment(pFirstPublishedDate).isAfter(pSecondPublishedDate)) {
            return -1;
        }
        else if (moment(pFirstPublishedDate).isBefore(pSecondPublishedDate)) {
            return 1;
        }
        else {
            return pFirst.title.localeCompare(pSecond.title);
        }
    });
    return pPosts;
}