Jekyll Sorting Accentuated Characters - jekyll

I'm failing to sort posts titles containing accentuated characters.
Using:
{% assign sorted_posts = (site.posts | sort: 'title') %}
I get:
Aujourd'hui Dimanche
Bientôt la nuit
À vendre
What I would like is getting:
Aujourd'hui Dimanche
À vendre
Bientôt la nuit
In other word, make as if 'A' was equal to 'À'.
Any clue?
Thanks in advance

I'm afraid that the only solution is to make a generator plugin that use I18n.transliterate to transform accented characters from title and create something like a slug field for each post.
Posts will then be sortable by slug.

Related

Split HTML in a certain form of list in Python

For a django project i need to generate from the Django Website a kind of complex Word document.
I started using Docx-Template that do the job great but i encountered a problem:
For certain "spot" in the word template i need to brake Django rich texte (HTML) in something usable for Docx Template
So i went into transforming my richtext in a list that can have two types of elements (to keep the order of the blocs) : ["some paragraphs","('list',['first elt of the list for bullet','second','ect...")]
For now i have two function : one that break the HTML and one that transform it
My "HTML Breaking function" is like that :
def decoupe_html (raw_html):
soup=BeautifulSoup(raw_html,"html.parser")
arbre=[]
#decoupe en grand bloc HTML
for elt in soup:
arbre.append(elt)
print(arbre)
#On parcours chaque elt pour le transformer en truc compréhensible par Word dans une liste
for elt in arbre:
#recup du tag de début du "chunk"
tag=elt.name
#traitement des paragraphe de texte
if tag == "p":
texte=elt.text
place=arbre.index(elt)
arbre[place]=texte
#traitement des listes
elif tag == "ul":
list_elt=[]
enfants = elt.findChildren()
#on récupère tous les elt de la liste
for chld in enfants:
list_elt.append(chld.text)
place=arbre.index(elt)
arbre[place]=("list",list_elt)
return(arbre)
But i have trouble in "breaking" more complex list with multi level like for example this html :
<p>pfoizepfkjze</p>
<ul>
<li>blabla
<ul>
<li>bla2
<ul>
<li>bla3
<ul>
<li>bla4</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>rebla</li>
</ul>
what should i change in my code to keep my data structure and get for example :
arbre = ['pfoizepfkjze',('list',['blabla',('list',['bla2',('list',['bla3',('list',['bla4'])])]),'rebla'])]
Thanks all for your help :)

Microsoft translator changing phrase where there are html spans

Plain english sentence is:
While in 5th direct and ready for the downshift to 4th overdrive, push
the range preselection lever down.
Converts to French correctly as:
Alors que dans le 5ème direct et prêt pour le downshift à la 4ème
overdrive, pousser le levier de présélection de gamme vers le bas.
However, when including html (&textType=html), the phrase doesn't have the same meaning:
While in 5th direct and ready for the downshift to <span data-id="xyz123">4th overdrive</span>, push the range preselection lever down.
Translates to:
Alors que dans le 5ème direct et prêt pour le downshift à 4e
overdrive, pousser la gamme levier de présélection duvet.
The tags are considered an additional token in the sentence. Similar effect as punctuation, both having an effect on the translation.

How to create a switch that changes the content of the page?

I have a drupal site 8 th I use Twig to customize my pages.
I created 2 blocks view :
drupal_view('message_activity_stream_timeline_public', 'block_1') }}
drupal_view('message_activity_stream_timeline_private', 'block_1') }}
On my homepage, I want to put a switch that goes from block_1 to block_2 and vice versa.
When the switch is on the position PUBLIC it must display the block drupal_view('message_activity_stream_timeline_public', 'block_1') }}.
When the switch is on the position PRIVÉ it must display the block drupal_view('message_activity_stream_timeline_private', 'block_1') }}.
It is not necessary to memorize the position.
How can I do this ?
Here is my page :
<div class="home-page-header-bottom">
<h5>Fil d’actualité <button type="button" class="btn btn-default btn-tooltip" data-toggle="tooltip" data-placement="bottom" title="Le fil d'actualité public affiche en temps réel toute l'activité publique qui se déroule sur le site. Le fil d'actualité privé affiche en temps réel uniquement l'activité publique des pages que vous aimez et l'activité privée liée à votre compte. Lorsque vous êtes connecté, vous pouvez basculer d'un fil d'actualité à l'autre."><i class="fas fa-info-circle fa-lg"></i></button></h5>
<div class="toggle-on-off">
<span class="toggle-on-off-public">PUBLIC</span>
<i class="fas fa-toggle-on fa-rotate-180 fa-3x"></i>
<span class="toggle-on-off-prive">PRIVÉ</span>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 home-page-footer">
<div class="col-md-12 timelines">
<div class="main-timeline">
{{ drupal_view('message_activity_stream_timeline_public', 'block_1') }}
{{ drupal_view('message_activity_stream_timeline_private', 'block_1') }}
</div>
</div>
</div>
Can you explain to me how to get the method with reloading the page and without reloading the page ?
You can set additional variables to send to a template using hook_preprocess_HOOK(), and then use that value within a twig conditional.
You'll also need to consider caching, otherwise Drupal's Dynamic Page Cache may store the rendered page fragment the first time it's needed and server it to all later users.
function MY_MODULE_hook_preprocess_ELEMENT(&$variables) {
// Add a variable to send to the template.
$variables['new_variable'] = TRUE;
// Add the appropriate cache contexts so that the template is re-rendered when needed.
$variables['#cache']['contexts'][] = 'session';
}

