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

Pin post to top [SOLVED] #651

Closed
Doogiemuc opened this issue Sep 9, 2019 · 3 comments
Closed

Pin post to top [SOLVED] #651

Doogiemuc opened this issue Sep 9, 2019 · 3 comments

Comments

@Doogiemuc
Copy link

Doogiemuc commented Sep 9, 2019

Summary

I would like to pin posts to the top of my blog.

Implementation suggestion

Add a pinned flag to the YAML at the top of a post's markdown file

---
title: Some post
author: Doogie
date: 2019-09-09T20:00:00Z
hero_image: "/src/assets/content/images/mandel-fractal.jpg"
pinned: true          // <====== THIS
---
Here comes the posts *markdown* ...

I already tried adding this. But somehow I cannot query it the page-query of Blog.vue. Error message: "Error: Cannot query field "pinned" on type "Blog". How can I add "metadata" fields to posts?

@Doogiemuc
Copy link
Author

Ok, meanwhile I found out that Gridsome has its built-in GraphQL schema for a "Post". So this needs some more digging around ... maybe create a Gridsome plugin? I am not sure what's the right path to take. I'd be glad for any hint or suggestion...

@Doogiemuc
Copy link
Author

[SOLVED] And suddenly it works.

Add the "pinned" variable to <page-query> of templates/Blog.vue

<page-query>
query getPostData ($path: String!) {
  post: blog(path: $path) {
    title
    date (format: "MMMM DD, YYYY")
    author
    content
    pinned     // <===== added
    hero_image (quality: 80)
}
all: allBlog { ... }

Then you can use it in components/BlogList.vue

<li v-if="post.node.pinned">

@Doogiemuc Doogiemuc changed the title Pin post to top [Question] Pin post to top [SOLVED] Sep 10, 2019
@hacknug
Copy link
Member

hacknug commented Sep 12, 2019

You could also sort your query by pinned and date to get your posts sorted the way you want without any need to render conditionally on your template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants