How to get latest 10 post's link in jekyll

I want to get latest 10 post’s url to my page. How to do it? thanks.

You can loop over site.posts and then limit it to whatever amount you need.

Example:

{% for post in site.posts limit:10 %}
  {{ post.url }}
{% endfor %}

Thanks. I also need to iterate pages. I use jekyll paginate v1. Can I use like below?

{% for paginator.page in paginator.total_pages %}
{{ paginator.page }},
{% endfor %}

I tried like

{% for page in (1..paginator.total_pages) %}

'/page{{ page }}/',
{% endfor %}

But seems to be not working. I am not adding this code to index.html, but for a js file with empty front matter.

Try iterating over site.pages

{% for page in site.pages limit:10 %}
  {{ page.url }}
{% endfor %}

It gives pages url like /about/index.html. But what I need is jekyll-paginator page url like http://example.com/page2 and http://example.com/page3.

This should do what you want.

{% assign page_start = 2 %}
{% assign page_end = paginator.total_pages %}

{% for index in (page_start..page_end) %}
  {{ site.paginate_path | replace: ':num', index | relative_url }}
{% endfor %}

Your last solution not working for me, may be I added quote around code like "{{ site.paginate_path | replace: ':num', index | relative_url }}". First solution works.

{% for page in site.pages limit:10 %}
  {{ page.url }}
{% endfor %}

It gives links page2 and page3, but also gives other pages like /about and /contact. Can I avoid it using codes

Sure anything is possible if you want to create some logic in the Liquid to pull out those pages.

site.pages is every page available to Jekyll. That’s why you’re seeing paginator pages and normal content pages like About and Contact.

There might be a better way of approaching it with some further context on what you’re trying to do exactly with these arrays of latest posts/pages.