Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply new resource layout (resolves #141) #190

Merged
merged 6 commits into from
Feb 20, 2020
Merged
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
12 changes: 8 additions & 4 deletions app/Controllers/Partials/Resource.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace App\Controllers\Partials;

use function App\maybe_swap_term;
use function App\natural_language_join;

trait Resource
{
Expand Down Expand Up @@ -54,16 +55,19 @@ public static function getWaybackMachineLinks()
return false;
}

public static function getPublicationDate()
public static function getPublicationDate($format = false)
{
global $post;

if ($post->post_type == 'lc_resource') {
if (!$format) {
$format = get_option('date_format');
}
$y = get_post_meta($post->ID, 'lc_resource_publication_year', true);
$m = get_post_meta($post->ID, 'lc_resource_publication_month', true);
$d = get_post_meta($post->ID, 'lc_resource_publication_day', true);
return date_i18n(
get_option('date_format'),
$format,
strtotime(implode('-', [$y, $m, $d]))
);
}
Expand Down Expand Up @@ -106,9 +110,9 @@ public static function getAuthors()
{
global $post;
if ($post->post_type == 'lc_resource') {
$authors = get_post_meta($post->ID, 'lc_resource_authors', true);
$authors = get_post_meta($post->ID, 'lc_resource_author', true);
if ($authors) {
return $authors;
return natural_language_join($authors);
}
}
return false;
Expand Down
27 changes: 27 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,30 @@ function maybe_swap_term($term, $lang = false)
}
return $term;
}


/**
* Join a string with a natural language conjunction at the end.
* Based on https://gist.github.com/angry-dan/e01b8712d6538510dd9c
*
* @param array $list
* @param string $conjunction
* @param bool $oxford
*
* @return string
*/
function natural_language_join(array $list, $conjunction = 'and', $oxford = true)
{
if (count($list) > 2) {
$last_item = array_pop($list);
if ($oxford) {
$final_separator = ", $conjunction ";
} else {
$final_separator = " $conjunction ";
}
return implode(', ', $list) . $final_separator . $last_item;
} elseif (count($list) === 2) {
return implode(" $conjunction ", $list);
}
return array_pop($list);
}
15 changes: 9 additions & 6 deletions resources/views/partials/content-lc_resource.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<span class="separator">.</span>
@endif
@if(Archive::getPublicationDate())
<span class="card__date"><span class="screen-reader-text">{{ __('date published', 'coop-library') }}: </span>2016</span>
<span class="card__date"><span class="screen-reader-text">{{ __('date published', 'coop-library') }}: </span>{{ Archive::getPublicationDate('Y') }}</span>
@endif
</div>
@endif
Expand All @@ -43,10 +43,13 @@
@endif
</div>
@endif
@if(Archive::isFavorited())
<div class="card__favorite">
@svg('favorite-filled', 'icon--favorite-filled', ['focusable' => 'false', 'aria-hidden' => 'true'])
{{ __('Favorited', 'coop-library') }}
<div class="card__meta">
<span class="card__added">{{ sprintf(__('Added %s', 'coop-library'), get_the_date()) }}</span>
@if(Archive::isFavorited())
<span class="card__favorite">
@svg('favorite-filled', 'icon--favorite-filled', ['focusable' => 'false', 'aria-hidden' => 'true'])
{{ __('Favorited', 'coop-library') }}
</span>
@endif
</div>
@endif
</article>
41 changes: 29 additions & 12 deletions resources/views/partials/content-single-lc_resource.blade.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<article @php post_class() @endphp>
<div class="page-header resource__header">
<p class="resource__format">
@svg(Single::getFormatIcon(), 'icon--' . Single::getFormatIcon(), ['focusable' => 'false', 'aria-hidden' => 'true']) <span class="screen-reader-text">{{ __('resource format', 'coop-library') }}: </span>{{ Single::getFormat() }}
</p>
<h1 class="resource__title">{!! get_the_title() !!}</h1>
@if(Single::getPublisher() || Single::getRegion())
<p class="resource__meta">
@if(Single::getPublisher())
<span class="resource__publisher byline vcard">{{ __('By', 'coop-library') }} {!! Single::getPublisher(true) !!}</span>
@endif
@if(Single::getRegion())
<span class="resource__locality">@svg('location', 'icon--location', ['focusable' => 'false', 'aria-hidden' => 'true']) {{ Archive::getRegion() }}</span>
@endif
</p>
@if(Single::getAuthors())
<div class="resource__meta resource__byline">@svg('author', 'icon--author', ['focusable' => 'false', 'aria-hidden' => 'true']) {{ sprintf(__('By %s', 'coop-library'), Single::getAuthors()) }}</div>
@endif
<div class="resource__meta">
<div class="resource__meta-group">
<span class="resource__format">@svg(Single::getFormatIcon(), 'icon--' . Single::getFormatIcon(), ['focusable' => 'false', 'aria-hidden' => 'true']) <span class="screen-reader-text">{{ __('resource format', 'coop-library') }}: </span>{{ Single::getFormat() }}</span>@if(Single::getPublisher())<span class="separator">.</span>
<span class="resource__publisher">{!! sprintf(__('Published by %s', 'coop-library'), Single::getPublisher()) !!}</span>
@endif
</div>
@if(Single::getRegion())
<div class="resource__meta-group">
<span class="resource__locality">@svg('location', 'icon--location', ['focusable' => 'false', 'aria-hidden' => 'true']) <span class="screen-reader-text">{{ __('location of relevance', 'coop-library') }}: </span>{{ Single::getRegion() }}</span>
</div>
@endif
@if($current_language !== Single::getLanguage() || Single::getPublicationDate())
<div class="resource__meta-group">
@svg('info', 'icon--info', ['focusable' => 'false', 'aria-hidden' => 'true'])
@if($current_language !== Single::getLanguage())
<span class="resource__language"><span class="screen-reader-text">{{ __('language', 'coop-library') }}: </span>{{ $languages[Single::getLanguage()] }}</span>
<span class="separator">.</span>
@endif
@if(Single::getPublicationDate())
<span class="resource__date"><span class="screen-reader-text">{{ __('date published', 'coop-library') }}: </span>{{ Single::getPublicationDate() }}</span>
@endif
</div>
@endif
</div>
</div>
<div class="resource__abstract">
<h2>{{ __('Summary', 'coop-library') }}</h2>
Expand Down Expand Up @@ -92,5 +106,8 @@
</div>
@endif
</div>
<div class="resource__meta">
<span class="date__added">{{ sprintf(__('Added %s', 'coop-library'), get_the_date()) }}</span>
</div>
@php comments_template('/partials/comments.blade.php') @endphp
</article>