feat: make displayed publication time as relative time using @github/time-elements

This commit is contained in:
Yassine Doghri 2021-08-09 15:56:59 +00:00
parent 0e14eb4d3f
commit 230e139e43
16 changed files with 47 additions and 71 deletions

View File

@ -514,3 +514,24 @@ if (! function_exists('audio_player')) {
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------
if (! function_exists('relative_time')) {
function relative_time(Time $time, string $class = ''): string
{
$translatedDate = lang('Common.mediumDate', [$time]);
$datetime = $time->toDateTimeString();
return <<<CODE_SAMPLE
<time-ago class="${class}" datetime="${datetime}">
<time
itemprop="published"
datetime="${datetime}"
title="${time}">${translatedDate}</time>
</time-ago>
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------

View File

@ -1,4 +1,5 @@
import "@github/markdown-toolbar-element";
import "@github/time-elements";
import ClientTimezone from "./modules/ClientTimezone";
import Clipboard from "./modules/Clipboard";
import DateTimePicker from "./modules/DateTimePicker";

View File

@ -1,3 +1,4 @@
import "@github/time-elements";
import Dropdown from "./modules/Dropdown";
import Time from "./modules/Time";
import Toggler from "./modules/Toggler";

View File

@ -42,12 +42,7 @@
<span class="text-sm text-gray-500 truncate">@<?= $podcast
->actor->username ?></span>
</p>
<time class="text-xs text-gray-500" itemprop="published" datetime="<?= $status->published_at->format(
DateTime::ATOM,
) ?>" title="<?= $status->published_at ?>"><?= lang(
'Common.mediumDate',
[$status->published_at],
) ?></time>
<?= relative_time($status->published_at, 'text-xs text-gray-500') ?>
</div>
</div>
<div class="px-4 mb-2">
@ -78,13 +73,7 @@
) ?>
</div>
<div class="text-xs text-gray-600">
<time itemprop="published" datetime="<?= $episode->published_at->format(
DateTime::ATOM,
) ?>" title="<?= $episode->published_at ?>">
<?= lang('Common.mediumDate', [
$episode->published_at,
]) ?>
</time>
<?= relative_time($episode->published_at) ?>
<span class="mx-1"></span>
<time datetime="PT<?= $episode->audio_file_duration ?>S">
<?= format_duration($episode->audio_file_duration) ?>

View File

@ -21,11 +21,7 @@
<span class="mx-1">-</span>
<?= $episode->title ?>
</h2>
<time class="text-xs whitespace-nowrap" itemprop="published" datetime="<?= $episode->published_at->format(DateTime::ATOM,) ?>" title="<?= $episode->published_at ?>">
<?= lang('Common.mediumDate', [
$episode->published_at,
]) ?>
</time>
<?= relative_time($episode->published_at, 'text-xs whitespace-nowrap') ?>
</a>
<div class="flex mt-auto gap-x-4">
<?= play_episode_button($episode->id, $episode->image->thumbnail_url, $episode->title, $podcast->title, $episode->audio_file_web_url, $episode->audio_file_mimetype, 'mt-auto') ?>

View File

@ -19,13 +19,7 @@
<span class="mx-1">-</span>
<?= $episode->title ?>
</div>
<time
class="text-xs"
itemprop="published"
datetime="<?= $episode->published_at->format(DateTime::ATOM) ?>"
title="<?= $episode->published_at ?>">
<?= lang('Common.mediumDate', [$episode->published_at]) ?>
</time>
<?= relative_time($episode->published_at, 'text-xs whitespace-nowrap') ?>
</a>
<?= play_episode_button($episode->id, $episode->image->thumbnail_url, $episode->title, $podcast->title, $episode->audio_file_web_url, $episode->audio_file_mimetype, 'mt-auto') ?>
</div>

View File

@ -25,11 +25,7 @@
</a>
<a href="<?= route_to('status', $podcast->handle, $status->id) ?>"
class="text-xs text-gray-500">
<time
itemprop="published"
datetime="<?= $status->published_at->format(DateTime::ATOM) ?>"
title="<?= $status->published_at ?>"
><?= lang('Common.mediumDate', [$status->published_at]) ?></time>
<?= relative_time($status->published_at) ?>
</a>
</div>
</header>

View File

@ -25,11 +25,7 @@
</a>
<a href="<?= route_to('status', $podcast->handle, $status->id) ?>"
class="text-xs text-gray-500">
<time
itemprop="published"
datetime="<?= $status->published_at->format(DateTime::ATOM) ?>"
title="<?= $status->published_at ?>"
><?= lang('Common.mediumDate', [$status->published_at]) ?></time>
<?= relative_time($status->published_at) ?>
</a>
</div>
</header>

View File

@ -11,12 +11,7 @@
->display_name ?><span class="ml-1 text-sm font-normal text-gray-600">@<?= $reply
->actor->username .
($reply->actor->is_local ? '' : '@' . $reply->actor->domain) ?></span></a>
<time
class="flex-shrink-0 ml-auto text-xs text-gray-600"
itemprop="published"
datetime="<?= $reply->published_at->format(DateTime::ATOM) ?>"
title="<?= $reply->published_at ?>"
><?= lang('Common.mediumDate', [$reply->published_at]) ?></time>
<?= relative_time($status->published_at, 'flex-shrink-0 ml-auto text-xs text-gray-600') ?>
</header>
<p class="mb-2 status-content"><?= $reply->message_html ?></p>
<?php if ($reply->has_preview_card): ?>

