Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/Libraries/OsuWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ public static function getUpdatedFiles($old, $new)
return $diff['files'];
}

public static function fetchLastCommitDate(string $path): ?string
{
try {
$commits = GitHub::repo()
->commits()
->all(static::user(), static::repository(), [
'path' => $path,
'sha' => static::branch(),
'per_page' => 1,
]);

return $commits[0]['commit']['committer']['date'] ?? null;
} catch (GithubException $e) {
return null;
}
}

public static function fetchCommitDate(string $hash): ?string
{
try {
$commit = GitHub::repo()
->commits()
->show(static::user(), static::repository(), $hash);

return $commit['commit']['committer']['date'] ?? null;
} catch (GithubException $e) {
return null;
}
}

public static function isImage($path)
{
return preg_match('/\.(?:jpe?g|gif|png)$/i', $path) === 1;
Expand Down
29 changes: 27 additions & 2 deletions app/Models/Wiki/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function esIndexDocument(array $options = [])
public function esFetch()
{
$response = (new BasicSearch(static::esIndexName(), 'wiki_page_lookup'))
->source(['markdown', 'page', 'page_text', 'indexed_at', 'version'])
->source(['markdown', 'page', 'page_text', 'indexed_at', 'outdated_since_date', 'updated_at', 'version'])
->query([
'term' => [
'_id' => $this->pagePath(),
Expand Down Expand Up @@ -304,6 +304,13 @@ public function isOutdatedTranslation(): bool
&& ($this->page['header']['outdated_translation'] ?? false);
}

public function outdatedSinceDate(): ?Carbon
{
$date = $this->source['outdated_since_date'] ?? null;

return $date !== null ? Carbon::parse($date) : null;
}

public function isStub(): bool
{
return $this->page['header']['stub'] ?? false;
Expand Down Expand Up @@ -395,6 +402,8 @@ public function sync($force = false, $indexName = null)
return $this;
}

$lastCommitDate = OsuWiki::fetchLastCommitDate('wiki/'.$this->pagePath());

$source = [
'locale' => $this->locale,
'page' => null,
Expand All @@ -404,11 +413,20 @@ public function sync($force = false, $indexName = null)
'tags' => [],
'title' => null,
'indexed_at' => json_time(now()),
'outdated_since_date' => null,
'updated_at' => $lastCommitDate,
'version' => static::VERSION,
];

if (isset($content)) {
$layout = OsuMarkdown::parseYamlHeader($content)['header']['layout'] ?? null;
$parsedHeader = OsuMarkdown::parseYamlHeader($content)['header'];

$outdatedSinceHash = presence($parsedHeader['outdated_since'] ?? null);
if ($outdatedSinceHash !== null) {
$source['outdated_since_date'] = OsuWiki::fetchCommitDate($outdatedSinceHash);
}

$layout = $parsedHeader['layout'] ?? null;
$layout = $this->layout($layout);
$rendererClass = static::RENDERERS[$layout];
$contentRenderer = new $rendererClass($this, $content);
Expand Down Expand Up @@ -457,6 +475,13 @@ public function title($withSubtitle = false)
return $title;
}

public function updatedAt(): ?Carbon
{
$date = $this->source['updated_at'] ?? null;

return $date !== null ? Carbon::parse($date) : null;
}

private function log($action)
{
$message = "wiki ({$action}): {$this->pagePath()}";
Expand Down
2 changes: 2 additions & 0 deletions app/Transformers/WikiPageTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public function transform(Page $page)
'layout' => $page->layout(),
'locale' => $page->locale,
'markdown' => $page->getMarkdown(),
'outdated_since_date' => json_time($page->outdatedSinceDate()),
'path' => $page->path,
'subtitle' => $page->subtitle(),
'tags' => $page->tags(),
'title' => $page->title(),
'updated_at' => json_time($page->updatedAt()),
];
}
}
6 changes: 6 additions & 0 deletions config/schemas/wiki_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"indexed_at": {
"type": "date"
},
"outdated_since_date": {
"type": "date"
},
"updated_at": {
"type": "date"
},
"layout": {
"type": "keyword"
},
Expand Down
9 changes: 9 additions & 0 deletions resources/css/bem/wiki-page.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
}
}

&__footer {
margin-top: 30px;
padding-top: 10px;
border-top: 1px solid hsl(var(--hsl-b3));
font-size: @font-size--small;
color: hsl(var(--hsl-f1));
opacity: 0.8;
}

&__toc {
background-color: @osu-colour-b4;
border-radius: @border-radius-large;
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'search' => 'Search existing pages for :link.',
'stub' => 'This article is incomplete and waiting on someone to expand it.',
'toc' => 'Contents',
'updated_at' => 'This page was last edited on :date.',

'edit' => [
'link' => 'Show on GitHub',
Expand All @@ -23,6 +24,8 @@
'translation' => [
'legal' => 'This translation is provided for convenience only. The original :default shall be the sole legally binding version of this text.',
'outdated' => 'This page contains an outdated translation of the original content. Please check the :default for the most accurate information (and consider updating the translation if you are able to help out)!',
'updated_at' => 'This translation was last updated on :date.',
'updated_at_outdated' => 'This translation was last updated on :date, and was outdated since :outdated_since.',

'default' => 'English version',
],
Expand Down
14 changes: 14 additions & 0 deletions resources/views/wiki/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ class="sidebar__mobile-toggle js-mobile-toggle"

@if ($page->get() !== null)
{!! $page->get()['output'] !!}

@if ($page->updatedAt() !== null)
<div class="wiki-page__footer">
@if ($page->isTranslation())
@if ($page->isOutdatedTranslation() && $page->outdatedSinceDate() !== null)
{{ osu_trans('wiki.show.translation.updated_at_outdated', ['date' => i18n_date($page->updatedAt()), 'outdated_since' => i18n_date($page->outdatedSinceDate())]) }}
@else
{{ osu_trans('wiki.show.translation.updated_at', ['date' => i18n_date($page->updatedAt())]) }}
@endif
@else
{{ osu_trans('wiki.show.updated_at', ['date' => i18n_date($page->updatedAt())]) }}
@endif
</div>
@endif
@else
<div class="wiki-content">
<p>
Expand Down