XPath for href links based on anchor text substring

I have this HTML and I need to make an XPath to find all the "A1" text and get the href of all those elements of the page. It has multiple A1s in the page but I need all the hrefs.
I can't crack it.
<a href="./leitor.do?numero=20090&keyword=ministro&anchor=5975889&origem=busca" class="edition" title="Folha de S.Paulo">
<figure>
<img src="https://acervo.folha.uol.com.br/files/flip/11/89/58/97/5975889/140/5975889.jpg" width="180" height="312.4">
</figure>
<h3>31.dez.2014</h3>
<p>
país. Poder Novo <b>ministro</b> diz que Congresso irá ?expurgar? culpados futuro articulador polí
</p>
<small>
Folha de S.Paulo, Ano 94 - N° 20.090<br>
A1 - 1 ocorrência
</small>
</a>
This XPath,
//a[contains(.,"A1")]/#href
will return all href attributes on a elements with string values that contain an "A1" substring.
You don't have to use XPath for that. You can use driver.find_elements_by_partial_link_text("A1"), and on each of the returned element, call element.get_attribute("href")
You can combine it to one line as follows:
all_hrefs=[el.get_attribute("href") for el in driver.find_elements_by_partial_link_text("A1")]

Loop incrementation for url

I want to insert dynamic url from my title, it works but it displays 6*6 'cause of 2 differents loops... I don't know how to do differently...
I tried to use global variable but it's the same... (I have 6 Recipes)
Thanks !
Code XML :
<recette id="r1">
<titre>Cake au chocolat</titre>
<cat>dessert</cat>
<type/>
<nombre>6</nombre>
<listeingredients>
<ingredient q="150" u="g">chocolat pâtissier</ingredient>
<ingredient q="3" u="pièce">oeufs</ingredient>
<ingredient q="100" u="g">sucre en poudre</ingredient>
<ingredient q="60" u="g">farine</ingredient>
<ingredient q="1" u="cuillère à café">levure</ingredient>
<ingredient q="80" u="g">beurre</ingredient>
<ingredient q="50" u="g">poudre d'amandes</ingredient>
</listeingredients>
<cuisson>
<temps type="preparation">15</temps>
<temps type="cuisson">30</temps>
<temperature u="C">180</temperature>
</cuisson>
</recette>
<recette id="r2">
<titre>Brownies aux noix de pécan</titre>
<cat>dessert</cat>
<type/>
<nombre>6</nombre>
<listeingredients>
<ingredient q="200" u="g">chocolat à cuire</ingredient>
<cuisson>
<temps type="preparation">10</temps>
<temps type="cuisson">25</temps>
<temperature u="C">180</temperature>
</cuisson>
<instruction>
<etape>Faire fondre le chocolat avec le beurre, soit au bain-marie à feu doux, soit au micro-ondes sur programme 'décongélation'.</etape>
<etape>Quand c'est bien fondu, mélanger et ajouter le sucre, les oeufs un par un, la farine, puis les noix de pécan hachées grossièrement.</etape>
<etape>Bien mélanger et verser dans un moule carré de 20 cm (ou rectangulaire pas trop grand), chemisé de papier sulfurisé.</etape>
<etape>Mettre au four préchauffé à 180°C pendant 25 min.</etape>
<etape>Laisser refroidir et couper en carrés.</etape>
</instruction>
</recette>
</listerecettes>
Code xq :
{
for $titre in db:open("recettes")//recette//titre, $j in (6,2,1,5,4,3)
order by $titre
return
<a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='r{$j}']">
<ul>
<li>
{
$titre
}
</li>
</ul>
</a>
}
</body>
</html>
After your comment I still don't really know what you want to achieve with $j as it is not useful at all and can simply be removed. So I guess you maybe want something else and not just a simple list ordered by thte title - If so, please clearify what you want to achieve. Otherwise, simply removing the $j and using the id attribute will work fine.
for $recette in db:open("recettes")//recette
let $titre := $recette/titre
order by $titre
return
<a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='{$recette/#id}']">
<ul>
<li>
{
$titre
}
</li>
</ul>
</a>
Thank you but I had just found an other way ! :
for $titre in db:open("recettes")//recette//titre
order by $titre
return
<a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='{$titre/..//#id}']">
<ul>
<li>
{
$titre
}
</li>
</ul>
</a>
I tested your code and it's correct but you've forget "$titre" after order by !