Does Jekyll support searching blog posts by multiple tags? - filtering

Does Jekyll support searching blog posts by multiple tags? Based on the documentation, it seems like it supports tagging posts using multiple tags, but I'm wondering if it supports being able to filter posts using multiple tags when searching for a post

You can use the where filter. This code filters all posts that have the tags "jekyll" and "tutorial":
{% assign posts = site.posts | where: "tags", "jekyll" | where: "tags", "tutorial" %}
You can also use the where_exp filter:
{% assign posts = site.posts | where_exp: "item", "item.tags contains 'jekyll' and item.tags contains 'tutorial'" %}
Learn more about filters in the docs.

Related

CSV Data in jekyll: how to sort and display data according to "Publication year"

I am trying to work on a simple workflow to sort out my publications csv to a list in my jekyll-based website.
This is my references.csv extracted from referencing software Mendeley and converted from bib to csv using online converter. I want to place this in my _data folder and make a list of publications in the page on jekyll website hosted on github. The sampe data is shown below:
"Item type","Authors","Title","Journal","Publication year","Volume","Issue","Pages","Publisher","Date published","ISSN","URLs","DOI","PMID","Abstract","Keywords"
"Book","Wilden H","PCI design handbook: Precast and prestressed concrete","","2017","","","","Precast/Prestressed Concrete Institute Wakefield, MA, USA","2017","","","","","",""
"Journal Article","Nanni A,Di Ludovico M,Parretti R","Shear strengthening of a PC bridge girder with NSM CFRP rectangular bars","Advances in Structural Engineering","2004","7","4","297-309","SAGE PublicationsSage UK: London, England","2004-11","1369-4332","https://journals.sagepub.com/doi/10.1260/1369433041653570;http://dx.doi.org/10.1260/1369433041653570","10.1260/1369433041653570","","trimmed down abstract","keyword 1"
"Journal Article","Di B,Wang J,Li H,Zheng J,Zheng Y,Song G","Investigation of Bonding Behavior of FRP and Steel Bars in Self-Compacting Concrete Structures Using Acoustic Emission Method","Sensors 2019, Vol. 19, Page 159","2019","19","1","159","Multidisciplinary Digital Publishing Institute","2019-01","1424-8220","http://dx.doi.org/10.3390/S19010159;https://www.ncbi.nlm.nih.gov/pubmed/30621189","10.3390/S19010159","30621189","To extend ","FRP,acoustic emission,bonding,compacting concrete,out test,pull,self"
"Journal Article","Crivelli D,Bland S","Structural health monitoring via acoustic emission","Reinforced Plastics","2016","60","6","390-392","Elsevier Ltd","2016-11","0034-3617","http://dx.doi.org/10.1016/j.repl.2015.05.004","10.1016/j.repl.2015.05.004","","Reinforced Plastics spoke to Dr Davide Crivelli from the Politecnico di Milano about new methods for detecting damage in composites.",""
"Journal Article","Tonelli D,Luchetta M,Rossi F,Migliorino P,Zonta D","Structural health monitoring based on acoustic emissions: Validation on a prestressed concrete bridge tested to failure","Sensors (Switzerland)","2020","20","24","1-20","Multidisciplinary Digital Publishing Institute","2020-12","1424-8220","http://dx.doi.org/10.3390/s20247272;https://www.ncbi.nlm.nih.gov/pubmed/33352961","10.3390/s20247272","33352961","very small abstract","AE"
Now, I want to make the list from these data as a citation data without getting into complexities of _includes. I want to keep it simple in a separate "Publications" page.
For example, I used the following code
{% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
{% for card in cards %}
<ul>
<li>{{ card.Publication year }} {{ card.Title }} {{ card.Publication }} </li>
<ul> {{ card.Authors }} {{ card.Authors }} </ul>
</ul>
{% endfor %}
In the code, when I use the heading in csv as "Year" and then sort using sort: 'Year' | 'reverse' %,it works. Maybe, there is a different way to write it for "two-worded" headings, as I think the card.Publication year won't work. i have spent a lot of time on this and I think I need to just use the code once and then just work with the csv file only.
The output I intend to only pick up the Journal Article from the Item type and prepare a list with the following information with items shown in the following:
[Publication year][title][Journal]
[Authors]
Also, I tried italisizing the text in one of the items, it should work like {{ __card.Publication year__ }} but it does not. I also read somewhere that the csv encoding doesn't allow to extract the first column due to some BOM or UTF-8 something encoding. But I want to filter using the item type.
ps I have tried to compromise with another simplified code with headings same as this, but the google scholar exported csv has ; as delimiters and while using card.Authors does not work to call the data.
I apologize I am not at all familiar with this and I am struggling with using this syntax. However, I foresee that if the code works, it will make my life easier. I would really appreciate your help. I apologize for any lack of proper jargon while explaining the problem.
Thank you in advance.
I tried to display the data from csv data file on the website but some values are missing. I cannot figure out the solution
You're on the right track but you are incorrectly referencing the CSV file column. Since "Publication year" is a two-worded heading, you need to reference it using underscores instead of spaces.
Try changing this line:
{% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
You can use sort_by instead of sort and provide 'Publication_year' as an argument.
{% assign cards = site.data.references | sort_by: 'Publication_year' | reverse %}
When you reference the column in the for loop, you should also use underscores:
<li>{{ card.Publication_year }} {{ card.Title }} {{ card.Journal }} </li>

How to show the category name on the category listing page?

I've been using Wagtail for a while, for my basic website, but during the pandemic I've had to create online versions of all my courses -- I teach at a university -- and I've decided to do this in Wagtail. It's a much more robust solution than anything the university can provide. (I think a lot of people are in my situation.) It's been great so far, but I'm not a programmer (I teach Creative Writing!) and so I'm a bit out of my depth with a few things. Here's one thing I could use help with. I have categories (as per Kalob's tutorials), and I have category listing pages. I click on a category and I get a page showing just pages in that category. So far so good. But how would I show, on these listing pages, a header that says "Showing Pages in Category X"? Here's what I have in the models for my courses app (taken straight from Kalob's tutorial on categories):
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
context = self.get_context(request)
try:
# Look for the course category by its slug.
category = CourseCategory.objects.get(slug=cat_slug)
except Exception:
category = None
if category is None:
# This is an additional check.
pass
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
And here's what I have in the template for these category pages:
<ul class="menu-list">
{% for cat in categories %}
<li>
<a href="{% routablepageurl page "category_view" cat.slug %}">
{{ cat.name }}
</a>
</li>
{% endfor %}
</ul>
As Intended, the above shows all categories. How would I show only the category of the selected pages, so that I could put that in the title of the page? I've tried a few things, but as I said, I'm out of my depth here and I am just guessing and googling -- so far, without success. I know a lot of the ways to not make this work.
Not sure if I am missing something, but if you want to make the current category available to your template (the one based on the slug in the URL). You can add it to the context to make it available in your template, similar to how you are adding courses.
Example
my_model.py
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
# ... rest of the code from above
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
context["current_category"] = category
my_template.html
<h2>{{ page.title }} - {{ current_category }}

Symfony2 How to create specific collection widget for specific colletion in deep collection form nesting

I have little more complex problem, i have never done more than 1 nested form in an a form, which was fine to just include a custom collection widget template. (Reason: I need to re-code website based on laravel and Spaghetti code, with Spaghetti structure with tons of bugs and buggy patches, what i am fixing for a year now, and i have decided to recreate this app on my loved Symfony).
Let me write the structure:
Questionnaire (short name QN for later use)
- QN -
|_ QN Sections -
|_ QN Parts -
|_ QN Groups -
|_ QN Questions -
|_ some predefined answers
As you can see each QN can have Sections, these sections can have parts, these parts can have groups, and these groups can have questions, these questions have some conditional fields like if question type is "A,B,C" it has another nested collection form for these predefined answers,...
Problem is that for each of these collection form, i need to specify somehow a custom collection wiget template, because each of these collection form has different layout of fields, how they are displayed and handled.
Currently i have created a collection widget template that i include before QN Sections to style QN Sections, but this template is used also for his child collection form, what i need to avoid.
In a perfect world it should work like "prototype_template" => "some path", and then create javascript for each tempalte to add, remove, etc.
Here is an screenshot with some information how it looks now:
In final stage using these separate templates for each collection form, the "form builder" should look like actual web app.
If you need more informations please let me know, i will provide as much informations as i can.
To recap: I need somehow to specify for each nested collection form type to use different collection form widget template.
Thank you
Finnaly I got it.
The main collection template i have used was collection_widget block.
That was bad because it was too general. I hav renamed it to _questionnaire_questionnaireSections_widget, so the 1. level collection were themed. But after day of headake, 1000 combinations of form names i have got how to name the 2. level collection, its block name is "_questionnaire_questionnaireSections_entry_questionnaireParts_widget" what simply stand for "_mainFormTypeName_fieldNameOfFirstCLevelCollection_entry_FieldNameOfSecondLevelCollection_widget"
Than i just needed to place each template file to right place at the right moment.
edit.html.twig
{{ form_start(form) }}
{% form_theme form "::templates/collection/questionnaire/questionnaireSection.html.twig" %}
.........
{{ form_widget(form.questionnaireSections) }}
questionnaireSection.html.twig
{% block _questionnaire_questionnaireSections_widget %}
.............
{% for rows in form %}
{% form_theme form "::templates/collection/questionnaire/questionnairePart.html.twig" %}
questionnairePart.html.twig
{% block _questionnaire_questionnaireSections_entry_questionnaireParts_widget %}
So problem is solved, i have successfully themed nested collections. Thanks to myself and to symfony docs that has 0 words documentation to nested form theming, but they has some information about the "entry " part.

Symfony form, saving filtration through pagination

I use filtration form and pagination on same page to display great number of objects.
If i use POST form, after going through pagination filtration resets. If i use GET form filtration works, but URL is not clear and even have token.
Something like this:
?form[date_from][year]=&form[date_from][month]=&form[date_from][day]=&form[date_to][year]=&form[date_to][month]=&form[date_to][day]=&form[email]=email&form[submit]=&form[_token]=Nk0prilVJiROZaQQKvCt-hRfnKdh0IdDOWOIer
Is any way to make url more clear, hide token and unused parameters?
Well, i find no solution and write service for handling form filtration data in sessions.
Save filtration: use an array in controller:
$filter_array=[];
if ($search_form->isSubmitted() && $search_form->isValid()) {
$search_form->getData();
//save post/get form data without empty fields
$filter_array[$search_form->getName()]=array_filter(
$request->get($search_form->getName()),
function($value) { return $value !== ''; });
//... etc
}
Solution 1- make forms in your page links and add hidden fields with $filter_array
Solution 2- in page links use a script to add a hidden form field with page number and submit the form, simple but the form could be modified before click.
Solution 3- Put the paginator navigation and search results in a div, use jquery.load() for all actions (send form, page links, $( document ).ready() ...). The url will look like domain/page/#page_1:
{% for i in range(1, paginator.getTotalPages()) %}
<li {% if paginator.getPage() == i %} class="active"{%endif%}>
<a href="#page_{{i}}" onClick="
$('{{selector}}').load('{{ paginationPath }}',
{{filter_array|merge({page: i,})|json_encode()}});"
href="#page_{{i}}">{{ i }}</a>
</li>
{%endfor%}

tagging in umbraco 4.11 just like stackoverflow

im using snipper tag system and following below article:
http://daniel.streefkerkonline.com/tag/umbraco/
i can install and use snipper tag system successfully. but when i browse the page..tags appear as text and not hyper link...
Am i'm missing something. IS it some javascript file or im missing some step to include tags?
Any ideas?
here is my page:
http://www.leezardpharma.com/pharmacy/our-products/weight-loss-medicine/gastro1.aspx
here relevant tags are coming becuase of snipper ..but they arent clickable.
If you need to create tags as link with option to display the products which are tagged then you can create new page called ../search.aspx?tag=tagname
and then search for the products which are in that TAG, code is as below:
#inherits umbraco.MacroEngines.DynamicNodeContext
#using System.Text
#using umbraco.MacroEngines
#using umbraco.cms.businesslogic.Tags
#{
string searchFor = Request["tags"];
if(string.IsNullOrEmpty(searchFor))
{
#* No tags were specified *#
<p>Please specify a tag to search for</p>
return;
}
// this is to search from the tags added and then get all the nodes
var matchingNodes = Tag.GetNodesWithTags(searchFor).ToList();
string tagsText = searchFor.Split(',').Count() > 1 ? "tags" : "tag";
if (matchingNodes.Count < 1)
{
#* No results were found for the specified tags *#
<p>No tagged items were found that matched the #tagsText: #searchFor</p>
return;
}
#* Some results were found for the specified tags *#
<p><strong>#matchingNodes.Count</strong> products were found that matched the #tagsText: "#searchFor"</p>
<ul>
// go through the code and create URL for that product
#foreach (var node in matchingNodes)
{
dynamic dn = new DynamicNode(node.Id);
<li>#dn.Name</li>
}
</ul>
}
you can refer to this article as I have checked it click here and half way down you will see this code
Let me know any more explanation need. I have commented this so that you can get briefing of the code.
You sure you're doing this?
<ul>
#foreach (var node in matchingNodes)
{
dynamic dn = new DynamicNode(node.Id);
<li>#dn.Name</li>
}
</ul>
Something doesn't look right here, where you're displaying your tags:
Where are those two links coming from?
There's no javascript or anything fancy needed. This is all done in razor on the server-side.
I wrote the sniper tagging control.
If you want friendly URLs for the tags,
Create a rewrite rule to map /tags/([\w]*) rewrite to tagsearch.aspx?tag=$1
Then implement tagsearch.aspx to take that tag parameter and return any pages containing it as explained above.