Giter VIP home page Giter VIP logo

Comments (2)

absolutejam avatar absolutejam commented on June 4, 2024

I don't know if this is what you're after, but have you tried using for {% page in site.html_pages %}?

I'm trying that approach and it seems to also include my .md pages (I'm guessing it's because they become .html once served). I don't know if this is standard behaviour, or if it's because I have supplied the 'permalink' front-matter on them (Eg. permalink: /about/ in about.md).

I have however had issues with using the above approach as it seems to ignore the limit argument, so I always have 10 suggested items (Which is too many for my liking). If I use just site.html_pages or use it along side site.posts, I get this issue.

My code is:

---

---
[
  {% for post in site.posts %}
    {
      "title"    : "{{ post.title | escape }}",
      "category" : "{{ post.category }}",
      "tags"     : "{{ post.tags | array_to_sentence_string }}",
      "url"      : "{{ site.baseurl }}{{ post.url }}",
      "date"     : "{{ post.date }}",
      "formatted-date" : "{{ post.date | date: '%b %-d, %Y' }}",
      "type"     : "Post"
    },
  {% endfor %}
  {% for page in site.html_pages %}
  {
    "title"    : "{{ page.title | escape }}",
    "url"      : "{{ site.baseurl }}{{ page.url }}",
    "type"     : "Page"
    }{% unless forloop.last %},{% endunless %}
  {% endfor %}
]

from simple-jekyll-search.

daviddarnes avatar daviddarnes commented on June 4, 2024

This looks pretty good! Thanks for your reply. Due to the project I am working on I have had to make a slight modification to how the json file outputs, I've had to figure out a way to exclude pages from the search. Here's what I have currently:

---
searchable: false
---
{% assign items = site.pages %}
[
    {% for item in items %}{% if item.searchable == false %}
        {
            "title"     : " ",
            "content"   : " ",
            "url"       : " ",
            "searchable": "{{ item.searchable }}"
        }{% else %}
        {
            "title"     : {{ item.title | jsonify }},
            "content"   : {{ item.content | jsonify }},
            "url"       : {{ item.url | jsonify }},
            "searchable": "{{ item.searchable }}"
        }{% endif %}{% unless forloop.last %},{% endunless %}
    {% endfor %}
]

Due to how the loop works I couldn't exclude 'non-searchable' pages from the json file as the forloop.last would then be incorrect and the trailing comma would sometimes fail to appear.

I believe I also had the 10 items limit issue, my new sample code avoids that but in not really in a clean way.

I'm sorry to go into so much detail with my case use, but I feel that explaining my real world usage of the plugin it will help with its development.

from simple-jekyll-search.

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.