View File

@ -11,12 +11,7 @@
->display_name ?><span class="ml-1 text-sm font-normal text-gray-600">@<?= $reply
->actor->username .
($reply->actor->is_local ? '' : '@' . $reply->actor->domain) ?></span></a>
<time
class="flex-shrink-0 ml-auto text-xs text-gray-600"
itemprop="published"
datetime="<?= $reply->published_at->format(DateTime::ATOM) ?>"
title="<?= $reply->published_at ?>"
><?= lang('Common.mediumDate', [$reply->published_at]) ?></time>
<?= relative_time($status->published_at, 'flex-shrink-0 ml-auto text-xs text-gray-600') ?>
</header>
<p class="mb-2 status-content"><?= $reply->message_html ?></p>
<?php if ($reply->has_preview_card): ?>

View File

@ -18,11 +18,7 @@
</a>
<a href="<?= route_to('status', $podcast->handle, $status->id) ?>"
class="text-xs text-gray-500">
<time
itemprop="published"
datetime="<?= $status->published_at->format(DateTime::ATOM) ?>"
title="<?= $status->published_at ?>"
><?= lang('Common.mediumDate', [$status->published_at]) ?></time>
<?= relative_time($status->published_at) ?>
</a>
</div>
</header>

View File

@ -18,11 +18,7 @@
</a>
<a href="<?= route_to('status', $podcast->handle, $status->id) ?>"
class="text-xs text-gray-500">
<time
itemprop="published"
datetime="<?= $status->published_at->format(DateTime::ATOM) ?>"
title="<?= $status->published_at ?>"
><?= lang('Common.mediumDate', [$status->published_at]) ?></time>
<?= relative_time($status->published_at) ?>
</a>
</div>
</header>

View File

@ -59,13 +59,7 @@
'text-gray-700',
) ?>
<div class="mb-4 text-xs">
<time pubdate datetime="<?= $episode->published_at->format(
DateTime::ATOM,
) ?>" title="<?= $episode->published_at ?>">
<?= lang('Common.mediumDate', [
$episode->published_at,
]) ?>
</time>
<?= relative_time($episode->published_at) ?>
<span class="mx-1"></span>
<time datetime="PT<?= $episode->audio_file_duration ?>S">
<?= format_duration($episode->audio_file_duration) ?>

View File

@ -59,13 +59,7 @@
'text-gray-700',
) ?>
<div class="mb-4 text-xs">
<time pubdate datetime="<?= $episode->published_at->format(
DateTime::ATOM,
) ?>" title="<?= $episode->published_at ?>">
<?= lang('Common.mediumDate', [
$episode->published_at,
]) ?>
</time>
<?= relative_time($episode->published_at) ?>
<span class="mx-1"></span>
<time datetime="PT<?= $episode->audio_file_duration ?>S">
<?= format_duration($episode->audio_file_duration) ?>

11
package-lock.json generated
View File

@ -12,6 +12,7 @@
"@amcharts/amcharts4": "^4.10.20",
"@amcharts/amcharts4-geodata": "^4.1.21",
"@github/markdown-toolbar-element": "^1.5.1",
"@github/time-elements": "^3.1.2",
"@popperjs/core": "^2.9.2",
"@vime/core": "^5.0.33",
"choices.js": "^9.0.1",
@ -1039,6 +1040,11 @@
"resolved": "https://registry.npmjs.org/@github/markdown-toolbar-element/-/markdown-toolbar-element-1.5.3.tgz",
"integrity": "sha512-fNgAuHBWWzqxMvkTMM7ijqPryLmnPVOi4OWp8YyUC74YgtJCRvQyL7gl9SzNLMXmGQxiRVIYbUJxa61X1oRObw=="
},
"node_modules/@github/time-elements": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/@github/time-elements/-/time-elements-3.1.2.tgz",
"integrity": "sha512-YVtZVLBikP6I7na22kfB9PKIseISwX41MFJ7lPuNz1VVH2IR5cpRRU6F1X6kcchPChljuvMUR4OiwMWHOJQ8kQ=="
},
"node_modules/@humanwhocodes/config-array": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz",
@ -20246,6 +20252,11 @@
"resolved": "https://registry.npmjs.org/@github/markdown-toolbar-element/-/markdown-toolbar-element-1.5.3.tgz",
"integrity": "sha512-fNgAuHBWWzqxMvkTMM7ijqPryLmnPVOi4OWp8YyUC74YgtJCRvQyL7gl9SzNLMXmGQxiRVIYbUJxa61X1oRObw=="
},
"@github/time-elements": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/@github/time-elements/-/time-elements-3.1.2.tgz",
"integrity": "sha512-YVtZVLBikP6I7na22kfB9PKIseISwX41MFJ7lPuNz1VVH2IR5cpRRU6F1X6kcchPChljuvMUR4OiwMWHOJQ8kQ=="
},
"@humanwhocodes/config-array": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz",

View File

@ -30,6 +30,7 @@
"@amcharts/amcharts4-geodata": "^4.1.21",
"@amcharts/amcharts4": "^4.10.20",
"@github/markdown-toolbar-element": "^1.5.1",
"@github/time-elements": "^3.1.2",
"@popperjs/core": "^2.9.2",
"@vime/core": "^5.0.33",
"choices.js": "^9.0.1",