Include search in jekyll site with angularjs - angularjs

I am trying to implement search in jekyll using angularjs but not able to display . can anyone suggest me how can i plan for search in jekyll site using angularjs.
on submit of search text need to shoe list of blog posts with search text. how can i form search.json and how can add filter to load page faster .
another problem is can we use same index.html which is for blog
{% for post in paginator.posts %}
<div class="entry">
{% include blog/post_header.html post=post %}
<div>
{{ post.excerpt | markdownify }}
<p>Read post <i class="fa fa-arrow-right"></i></p>
</div>
</div>
{% endfor %}
to again display filtered blogs ?

Related

How do I reference my site's title in a template?

I'm starting a Wagtail site. In the admin section, I went to Settings >> Sites >> localhost, and set "Site name" to "My first Wagtail site."
How do I display the site title in templates using Django code?
The tag to use is:
{{ request.site.site_name }}
Old version
<h1>Welcome to the {{ request.site.site_name }} website!</h1>
new version
{% load wagtailcore_tags %}
{% wagtail_site as current_site %}
<h1>Welcome to the {{ current_site.site_name }} website!</h1>
Reference: https://docs.wagtail.io/en/stable/releases/2.9.html#upgrade-considerations
in wagtail 4.1,use {{page.get_site}} in template.

How to access default page models in template wagtail

So this awesome Wagtail/Django framework is nice!
I like it allot.
Still getting used to but seems straight forward,
What I do not understand tho is how can I access default page models and render them in the templates?
So Wagtail has this models that you make based on their Page class.
class SomeClass(Page):
"""
Some text
"""
intro = models.CharField(max_length=255, blank=True)
body_small = models.CharField(max_length=255, blank=True)
All good and well.
Now my page template looks like this
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% block base_content %}
{{ page.intro }}
{{ page.body_small }}
{% endblock %}
Now I want to add the settings model items like Published Date.
Those are default from Wagtail, see:
What page model do I need to use?
{{ page.published_date }} //Does not work
Any suggestions?
The fields in the Settings tab are available as {{ page.go_live_at }} and {{ page.expire_at }}. However, these are only used for scheduled publishing so may not be a particularly relevant thing to output on the page - {{ page.first_published_at }} and {{ page.last_published_at }} are probably more useful. See http://docs.wagtail.io/en/stable/reference/pages/model_reference.html for more.

Jekyll nested front matter not displaying in layout template for loop

I am trying to loop over a nested list in my posts font matter and display an associated image (using svg) for each nested item
post front matter:
---
layout: post
title: title of this post
spec:
- name: tee
- name: mobile
---
using a for loop in my post.html file
<div>
<h4>specs</h4>
{% for item in page.spec %}
<svg class='spec-icon'><use xlink:href="#icons_{{item.name}}"/</svg>
{% endfor %}
</div>
I would like this to render like below
<div>
<h4>specs</h4>
<svg class='spec-icon'><use xlink:href="#icons_tee"/></svg>
<svg class='spec-icon'><use xlink:href="#icons_mobile"/></svg>
</div>
for every neseted name:vale pair under spec:, I would like there to be a unique svg element created with that nested value included in the #id
???
Try this:
---
layout: post
title: title of this post
spec: [tee, mobile]
---
Then:
<div>
<h4>specs</h4>
{% for item in page.spec %}
<svg class='spec-icon'><use xlink:href="#icons_{{ item }}"/</svg>
{% endfor %}
</div>
Hope to have helped! Let me know if this works, yeah?

Jekyll — Loop through posts with title and number

I'm building a simple blog using Jekyll. I'm looping through all of my posts which works a treat. However, I'd like to add a number marker to each post. For example the first post would be marked with a 1, second with a 2... and so on.
My current loop likes like this:
<ol class="post-list">
{% for post in site.posts %}
<li class="post-item">
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">
<div class="post-info">
<p>Post #1</p>
<h2>{{ post.title }}</h2>
</div>
</a>
</li>
{% endfor %}
</ol>
I understand I need to add a count to this loop but I'm unsure how.
Adding the following to my loop seems to make sense:
{% for num in (1...n) %}
But I'm not sure how to use this with my existing loop.
Any help would be gratefully received.
In each liquid loop you have a counter out of the box : forloop
Change : <p>Post #1</p> for : <p>Post #{{ forloop.index }}</p>
Documentation here.
If you don't need to count them automatically you can simple add the variable to your posts:
---
number: 1
---
Than call it via
{{ post.number }}

django code is execude only once in an angular ng-repeat

All,
I have some HTML in an Angular "ng-repeat" block which includes calling a Django template tag. However, that tag only gets called once. Here is a contrived example:
my_template.html
<div ng-repeat="item in items" ng-init="items=['a','b','c']">
{% verbatim %}
the item is: {{a}}
{% endverbatim %}
the template tag returns: {% my_template_tag %}
</div>
my_template_tags.py
my_generator = (i for i in ['a','b','c'])
#register.simple_tag
def my_template_tag():
return my_generator.next()
This correctly renders 3 divs but they have the wrong content:
<div...>
the item is: a
the template tag returns: a
</div>
<div...>
the item is: b
the template tag returns: a
</div>
<div...>
the item is: c
the template tag returns: a
</div>
That template tag is only being called once. Does anybody know why?
Thanks.
The Django template is rendering the HTML before Angular does anything. The Django template has no knowledge that you're going to do an iteration on the front end. So, when Django is done processing, the code looks like this:
<div ng-repeat="item in items" ng-init="items=['a','b','c']">
the item is: {{a}}
the template tag returns: a
</div>
If you're iterating with the Django template, you need to actually render all the divs you want to create on the server side. The Django iteration doesn't really mix with the ng-repeat you have on the front-end.

Resources