按Jekyll中的姓氏排序

按Jekyll中的姓氏排序,jekyll,Jekyll,我正在管理一个静态博客,其中有大量的人名列表。我需要按姓氏的字母顺序对这些人进行分类。如果姓氏是一个字符串,如何按姓氏排序?例如: {%assign People=John Smith,Foo Bar,Zee Mack Arlington | split:,%} {%assign sortedPeople=People | sort_natural%} {sortedPeople%中的人员的百分比} {{person}} {%endfor%} 这给了我一个按名字字母顺序排列的人的列表,但我需要按

我正在管理一个静态博客,其中有大量的人名列表。我需要按姓氏的字母顺序对这些人进行分类。如果姓氏是一个字符串,如何按姓氏排序?例如:

{%assign People=John Smith,Foo Bar,Zee Mack Arlington | split:,%} {%assign sortedPeople=People | sort_natural%} {sortedPeople%中的人员的百分比} {{person}}

{%endfor%} 这给了我一个按名字字母顺序排列的人的列表,但我需要按姓氏排序

Foo Bar
Zee Mack Arlington
John Smith

液体在设计上有点限制,但这里有一种方法:

{% assign sorted_names = "" | split: "" %}
{% assign names_prefixed_with_last = "" | split: "" %}

{% assign names = "John Smith, Foo Bar, Zee Mack Arlington" | split: "," %}

{% for name in names %}
  {% assign name_parts = name | split: " " %}
  {% assign last_name = name_parts | last %}
  {% assign name_prefixed_with_last = name | prepend: last_name %}
  {% assign names_prefixed_with_last = names_prefixed_with_last | push: name_prefixed_with_last %}
{% endfor %}

{% assign sorted_with_prefix = names_prefixed_with_last | sort %}

{% for name_with_prefix in sorted_with_prefix %}
  {% assign name_parts = name_with_prefix | split: " " %}
  {% assign last_name = name_parts | last %}
  {% assign name = name_with_prefix | replace_first: last_name %}
  {% assign sorted_names = sorted_names | push: name %}
{% endfor %}

{% for name in sorted_names %}
  <p>{{ name }}</p>
{% endfor %}
这将产生:

<p>Zee Mack Arlington</p>
<p>Foo Bar</p>
<p>John Smith</p>
首先,我们使用拆分空字符串技巧创建两个数组,然后用以姓氏为前缀的名称填充数组,例如Smith John Smith。然后我们对它进行排序,因为它将按姓氏排序,然后用已排序的值填充一个数组,前缀为已移除的数组


虽然我对问题范围没有任何其他知识,但更好的方法可能是将其与其他内容排序,并将其放入数据文件中。您也可以将它们存储在一个数组中,而不是一个庞大而笨重的字符串中。

液体在设计上有点限制,但这里有一种方法:

{% assign sorted_names = "" | split: "" %}
{% assign names_prefixed_with_last = "" | split: "" %}

{% assign names = "John Smith, Foo Bar, Zee Mack Arlington" | split: "," %}

{% for name in names %}
  {% assign name_parts = name | split: " " %}
  {% assign last_name = name_parts | last %}
  {% assign name_prefixed_with_last = name | prepend: last_name %}
  {% assign names_prefixed_with_last = names_prefixed_with_last | push: name_prefixed_with_last %}
{% endfor %}

{% assign sorted_with_prefix = names_prefixed_with_last | sort %}

{% for name_with_prefix in sorted_with_prefix %}
  {% assign name_parts = name_with_prefix | split: " " %}
  {% assign last_name = name_parts | last %}
  {% assign name = name_with_prefix | replace_first: last_name %}
  {% assign sorted_names = sorted_names | push: name %}
{% endfor %}

{% for name in sorted_names %}
  <p>{{ name }}</p>
{% endfor %}
这将产生:

<p>Zee Mack Arlington</p>
<p>Foo Bar</p>
<p>John Smith</p>
首先,我们使用拆分空字符串技巧创建两个数组,然后用以姓氏为前缀的名称填充数组,例如Smith John Smith。然后我们对它进行排序,因为它将按姓氏排序,然后用已排序的值填充一个数组,前缀为已移除的数组


虽然我对问题范围没有任何其他知识,但更好的方法可能是将其与其他内容排序,并将其放入数据文件中。您还可以将它们存储在一个数组中,而不是一个庞大而笨重的字符串。

感谢您的解决方案。如果没有你的帮助,我想我永远也做不到谢谢你的解决方案。如果没有你的帮助,我想我永远也做不到