Giter VIP home page Giter VIP logo

Comments (3)

elmasse avatar elmasse commented on June 6, 2024

@vadimdemedes I'll add that as a feature in request to the list. Meanwhile, what I do is to mix withPosts and withPost on the same page. It might sound a bit strange, but you can get those in the same page.

Check the docs page in nextein-www. In that case I'm first filtering by an specific category to retrieve all posts in that category and subcategories.

https://github.com/elmasse/nextein-www/blob/master/pages/docs.js#L22:L24

But I agree that might become useful to list all categories without accessing the posts.

from nextein.

vadimdemedes avatar vadimdemedes commented on June 6, 2024

Ok, thanks!

from nextein.

elmasse avatar elmasse commented on June 6, 2024

As mentioned in #19, the experimental entries can be used to retrieve data / meta data from posts without making them part of the NEXT_DATA global in exported sites.

To add a list of categories to our page component we can do something like this:

import React, { Component } from 'react'
import withPosts, { entries } from 'nextein/posts'

export default withPosts(class Index extends Component {
  static async getInitialProps() {
    const all = await entries()
    const categories = [ ...new Set(all.map( p => p.data.category )) ] //unique values

   return { categories }
  }

  render () {
     const { posts, categories } = this.props

    return (/* Render your posts here */)
  }
})

It might be possible that the categories will be added to the API but I'm still trying to keep the API surface as minimum as possible.

Hope that helps. Please let me know your thoughts on that.

from nextein.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.