mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-13 20:36:52 +00:00
Optimize related include (#33104)
This commit is contained in:
parent
e986103ebf
commit
5f0c3ff81b
27
plugins/site_pages.rb
Normal file
27
plugins/site_pages.rb
Normal file
@ -0,0 +1,27 @@
|
||||
module Jekyll
|
||||
class SitePagesGenerator < Jekyll::Generator
|
||||
def generate(site)
|
||||
all_pages = Array.new
|
||||
|
||||
site.collections.each do |name, collection|
|
||||
all_pages.concat(collection.docs)
|
||||
end
|
||||
|
||||
site.data["site_pages"] = all_pages
|
||||
.concat(site.pages)
|
||||
.concat(site.documents)
|
||||
.map { |entry|
|
||||
[
|
||||
entry.url.to_s,
|
||||
{
|
||||
"title" => entry["title"],
|
||||
"description" => entry["description"],
|
||||
"url" => entry.url,
|
||||
"relative_path" => entry.relative_path
|
||||
}
|
||||
]
|
||||
}
|
||||
.to_h
|
||||
end
|
||||
end
|
||||
end
|
@ -11,23 +11,19 @@
|
||||
<div class="text related-topics">
|
||||
<h2><a class="title-link" href="#related-topics" name="related-topics"></a>Related topics</h2>
|
||||
<ul>
|
||||
{% assign site_part = "pages,documents" | split: "," %}
|
||||
{%- for related in related_topics -%}
|
||||
{%- for part in site_part -%}
|
||||
{%- for entry in site[part] -%}
|
||||
{% assign computed = related.docs | split: "#" %}
|
||||
{% assign target_url = computed[0] %}
|
||||
{% assign target_page = site.data["site_pages"][target_url] %}
|
||||
{% unless target_page == null %}
|
||||
{% assign link_target = computed[1] %}
|
||||
{% assign suggested_title = related.title | default: link_target | split: "-" | join: " " | capitalize %}
|
||||
{%- if computed[0] == entry.url -%}
|
||||
<li>
|
||||
<a href="{{ entry.url | relative_url }}{% if link_target %}#{{link_target}}{% endif %}" class="topic">
|
||||
{{ suggested_title | default: entry.title}}
|
||||
<a href="{{ target_page['url'] | relative_url }}{% if link_target %}#{{link_target}}{% endif %}" class="topic">
|
||||
{{ suggested_title | default: target_page["title"]}}
|
||||
</a>
|
||||
</li>
|
||||
{% break %}{% break %}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{% endunless %}
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user