Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related Posts plugin #26

Open
4 tasks
aileen opened this issue Jan 14, 2019 · 4 comments
Open
4 tasks

Related Posts plugin #26

aileen opened this issue Jan 14, 2019 · 4 comments
Labels
feature New feature or request help wanted Community project needs info

Comments

@aileen
Copy link
Member

aileen commented Jan 14, 2019

Problem description

It is possible to fetch related posts based on how many tags they have in common. A current implementation of that can be found in the Ghost Docs repository here. This code is very specific to the Ghost Docs requirements and also very messy.

There are probably better solutions to solve this, but this one works and can be a good starting point to create a plugin for the

Proposal

I had a play with this already, trying to add related posts to the GraphQL schema, but wasn't successful. This might be due to my lack of GraphQL knowledge, or simply because it's not possible that way.

The working solution in Ghost Docs inserts the related posts into the PageContext which is another option (not such a nice one, as having it available with a pretty GraphQL query) to implement this.

Maybe (probably) there are even better ways on doing that? This needs further research.

Todos

  • investigate do-ability and different options further
  • write up tech spec and agree on solution with core team
  • implement a general plugin for related Ghost posts, that can be configured
  • publish plugin
@aileen aileen added help wanted Community project feature New feature or request needs info labels Jan 14, 2019
@imballa
Copy link

imballa commented Nov 20, 2019

Any update on this ?, How we can show related posts on frontend just like ghost's casper theme ?

@styxlab
Copy link
Contributor

styxlab commented Feb 19, 2020

See my casper-v3 fork for a solution. The trick is to use grapghql queries in post.js like so:

        post: ghostPost(slug: { eq: $slug }) {
            ...GhostPostFields
        }
        prev: ghostPost(slug: { eq: $prev }) {
            ...GhostPostFields
        }
        next: ghostPost(slug: { eq: $next }) {
            ...GhostPostFields
        }

which can be accessed with data.post, data.prev and data.next. The query parameters are computed in gatsby-node.js. This solution is very clean and does not pollute the PageContext.

@fabianstarke
Copy link

@styxlab your link to your Casper fork is broken. I am really blocked as I would like to list all posts having the same tags as current post. Where you be able to solve that? Thanks

@javaadpatel
Copy link

for anyone looking for a hacky solution to this, i've been able to get related posts showing
image

I'm not a GraphQL expert and this isn't a plugin but you can find the code used here. I'm basically using the allGhostPost query and then filtering that on the related tags manually, ideally you'd use the filter property inside that query but I couldn't figure out how to pass in the parameter to filter on.

It's not the greatest but I hope it helps someone who was stuck like me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Community project needs info
Projects
None yet
Development

No branches or pull requests

5 participants