Improved code for datestamp

This commit is contained in:
pmoreno.rodriguez 2023-09-29 13:57:38 +02:00
parent 5799c62ac3
commit 9fc9ccf788
8 changed files with 36 additions and 30 deletions

View file

@ -1,5 +1,3 @@
{% set lang = grav.language.getActive ?: grav.config.site.default_lang %}
{% extends 'partials/base.html.twig' %}
{% block content %}
<article class="post">
@ -8,13 +6,7 @@
<h2>{{ form.message }}</h2>
</div>
<div class="meta">
{% if config.plugins["translate-date"].enabled %}
<time class="published" datetime="{{ form.date|td(null, "Y-m-d") }}">{{ form.date|td(null, "M j, Y") }}</time>
{% elseif config.plugins["twig-extensions"].enabled %}
<time class="published" datetime="{{ form.date|localizeddate('medium', 'none', lang) }}">{{ form.date|localizeddate('medium', 'none', lang) }}</time>
{% else %}
<time class="published" datetime="{{ form.date|date("Y-m-d") }}">{{ form.date|date("M j, Y") }}</time>
{% endif %}
<time class="published" datetime="{{ datestamp }}">{{ datestamp }}</time>
</div>
</header>
<p>{{'FUTURE.FORM_SUMMARY'|t}}</p>

View file

@ -15,7 +15,7 @@
</div>
{% endif %}
{% include 'partials/blog_item.html.twig' with {'listing': false, 'truncate':false} %}
{% include 'partials/blog_item.html.twig' with {'listing': false, 'truncate':false, datestamp} %}
{% if show_sidebar == false %}
<section id="footer" class="align-center">

View file

@ -3,8 +3,9 @@
{% set compress = theme_var('production-mode') ? '.min.css' : '.css' %}
{% set favicon = theme_config.favicon ? theme_config.favicon|first : { type:'image/png', path: url('theme://images/favicon.png') } %}
{# Set site language #}
{# Set site language and datestamp for pages #}
{% set lang = grav.language.getActive ?: grav.config.site.default_lang %}
{% set datestamp = include('partials/page-bits/date.html.twig') %}
{# Define if sidebar is shown in the page #}
{% set show_sidebar = header_var('show_sidebar')|defined(false) %}

View file

@ -39,14 +39,9 @@
{% if config.plugins.readingtime.enabled %}
<span class="reading-time"><i class="fas fa-book-reader"></i> {{ page.content|readingtime}}</span>
{% endif %}
{# Support for translate and twig extensions plugins #}
{% if config.plugins["translate-date"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|td(null, "Y-m-d") }}">{{ page.date|td(null, "M j, Y") }}</time>
{% elseif config.plugins["twig-extensions"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|localizeddate('medium', 'none', lang) }}">{{ page.date|localizeddate('medium', 'none', lang) }}</time>
{% else %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|date("Y-m-d") }}">{{ page.date|date("M j, Y") }}</time>
{% endif %}
<time class="published" itemprop="datePublished" datetime="{{ datestamp }}">{{ datestamp }}</time>
{% if author %}
<span itemprop="author" itemscope itemtype="http://schema.org/Person"/>
<a {% if page.taxonomy.author %}href="{{ blog.url }}/author{{ config.system.param_sep }}{{ author }}" itemprop="url" {% endif %}class="author" aria-label="{{ author }}" rel="nofollow">

View file

@ -0,0 +1,21 @@
{# Support for Twig-Extensions and Translate-Date plugins #}
{# Set page datestamp in folowing order with support for translations #}
{# FIRST: Page publication date #}
{# SECOND: Page date #}
{# LAST: Page modification date #}
{# SET DEFAULT GRAV LANGUAGE #}
{% set lang = grav.language.getActive ?: grav.config.site.default_lang %}
{% set default_format = system.pages.dateformat.default %}
{% set short_format = system.pages.dateformat.short %}
{% if config.plugins["translate-date"].enabled %}
{% set datestamp = (page.header.publish_date) ? (page.header.publish_date|td(lang,default_format)) : (page.date ? page.date|td(lang,default_format) : page.modified|td(lang,default_format)) %}
{% elseif config.plugins["twig-extensions"].enabled %}
{% set datestamp = (page.header.publish_date) ? (page.header.publish_date|localizeddate('medium', 'none', lang)) : (page.date ? page.date|localizeddate('medium', 'none', lang) : page.modified|localizeddate('medium', 'none', lang)) %}
{% else %}
{% set datestamp = (page.header.publish_date) ? (page.header.publish_date|date(short_format)) : (page.date ? page.date|date(short_format) : page.modified|date(short_format)) %}
{% endif %}
{{ datestamp }}

View file

@ -11,7 +11,7 @@
</header>
<div class="mini-posts">
{% for p in page.evaluate({'@taxonomy.category':miniposts_category}).order('header.order', 'asc').slice(0,miniposts_number) %}
{% set datestamp = include('partials/page-bits/date.html.twig', { 'page': p } ) %}
{% if p.header.metadata.author %}
{% set author = p.header.metadata.author %}
{% elseif p.header.author %}
@ -32,14 +32,10 @@
<header>
<h3>
<a href="{{ p.url }}" aria-label="{{ title }}">{{ title }}</a>
</h3>
{% if config.plugins["translate-date"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ p.date|td(null, "Y-m-d") }}">{{ p.date|td(null, "M j, Y") }}</time>
{% elseif config.plugins["twig-extensions"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ p.date|localizeddate('medium', 'none', lang) }}">{{ p.date|localizeddate('medium', 'none', lang) }}</time>
{% else %}
<time class="published" itemprop="datePublished" datetime="{{ p.date|date("Y-m-d") }}">{{ p.date|date("M j, Y") }}</time>
{% endif %}
</h3>
<time class="published" itemprop="datePublished" datetime="{{ datestamp }}">{{ datestamp }}</time>
{% if avatar %}
<a href="{{ p.url }}" class="author" title="{{ author }}"><img src="{{ avatar }}" alt="{{ author }}"/></a>
{% endif %}

View file

@ -13,7 +13,7 @@
<h3><a href="{{ page.url }}">{{ title }}</a></h3>
</div>
<div class="search-details">
<span class="search-date">{{ page.date|date(config.system.pages.dateformat.short) }}</span>
<span class="search-date">{{ datestamp }}</span>
</div>
{{ page.summary|striptags|truncate(300, true)|raw }}
</div>

View file

@ -31,7 +31,8 @@
</div>
</header>
{% for page in search_results %}
{% include 'partials/simplesearch_item.html.twig' with {'page':page} %}
{% set datestamp = include('partials/page-bits/date.html.twig') %}
{% include 'partials/simplesearch_item.html.twig' with {'page':page, datestamp} %}
{% endfor %}
</article>