Templates archives and related pages redefined

This commit is contained in:
pmoreno.rodriguez 2023-08-13 12:49:59 +02:00
parent 7ed17be931
commit 2363970749
3 changed files with 68 additions and 37 deletions

38
templates/partials/archives.html.twig Normal file → Executable file
View file

@ -1,25 +1,13 @@
<section>
<ul class="posts">
{% for p in page.find(theme_config.blog_page).children.order('date', 'desc').slice(0, 5) %}
{% set image = p.media[p.header.primaryImage] ?: p.media.images|first %}
{% set title = p.title|raw %}
<li>
<article>
<header>
<h3>
<a href="{{p.url}}">{{ title }}</a>
</h3>
{% if config.plugins["translate-date"].enabled %}
<time class="published" datetime="{{ p.date|td(null, "Y-m-d") }}">{{ p.date|td(null, "M j, Y") }}</time>
{% else %}
<time class="published" datetime="{{ p.date|date("Y-m-d") }}">{{ p.date|date("M j, Y") }}</time>
{% endif %}
</header>
<a href="{{p.url}}" class="image" aria-label="{{ title }}">
{{ image.cropZoom(64,64).quality(60).loading('lazy').attribute('decoding','async').html(title,title)|raw }}
</a>
</article>
</li>
{% endfor %}
</ul>
</section>
<ul class="alt">
{% for month,items in archives_data %}
<li>
<a href="{{ base_url }}/{{ config.plugins.archives.taxonomy_names.month }}{{ config.system.param_sep }}{{ month|date('M_Y')|lower|e('url') }}">
{% if archives_show_count %}
<span class="label label-circle">{{ items|length }}</span>
{% endif %}
<span class="archive_date">{{ month|date(config.plugins.archives.date_display_format) }} </span>
</a>
</li>
{% endfor %}
</ul>

38
templates/partials/relatedpages.html.twig Normal file → Executable file
View file

@ -1,13 +1,33 @@
<ul class="related-pages">
{% for related_path, score in related_pages %}
<section>
<ul class="posts">
{% for related_path, score in related_pages %}
{% set related = grav['pages'].get(related_path) %}
{% set related_image = related.media.images[related.header.primaryImage] ?: related.media.all|filter((v, k) => k != related.header.avatarImage and (v.type == 'image' ))|first %}
{% if related %}
<li>
<a href="{{ related.url }}" title="{{ related.title }}">{{ related.title }}</a>
{% if config.plugins.relatedpages.show_score %}
<span class="score">( {{ score }} )</span>
{% endif %}
</li>
<li>
<article>
{% if related.taxonomy.category is not null %}
<header>
<h3><a class="" href="{{ related.url }}" title="{{ related.title }}" rel="nofollow">{{ related.title }}</a></h3>
<small class="published">
In <span class="catlist">
{% for category in related.taxonomy.category %}
<a class="" href="{{ new_base_url }}/category{{ config.system.param_sep }}{{ category }}">{{ category|raw }}</a>{% if not loop.last %}<span class="sep">, </span>{% endif %}
{% endfor %}
</span>
</small>
</header>
{% if related_image is not empty %}
<a class="image" aria-label="{{ related.title }}" href="{{ related.url }}">
{{ related_image.cropResize(64,64).loading('lazy').attribute('decoding','async').html|raw }}
</a>
{% endif %}
{% endif %}
</article>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
</section>

View file

@ -1,3 +1,12 @@
{% set blog = page.find(header_var('blog_url')|defined(theme_var('blog_page'))) %}
{% set new_base_url = blog.url == '/' ? '' : blog.url %}
{% if uri.params %}
{% set feed_url = blog.url == '/' or blog.url == base_url_relative ? (uri.uri~'/'~blog.slug) : blog.url %}
{% else %}
{% set feed_url = blog.url == '/' or blog.url == base_url_relative ? (base_url_relative~'/'~blog.slug) : blog.url %}
{% endif %}
<section id="menu">
<div style="padding: 1.5em;"><a class="close" href="#menu" title="Menu"></a></div>
{% if config.plugins.simplesearch.enabled %}
@ -10,16 +19,17 @@
<div id="sidebarmenu">
{% include 'partials/sidebar_navigation.html.twig' %}
</div>
{% if config.plugins.archives.enabled and archives_data is not empty %}
<!-- Actions -->
{% if config.plugins.archives.enabled and archives_data is not empty %}
<!-- Archives -->
<div>
<header>
<h3>{{ 'FUTURE.SIDEBAR.ARCHIVES.HEADLINE'|t }}</h3>
</header>
{% include 'partials/archives.html.twig' %}
{% include 'partials/archives.html.twig' with {'base_url': new_base_url} %}
</div>
{% endif %}
{% if config.plugins.relatedpages.enabled and related_pages|length > 0 %}
<!-- Related posts -->
<div>
<header>
<h3>{{ 'FUTURE.SIDEBAR.RELATED_POSTS.HEADLINE'|t }}</h3>
@ -28,6 +38,7 @@
</div>
{% endif %}
{% if config.plugins.taxonomylist.enabled %}
<!-- Taxonomy list -->
<div>
<header>
<h3>{{ 'FUTURE.SIDEBAR.TAGS.HEADLINE'|t }}</h3>
@ -35,7 +46,19 @@
{% include 'partials/taxonomylist.html.twig' with {'base_url':new_base_url, 'taxonomy':'tag'} %}
</div>
{% endif %}
{% if config.plugins.feed.enabled %}
<!-- Syndicate -->
<div class="sidebar-content syndicate">
<h4>{{ 'FUTURE.SIDEBAR.SYNDICATE.HEADLINE'|t }}</h4>
<ul class="actions">
<li><a href="{{ feed_url }}.atom"><i class="fa fa-rss-square"></i> Atom 1.0</a></li>
<li><a href="{{ feed_url }}.rss"><i class="fa fa-rss-square"></i> RSS</a></li>
{% if config.plugins.feed.enable_json_feed %}<li><a href="{{ feed_url }}.json"><i class="fa fa-rss-square"></i> JSON</a></li>{% endif %}
</ul>
</div>
{% endif %}
{% if config.plugins.login.enabled %}
<!-- Login button -->
<div>
<ul class="actions stacked">
{% if not grav.user.authenticated %}