Git Product home page Git Product logo

Comments (14)

albertogg avatar albertogg commented on August 24, 2024

Hi @mhulse, you could do something like:

{% for post in site.posts %}
    {% unless post.categories contains 'external' %}
        <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endif %}
{% endfor %}

I don't know if this helps

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Ooh, unless is available to use now? Nice!!! I'll give that a whirl and let you know how it goes. Thanks much @albertogg, I really appreciate it!

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Wait, unless has been available forever. What was I thinking. Lol. I must be thinking of some other filter. Anyway, I'll be back shortly with results.

from jekyll-help.

albertogg avatar albertogg commented on August 24, 2024

No problem!

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

So, I think the problem is that I need to grab the next non-external post in order to make the permalink-page to permalink-page navigation smooth.

Let me clarify my question:


On my Jekyll permalink pages (the post detail view) I have previous and next buttons:

{% if page.previous.url %} ... link to previous post ... {% endif %}
{% if page.next.url %} ... link to next post ... {% endif %}

That works great.

My problem:

How do I skip a next/previous post if it's of a certain type?

Specifically, I have some posts that are "external" links. They have a font matter value of "layout: external" (and a category of "external").

Goal:

I'd like to skip next/previous posts that are marked as external; in other words, if the next two posts were marked as "external", my "next" button would skip to the third post.

I can't think of an easy way to do this using liquid.


Maybe something like this (pseudo logic):

  1. On permalink page …
  2. … Get all posts as an object/array …
  3. … Filter out posts marked as "external" (maybe this can be done in step above) …
  4. … In object/array, find the current post …
  5. … Assign "prev" and "next" variables to previous and next post in object/array (i.e. the next and previous post from current post position).

I hope that makes more sense.


@albertogg

{% for post in site.posts %}
    {% unless post.categories contains 'external' %}
        <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endif %}
{% endfor %}

After having thought about this, the above will spit out all posts not marked "external". While that's a good technique to filter posts, I don't think it's going to work like I need it to on the permalink pagination. 😦

from jekyll-help.

albertogg avatar albertogg commented on August 24, 2024

I still don't understand quite well what you want to do. Do you have any existing code/repo I can check?

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Hi @albertogg, thanks again for the help! 👍

I'm not at a machine where I can slap together demo code, but when I am, I'll put together a simple demo to show you the problem I'm trying to solve.

The most simple way I can describe it:

On a post detail page (aka, permalink page) I have the Jekyll tags to get previous and next posts:

{% if page.previous.url %} ... link to previous post ... {% endif %}
{% if page.next.url %} ... link to next post ... {% endif %}

When clicking on the above links, I want to ignore next or previous pages that are "external" (i.e., isn't meant to have a permalink page as it takes the user to the external website).

Optimally, I'd like to have my next/previous page navigation to skip "external" links and just page through pages/posts that are not marked external.

I hope that helps to explain things better, though, I'm sure an example will make things clearer. 😆

With that said, this is kinda like what I want:

http://ajclarkson.co.uk/blog/jekyll-category-post-navigation/
https://gist.github.com/stravid/4078840

Except, I want to ignore a category (or, custom frontmatter key/value).

I probably should spend some more time coding up a plugin … I started this code:

mhulse/mhulse.github.io#31 (comment)

… but I don't remember if I ever got it working. I kinda gave up on the issue.

Since this repo was created, I thought I'd try again; I'm mostly curious if there's a way to do this using Liquid only. With Jekyll 2.0 coming out, maybe there's some new code that could make this happen using only template tags?

Anyway, I'll setup a demo site with minimal code as an example.

Thanks for listening to me ramble. :octocat:

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Oooh, the 2.0 where and group_by filters might be of some help here:

http://jekyllrb.com/docs/templates/#filters

from jekyll-help.

albertogg avatar albertogg commented on August 24, 2024

Oh, I'm sorry I haven't been very helpful... hope jekyll 2.0 will make it easier.

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Oh, I'm sorry I haven't been very helpful... hope jekyll 2.0 will make it easier.

@albertogg Oh, no, you've been very helpful! I'm sorry that I have not been describing my problem very well.

I'm not sure if the where or group_by will really help; I have yet to do any experimentation with Jekyll 2.0 … There might be some new liquid bits that may be of some help … I'm really not sure though.

I plan on setting up a simple demo this weekend if you are still interested in seeing a working example. I think once you see a demo of my problem then all will be clear. 👍

Thanks for all of your help on this! Again, I apologize if I've been too wordy and/or not clear in my exact problem.

from jekyll-help.

albertogg avatar albertogg commented on August 24, 2024

Yes, I'm interested on a demo to see if we can solve this. Don't worry about it, I know it's hard to explain and also english is not my first language.

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Yes, I'm interested on a demo to see if we can solve this.

Sounds good! I'll have a demo up this weekend. Whether or not it's solvable is one thing though … I may be trying to do something that's just not possible. 😆

Don't worry about it, I know it's hard to explain and also english is not my first language.

Wow, your English is very good! I would have never guessed. English is my only language, and as you can see, I'm not very good at it. Hehe.

I'll post a link as soon as I have a demo up. Thanks again Alberto!

from jekyll-help.

kleinfreund avatar kleinfreund commented on August 24, 2024

There is currently no way to filter the posts in paginator.posts. Thus, you only can build a pagination based on all of your posts, not just a couple of them.

from jekyll-help.

mhulse avatar mhulse commented on August 24, 2024

Ok, thanks for the help folks, I really appreciate it. I'm going to live without pagination on permalink pages. Also, I was afk all weekend, so I did not have a chance to create a demo. Oh well, looks like the demo would be moot anyway. Thanks again all!!!

from jekyll-help.

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.