Skip to Content
🎉 Nextra 4.0 is released. dimaMachina is looking for a new job or consulting .
DocumentationBlog ThemeGet Posts and Their Tags

Get Posts and Their Tags

The following code snippet demonstrates how to retrieve all posts along with their associated tags.

app/posts/get-posts.js
import { normalizePages } from 'nextra/normalize-pages' import { getPageMap } from 'nextra/page-map' export async function getPosts() { const { directories } = normalizePages({ list: await getPageMap('/posts'), route: '/posts' }) return directories .filter(post => post.name !== 'index') .sort((a, b) => new Date(b.frontMatter.date) - new Date(a.frontMatter.date)) } export async function getTags() { const posts = await getPosts() const tags = posts.flatMap(post => post.frontMatter.tags) return tags }
Last updated on