Comments (14)
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.
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.
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.
No problem!
from jekyll-help.
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):
- On permalink page …
- … Get all posts as an object/array …
- … Filter out posts marked as "external" (maybe this can be done in step above) …
- … In object/array, find the current post …
- … 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.
{% 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.
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.
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.
from jekyll-help.
Oooh, the 2.0 where
and group_by
filters might be of some help here:
http://jekyllrb.com/docs/templates/#filters
from jekyll-help.
Oh, I'm sorry I haven't been very helpful... hope jekyll 2.0 will make it easier.
from jekyll-help.
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.
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.
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.
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.
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)
- undefined method 'activate_bin_path' HOT 1
- files not able to be accessed HOT 1
- bundle problem HOT 1
- Bundler could not find compatible versions for gem “kramdown” HOT 1
- Jekyll Error not helpful HOT 1
- Every thing is perfect in local server. But not in GitHub. HOT 1
- favicon for minima theme HOT 1
- Installation Process NEED HELP HOT 1
- Jekyll Server Stripping URLs From Generated Code HOT 1
- Jekyll category names from folder name & frontmatter HOT 1
- cannot install HOT 1
- jniujhcv HOT 1
- Saving a file while running jekyll serve causes an error HOT 1
- GH-pages build and local jekyll build have different display formats for posts HOT 1
- Need Jekyll Help in running multiple jekyll instances on different port and using nginx server HOT 1
- Installation fails on CentOS 7 due to dependencies HOT 1
- Jekyll Build Not Working after MacOS High Sierra Update HOT 1
- Accessing specific data items not working HOT 1
- Jekyll not found after running gem install HOT 1
- GitHub published site appears much different than local site HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jekyll-help.