Commit 9880f278 authored by Emma's avatar Emma 🏳🌈

use a macro for all relative timestamps

parent ae2f77f3
Pipeline #59662051 passed with stages
in 8 minutes and 54 seconds
......@@ -5,7 +5,7 @@ import { distanceInWords, distanceInWordsToNow, isBefore } from 'date-fns';
import Translator from 'bazinga-translator';
function makeTimesRelative(locale) {
$('.relative-time[datetime]').each(function () {
$('.js-relative-time[datetime]').each(function () {
const isoTime = $(this).attr('datetime');
$(this).text(distanceInWordsToNow(isoTime, {
......@@ -14,7 +14,7 @@ function makeTimesRelative(locale) {
}));
});
$('.relative-time-diff[datetime][data-compare-to]').each(function () {
$('.js-relative-time-diff[datetime][data-compare-to]').each(function () {
const timeA = $(this).attr('datetime');
const timeB = $(this).data('compare-to');
......
{%- block comment -%}
{%- from '_macros/time.html.twig' import relative_time, relative_time_diff -%}
{%- from 'vote/_macros.html.twig' import vote -%}
<article class="comment
comment--{{ level > 1 ? 'nested' : 'top-level' }}
......@@ -16,14 +17,13 @@
<span class="fg-muted text-sm">
{{ 'comments.info'|trans({
'%user%': block('comment_info_user'),
'%timestamp%': block('comment_info_timestamp'),
'%timestamp%': relative_time(comment.timestamp, { natural: true }),
})|raw }}
{% if comment.editedAt %}
<span class="comment__edited-at {{ comment.moderated ?
'comment__moderated' }} fg-muted text-sm">
<span class="comment__edited-at {{ comment.moderated ? 'comment__moderated' }} fg-muted text-sm">
{{ (comment.moderated ? 'comments.moderator_info' : 'comments.edit_info')|trans({
'%edited_at%': block('comment_info_edited_at')
'%edited_at%': relative_time_diff(comment.editedAt, comment.timestamp, { natural: true }),
})|raw }}
</span>
{% endif %}
......@@ -117,25 +117,6 @@
{{ user_flag(comment.userFlag) }}
{%- endblock comment_info_user -%}
{%- block comment_info_timestamp -%}
{%- set date = comment.timestamp|localizeddate('long', 'short') -%}
<time datetime="{{ comment.timestamp|date('c') }}"
title="{{ date }}"
class="comment__timestamp relative-time">
{{- 'comments.info_at_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{%- endblock comment_info_timestamp -%}
{%- block comment_info_edited_at -%}
{%- set date = comment.editedAt|localizeddate('long', 'short') -%}
<time datetime="{{ comment.editedAt|date('c') }}"
title="{{ date }}"
class="comment__edit-timestamp relative-time-diff"
data-compare-to="{{ comment.timestamp|date('c') }}">
{{- 'comments.info_at_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{%- endblock comment_info_edited_at -%}
{% block comment_nav %}
{{ block('comment_nav_reply') }}
{{ block('comment_nav_permalink') }}
......
{%- block submission -%}
{%- from '_macros/icon.html.twig' import icon -%}
{%- from '_macros/time.html.twig' import relative_time, relative_time_diff -%}
{%- from 'vote/_macros.html.twig' import vote -%}
{%- set open_external = submission.url is not empty and open_external_links_in_new_tab -%}
<article class="{{ block('submission_classes') }}">
......@@ -54,23 +55,19 @@
<p class="submission__info">
<span class="text-sm fg-muted">
{%- if show_forum_name -%}
{{ 'submissions.info_with_forum_name'|trans({
'%submitter%': block('submission_info_submitter'),
'%timestamp%': block('submission_info_timestamp'),
'%forum%': block('submission_info_forum_name'),
})|raw }}
{%- else -%}
{{ 'submissions.info_without_forum_name'|trans({
'%submitter%': block('submission_info_submitter'),
'%timestamp%': block('submission_info_timestamp'),
})|raw }}
{%- endif -%}
{{ (show_forum_name ? 'submissions.info_with_forum_name' : 'submissions.info_without_forum_name')|trans({
'%submitter%': block('submission_info_submitter'),
'%timestamp%': relative_time(submission.timestamp, {
natural: true,
extra_classes: 'submission__timestamp',
}),
'%forum%': block('submission_info_forum_name'),
})|raw }}
{% if submission.editedAt %}
<span class="submission__info-edited-at {{ submission.moderated ? 'submission__info-moderated' }}">
<span class="submission__info-edited-at {{ submission.moderated ? 'submission__info-moderated' }}">
{{ (submission.moderated ? 'submissions.moderator_info' : 'submissions.edit_info')|trans({
'%edited_at%': block('submission_info_edited_at')
'%edited_at%': relative_time_diff(submission.editedAt, submission.timestamp, { natural: true })
})|raw }}
</span>
{% endif %}
......@@ -132,15 +129,6 @@
{{ user_flag(submission.userFlag) }}
{% endblock submission_info_submitter %}
{% block submission_info_timestamp %}
{% set date = submission.timestamp|localizeddate('long', 'short') %}
{% filter spaceless %}
<time datetime="{{ submission.timestamp|date('c') }}" title="{{ date }}" class="submission__timestamp relative-time">
{{- 'submissions.info_at_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{% endfilter %}
{% endblock submission_info_timestamp %}
{% block submission_info_forum_name %}
{% filter spaceless %}
<a href="{{ path('forum', {forum_name: submission.forum.name}) }}" class="submission__forum fg-inherit">
......@@ -149,13 +137,6 @@
{% endfilter %}
{% endblock submission_info_forum_name %}
{%- block submission_info_edited_at -%}
{%- set date = submission.editedAt|localizeddate('long', 'short') -%}
<time datetime="{{ submission.editedAt|date('c') }}" title="{{ date }}" class="relative-time-diff" data-compare-to="{{ submission.timestamp|date('c') }}">
{{- 'submissions.info_at_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{%- endblock submission_info_edited_at -%}
{% block submission_nav %}
{{ block('submission_nav_comments') }}
{{ block('submission_nav_moderation') }}
......
{% macro relative_time(datetime, options={}) -%}
{%- set options = {
date_format: 'long',
time_format: 'short',
natural: false,
extra_classes: '',
}|merge(options) -%}
{%- set timestamp = datetime|localizeddate(options.date_format, options.time_format) -%}
{%- set tip = datetime|localizeddate('long', 'long') -%}
{%- set classes = ('js-relative-time '~options.extra_classes)|trim -%}
<time datetime="{{ datetime|date('c') }}" class="{{ classes }}" title="{{ tip }}">
{%- if options.natural -%}
{{- 'time.on_timestamp'|trans({'%timestamp%': timestamp}) -}}
{%- else -%}
{{- timestamp -}}
{%- endif -%}
</time>
{%- endmacro relative_time %}
{% macro relative_time_diff(datetime, compare_to, options={}) -%}
{%- set options = {
date_format: 'long',
time_format: 'short',
natural: false,
extra_classes: '',
}|merge(options) -%}
{%- set timestamp = datetime|localizeddate(options.date_format, options.time_format) -%}
{%- set tip = datetime|localizeddate('long', 'long') -%}
{%- set classes = ('js-relative-time-diff '~options.extra_classes)|trim -%}
<time datetime="{{ datetime|date('c') }}" data-compare-to="{{ compare_to|date('c') }}" class="{{ classes }}" title="{{ tip }}">
{%- if options.natural -%}
{{- 'time.on_timestamp'|trans({'%timestamp%': timestamp}) -}}
{%- else -%}
{{- timestamp -}}
{%- endif -%}
</time>
{%- endmacro relative_time_diff %}
......@@ -31,20 +31,15 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
<td class="table__shrink"><input type="checkbox" name="ban[]" value="{{ item.id }}" id="ban_{{ item.id }}"></td>
<td class="table__shrink"><label for="ban_{{ item.id }}">{{ item.ip }}</label></td>
<td class="table__shrink">
<time datetime="{{ item.timestamp|date('c') }}" class="relative-time">
{{- item.timestamp|localizeddate('long', 'short') -}}
</time>
</td>
<td class="table__shrink">{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}</td>
<td class="table__shrink">
{% if item.expiryDate %}
<time datetime="{{ item.expiryDate|date('c') }}" class="relative-time">
{{- item.expiryDate|localizeddate('long', 'short') -}}
</time>
{{ relative_time(item.expiryDate, { date_format: 'short', time_format: 'short' }) }}
{% else %}
<small>{{ 'ban_list.expires_never'|trans }}</small>
<small class="fg-muted text-sm">{{ 'ban_list.expires_never'|trans }}</small>
{% endif %}
</td>
<td class="table__shrink">
......
......@@ -24,24 +24,16 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
<td class="table__shrink">{{ user_link(item.user) }}</td>
<td class="table__shrink">{{ user_link(item.bannedBy) }}</td>
<td class="table__shrink">
{% with { date: item.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ item.timestamp|date('c') }}" title="{{ date }}" class="relative-time">
{{- date -}}
</time>
{% endwith %}
</td>
<td class="table__shrink">{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}</td>
<td class="table__shrink">
{% if item.expiresAt %}
{% set date = item.expiresAt|localizeddate('long', 'short') %}
<time datetime="{{ item.expiresAt|date('c') }}" title="{{ date }}" class="relative-time">
{{- date -}}
</time>
{{ relative_time(item.expiresAt, { date_format: 'short', time_format: 'short' }) }}
{% else %}
{{ 'label.never'|trans }}
<small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
{% endif %}
</td>
<td>{{ item.reason }}</td>
......
......@@ -79,13 +79,13 @@
{% macro _log_ban(entry) %}
{% from 'user/_macros.html.twig' import user_link %}
{% from _self import _log_diff_timestamp as diff_timestamp %}
{% from '_macros/time.html.twig' import relative_time_diff %}
{% if entry.ban.ban %}
{% if entry.ban.expired %}<del>{% endif %}
{{ 'log.ban'|trans({
'%user%': user_link(entry.user, {flag: entry.wasAdmin ? 'admin' : 'moderator'}),
'%banned%': user_link(entry.ban.user),
'%expires%': entry.ban.expiryTime ? diff_timestamp(entry.ban.expiryTime, entry.ban.timestamp) : 'label.never'|trans,
'%expires%': entry.ban.expiryTime ? relative_time_diff(entry.ban.expiryTime, entry.ban.timestamp) : 'label.never'|trans,
'%reason%': entry.ban.reason|e,
})|raw }}
{% if entry.ban.expired %}</del>{% endif %}
......@@ -97,14 +97,3 @@
})|raw }}
{% endif %}
{% endmacro %}
{%- macro _log_diff_timestamp(datetime, compareTo) -%}
{%- with {date: datetime|localizeddate('long', 'short')} -%}
<time datetime="{{ datetime|date('c') }}"
class="relative-time-diff"
data-compare-to="{{ compareTo|date('c') }}"
title="{{ date }}">
{{- date -}}
</time>
{%- endwith -%}
{%- endmacro -%}
......@@ -22,24 +22,17 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
<td class="table__shrink">{{ (item.ban ? 'label.ban' : 'label.unban')|trans }}</td>
<td>{{ item.reason }}</td>
<td class="table__shrink">
{% with {date: item.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ item.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
</td>
<td class="table__shrink">
{% if item.expiryTime %}
{% with {date: item.expiryTime|localizeddate('long', 'short')} %}
<time datetime="{{ item.expiryTime|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.expiryTime, { date_format: 'short' }) }}
{% else %}
{{ 'label.never'|trans }}
<small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
{% endif %}
</td>
{% endblock row %}
......
......@@ -22,28 +22,19 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
<td class="table__shrink">
{{ user_link(item.user) }}
</td>
<td class="table__shrink">{{ user_link(item.user) }}</td>
<td>{{ item.reason }}</td>
<td class="table__shrink">
{% with {date: item.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ item.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
</td>
<td class="table__shrink">
{% if item.expiryTime %}
{% with {date: item.expiryTime|localizeddate('long', 'short')} %}
<time datetime="{{ item.expiryTime|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.expiryTime, { date_format: 'short' }) }}
{% else %}
{{ 'label.never'|trans }}
<small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
{% endif %}
</td>
{% if is_granted('moderator', forum) %}
......
......@@ -7,6 +7,7 @@
{% block title 'title.global_moderation_log'|trans %}
{% block body %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'forum/_macros.html.twig' import log_line %}
<h1 class="page-heading">{{ block('title') }}</h1>
......@@ -19,11 +20,7 @@
&mdash;
{{ log_line(entry) }}
&mdash;
{% with {date: entry.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ entry.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(entry.timestamp) }}
</p>
</li>
{% endfor %}
......
......@@ -10,6 +10,7 @@
{% block title block('html_title')|striptags %}
{% block body %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'forum/_macros.html.twig' import log_line %}
<h1 class="page-heading">{{ block('html_title') }}</h1>
......@@ -20,11 +21,7 @@
<p>
{{ log_line(entry) }}
&mdash;
{% with {date: entry.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ entry.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(entry.timestamp) }}
</p>
</li>
{% endfor %}
......
......@@ -19,17 +19,17 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
<td><a href="{{ path('user', {username: item.user.username}) }}">{{ item.user.username }}</a></td>
<td class="table__shrink">
<time datetime="{{ item.timestamp|date('c') }}" title="{{ item.timestamp|localizeddate('long', 'short') }}" class="relative-time">
{{ item.timestamp|localizeddate('long', 'short') }}
</time>
{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
</td>
<td class="table__shrink">
{% if item.user.lastSeen is not null %}
<time datetime="{{ item.user.lastSeen|date('c') }}" title="{{ item.user.lastSeen|localizeddate('long', 'short') }}" class="relative-time">
{{ item.user.lastSeen|localizeddate('long', 'short') }}
</time>
{% if item.user.lastSeen %}
{{ relative_time(item.user.lastSeen, { date_format: 'short' }) }}
{% else %}
<small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
{% endif %}
</td>
<td class="table__shrink">
......@@ -43,4 +43,3 @@
{% endblock row %}
{% endembed %}
{% endblock body %}
......@@ -3,7 +3,8 @@
{% endmacro message %}
{% block message %}
{%- from _self import message_date, message_receivers -%}
{%- from _self import message_receivers -%}
{%- from '_macros/time.html.twig' import relative_time -%}
{%- from 'user/_macros.html.twig' import user_link -%}
<article class="message" id="message_{{ message.id }}">
<h1 class="message__head unheaderize">
......@@ -13,7 +14,7 @@
'%sender%': '<strong>%s</strong>'|format(user_link(message.sender, {
class: 'fg-inherit',
})),
'%timestamp%': message_date(message)
'%timestamp%': relative_time(message.timestamp, { natural: true })
})|raw }}
</span>
</h1>
......@@ -31,14 +32,6 @@
</article>
{% endblock message %}
{% macro message_date(message) %}
{% with { date: message.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ message.timestamp|date('c') }}" title="{{ date }}" class="relative-time">
{{- 'time.on_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{% endwith %}
{% endmacro message_date %}
{% macro message_receivers(message) %}
{%- from 'user/_macros.html.twig' import user_link -%}
{%- for receiver in message.thread.participants if receiver is not same as(message.sender) -%}
......
......@@ -21,24 +21,22 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
{% from _self import _time %}
<td><strong><a href="{{ path('message_thread', {id: item.id}) }}">{{ item.title }}</a></strong></td>
<td class="table__shrink text-align-right">{{ _time(item.messages|last.timestamp) }}</td>
<td class="table__shrink text-align-right">{{ (item.messages|length - 1)|localizednumber }}</td>
<td class="table__shrink text-align-right">
{{ relative_time(item.messages|last.timestamp, { date_format: 'short' }) }}
</td>
<td class="table__shrink text-align-right">
{{ (item.messages|length - 1)|localizednumber }}
</td>
<td class="table__shrink">
{%- for participant in item.participants if participant is not same as(app.user) -%}
{{- loop.index != 1 ? ', ' -}}
{{- user_link(participant) -}}
{%- endfor -%}
</td>
{% macro _time(datetime) %}
{% with {date: datetime|localizeddate('long', 'short')} %}
<time class="relative-time" datetime="{{ datetime|date('c') }}" title="{{ date }}">{{ date }}</time>
{% endwith %}
{% endmacro _time %}
{% endblock row %}
{% block flash_message 'flash.no_messages'|trans %}
......
{% extends 'base.html.twig' %}
{% from _self import timestamp %}
{% block site_nav_active app.user is same as(user) ? 'user' %}
{% block user_toolbox_active app.request.attributes.get('_route') %}
{% block sidebar %}
{% from '_macros/time.html.twig' import relative_time %}
<section class="sidebar__section sidebar-card">
<h1 class="sidebar__title no-margin break-text">
<a href="{{ path('user', {username: user.username}) }}" class="user-bio__user-link">{{ user.username }}</a>
......@@ -14,7 +13,7 @@
<p>
<small class="fg-muted text-md">{{ 'user.registered'|trans({
'%timestamp%': timestamp(user.created)
'%timestamp%': relative_time(user.created, { time_format: 'none', natural: true })
})|raw }}
</small>
</p>
......@@ -105,10 +104,3 @@
</section>
{% endif %}
{% endblock %}
{%- macro timestamp(timestamp) -%}
{%- set date = timestamp|localizeddate('long', 'short') -%}
<time datetime="{{ timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- 'time.on_timestamp'|trans({'%timestamp%': date}) -}}
</time>
{%- endmacro -%}
......@@ -19,16 +19,13 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
<td class="table__shrink">{{ user_link(item.blocked) }}</td>
<td class="table__shrink">
{% with {date: item.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ item.timestamp|date('c') }}" title="{{ date }}" class="relative-time">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
</td>
<td>{{ item.comment }}</td>
......
......@@ -26,25 +26,19 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
<td class="table__shrink"><a href="{{ path('forum', {forum_name: item.forum.name}) }}">/f/{{ item.forum.name }}</a></td>
<td class="table__shrink">{{ user_link(item.bannedBy) }}</td>
<td class="table__shrink">
{% with { date: item.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ item.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
</td>
<td class="table__shrink">
{% if item.expiryTime %}
{% set date = item.expiryTime|localizeddate('long', 'short') %}
<time datetime="{{ item.expiryTime|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{{ relative_time(item.expiryTime, { date_format: 'short' }) }}
{% else %}
<small>{{ 'label.never'|trans }}</small>
<small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
{% endif %}
</td>
<td>{{ item.reason }}</td>
......
......@@ -37,15 +37,12 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
{% from 'user/_macros.html.twig' import user_link %}
<td class="table__shrink">{{ item.id }}</td>
<td>{{ user_link(item) }}</td>
<td>
{% with { date: item.created|localizeddate('long', 'short')} %}
<time datetime="{{ item.created|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.created, { date_format: 'short', time_format: 'none' }) }}
</td>
<td>{{ item.admin ? ('label.admin'|trans) : item.trusted ? ('label.trusted'|trans) : '-' }}</td>
<td>
......
......@@ -10,7 +10,7 @@
}) %}
{% block body %}
{% from _self import time_ago, time_since %}
{% from '_macros/time.html.twig' import relative_time, relative_time_diff %}
<h1 class="page-heading">
{{ 'title.wiki_diff'|trans({
'%from%': '<a href="%s">%s</a>'|format(
......@@ -28,21 +28,10 @@
<thead>
<tr>
<th class="diff-table__header diff-table__header--from" colspan="2">
{% with { date: from.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ from.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(from.timestamp) }}
</th>
<th class="diff-table__header diff-table__header--to" colspan="2">
{% with { date: to.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ to.timestamp|date('c') }}"
class="relative-time-diff"
data-compare-to="{{ from.timestamp|date('c') }}"
title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time_diff(to.timestamp, from.timestamp) }}
</th>
</tr>
</thead>
......
......@@ -21,6 +21,8 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
<td class="table__shrink">
<span class="unstylable-widget">
<input class="form-control" type="radio" name="from" value="{{ item.id }}" {{ loop.index == 2 ? 'checked' }}>
......@@ -37,11 +39,7 @@
<a href="{{ path('wiki_revision', {id: item.id}) }}">{{ item.id.hex|slice(0, 8) }}</a>
</td>
<td class="table__shrink">
{% with {date: item.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ item.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
{{ relative_time(item.timestamp, { date_format: 'short' }) }}
</td>
<td><a href="{{ path('user', {username: item.user.username}) }}">{{ item.user.username }}</a></td>
{% endblock row %}
......
{% extends 'wiki/base.html.twig' %}
{% from '_macros/icon.html.twig' import icon %}
{% block title %}
{{ page.latestRevision.title }}
{% endblock %}
{% block title page.latestRevision.title %}
{% block head %}
<link rel="canonical" href="{{ url('wiki', {path: page.path}) }}">
......@@ -24,6 +22,8 @@
{% endblock %}
{% block sidebar %}
{% from '_macros/time.html.twig' import relative_time %}
<section class="sidebar__section sidebar-card">
<h1 class="sidebar__title">{{ page.path }}</h1>
<p>
......@@ -32,7 +32,7 @@
path('user', {username: page.latestRevision.user.username})|escape,
page.latestRevision.user.username|escape
),
'%timestamp%': block('_last_edited_time'),
'%timestamp%': relative_time(page.latestRevision.timestamp, { natural: true }),
})|raw -}}
</p>
......@@ -92,11 +92,3 @@
{{ parent() }}
{% endblock %}
{% block _last_edited_time %}
{% with {time: page.latestRevision.timestamp|localizeddate('long', 'short')} %}
<time datetime="{{ page.latestRevision.timestamp|date('c') }}" title="{{ time }}" class="relative-time">
{{ 'time.on_timestamp'|trans({'%timestamp%': time}) }}
</time>
{% endwith %}
{% endblock %}
......@@ -20,15 +20,13 @@
{% endblock header %}
{% block row %}
{% from '_macros/time.html.twig' import relative_time %}
<td class="table__shrink"><a href="{{ path('wiki_revision', {id: item.id}) }}">{{ item.id.hex|slice(0, 8) }}</td>
<td><a href="{{ path('wiki', {path: item.page.path}) }}">{{ item.page.path }}</a></td>
<td class="table__shrink"><a href="{{ path('user', {username: item.user.username}) }}">{{ item.user.username }}</a></td>
<td class="table__shrink">
{% with { date: item.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ item.timestamp|date('c') }}" title="{{ date }}" class="relative-time">
{{- date -}}