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: add homepage (resolves #117) #151

Merged
merged 9 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
20 changes: 19 additions & 1 deletion app/Controllers/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public static function sortUrl($order_by)
public static function title()
{
if (is_front_page()) {
return __('Platform Co-op Resource Library', 'coop-library');
return __(
'<span class="pc-ff--sans pc-fw--normal">Platform Co-op</span><br />Resource Library',
'coop-library'
);
}
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
Expand All @@ -110,4 +113,19 @@ public static function title()
}
return get_the_title();
}

public static function breadcrumb()
{
if (is_front_page()) {
return false;
}
return sprintf('<a href="%1$s">%2$s</a>', get_home_url(), __('Home', 'coop-library'));
}

public static function termListUrl($taxonomy)
{
$slug = str_replace('lc_', '', $taxonomy) . 's';
$page = get_page_by_path($slug);
return get_permalink($page->ID);
}
}
22 changes: 22 additions & 0 deletions app/Controllers/FrontPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,27 @@

class FrontPage extends Controller
{
public function mostViewed()
{
return new \WP_Query([
'post_type' => 'lc_resource',
'meta_key' => 'lc_resource_views',
'orderby' => ['meta_value_num', 'date'],
'posts_per_page' => 4,
'order' => 'desc',
'lang' => '',
]);
}

public function recentlyPublished()
{
return new \WP_Query([
'post_type' => 'lc_resource',
'meta_key' => 'lc_resource_publication_date',
'orderby' => ['meta_value', 'date'],
'posts_per_page' => 4,
'order' => 'desc',
'lang' => '',
]);
}
}
8 changes: 6 additions & 2 deletions app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@
if (! empty($_GET['order_by'])) {
switch ($_GET['order_by']) {
case 'published':
$query->set('meta_key', 'lc_resource_publication_year');
$query->set('orderby', ['meta_value_num', 'date']);
$query->set('meta_key', 'lc_resource_publication_date');
$query->set('orderby', ['meta_value', 'date']);
break;
case 'favorited':
$query->set('meta_key', 'lc_resource_favorites');
$query->set('orderby', ['meta_value_num', 'date']);
break;
case 'viewed':
$query->set('meta_key', 'lc_resource_views');
$query->set('orderby', ['meta_value_num', 'date']);
break;
case 'added':
default:
$query->set('orderby', 'date');
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.7",
"@commitlint/cli": "^8.3.4",
"@commitlint/config-conventional": "^8.3.4",
"@platform-coop-toolkit/pinecone": "^1.0.0-alpha.6",
"@platform-coop-toolkit/pinecone": "^1.0.0-alpha.7",
"@wordpress/babel-preset-default": "^4.8.0",
"@wordpress/browserslist-config": "^2.6.0",
"@wordpress/dependency-extraction-webpack-plugin": "^2.1.0",
Expand Down
7 changes: 7 additions & 0 deletions resources/assets/styles/common/_global.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.search-form label {
width: 100%;
}

.search-form [type="search"] {
max-width: 100%;
}
8 changes: 8 additions & 0 deletions resources/views/front-page.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@extends('layouts.app')

@section('content')
@while(have_posts()) @php the_post() @endphp
@include('partials.page-header')
@include('partials.content-front-page')
@endwhile
@endsection
46 changes: 46 additions & 0 deletions resources/views/partials/content-front-page.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="home__search">
@include('partials.search-form', ['modifier' => 'inverse', 'placeholder' => __('Search resource name, publisher, or topic…')])
{{-- TODO: Add saved searches --}}
</div>
<div class="home__browse">
<h2>{{ __('Browse by…', 'coop-library') }}</h2>
<ul class="link-list link-list--inverse">
@foreach([
'lc_topic' => __('Topics', 'coop-library'),
'lc_goal' => __('Goals', 'coop-library'),
'lc_sector' => __('Sectors', 'coop-library'),
'lc_format' => __('Formats', 'coop-library'),
] as $slug => $label)
<li class="link-list__item"><a href="{{ App::termListUrl($slug) }}">@svg(str_replace('lc_', '', $slug), 'icon--' . str_replace('lc_', '', $slug), ['focusable' => 'false', 'aria-hidden' => 'true']) {{ $label }}</a></li>
@endforeach
</ul>
<div class="wp-block-button wp-block-button--inverse"><a href="{{ get_post_type_archive_link('lc_resource') }}" class="wp-block-button__link">{{ __('Browse all resources', 'coop-library') }}</a></div>
</div>
<div class="home__feed">
greatislander marked this conversation as resolved.
Show resolved Hide resolved
<h2>{{ __('My feed', 'coop-library') }}</h2>
<hr class="is-style-thick has-grey-200-background-color">
<h3><a href="{{ get_post_type_archive_link('lc_resource') }}?order_by=viewed">{{ __('Most viewed', 'coop-library') }}</a></h3>
<div class="meta-card-wrapper">
<div class="card-wrapper">
@if($most_viewed->have_posts())
<ul class="cards">
@while ($most_viewed->have_posts()) @php $most_viewed->the_post() @endphp
@include('partials.content-'.get_post_type())
@endwhile
</ul>
@endif
</div>
{{-- TODO: Add info cards --}}
</div>
<hr class="is-style-thick has-grey-200-background-color">
<h3><a href="{{ get_post_type_archive_link('lc_resource') }}?order_by=published">{{ __('Recently published', 'coop-library') }}</a></h3>
<div class="card-wrapper">
@if($recently_published->have_posts())
<ul class="cards">
@while ($recently_published->have_posts()) @php $recently_published->the_post() @endphp
@include('partials.content-'.get_post_type())
@endwhile
</ul>
@endif
</div>
</div>
2 changes: 1 addition & 1 deletion resources/views/partials/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</button>
{!! wp_nav_menu([
'theme_location' => 'primary_navigation',
'menu_class' => (is_front_page()) ? 'menu menu--home' : 'menu',
'menu_class' => 'menu',
'container' => false,
'before' => '<li class="%s">',
'after' => '</li>',
Expand Down
7 changes: 6 additions & 1 deletion resources/views/partials/page-header.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<div class="page-header">
<p class="breadcrumb"><a href="/">{{ __('Home', 'coop-library') }}</a></p>
@if(App::breadcrumb())
<p class="breadcrumb">{!! App::breadcrumb() !!}</p>
@endif
<h1>{!! App::title() !!}</h1>
@if(is_front_page())
<p class="subhead">{{ get_bloginfo('description') }}</p>
@endif
</div>
10 changes: 10 additions & 0 deletions resources/views/partials/search-form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<form role="search" method="get" class="search-form @if($modifier)search-form--{{ $modifier }}@endif" action="{{ home_url() }}">
<label>
<span class="screen-reader-text">{{ __('Search for:', 'coop-library') }}</span>
<input type="search" class="search-field"@if($placeholder) placeholder="{{ $placeholder }}"@endif value="" name="s">
</label>
<button type="submit" class="search-submit">
<span class="screen-reader-text">{{ __('Search', 'coop-library') }}</span>
@svg('search', 'icon--search', ['focusable' => 'false', 'aria-hidden' => 'true'])
</button>
</form>
1 change: 1 addition & 0 deletions resources/views/partials/sort.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ul class="link-list">
<li class="link-list__item"><a href="{{ App::sortUrl('added') }}"{!! (!isset($_GET['order_by']) || $_GET['order_by']==='added') ? ' aria-current="true"' : '' !!}>{{ __('Date added', 'coop-library') }}</a></li>
<li class="link-list__item"><a href="{{ App::sortUrl('published') }}"{!! ($_GET['order_by']==='published') ? ' aria-current="true"' : '' !!}>{{ __('Date published', 'coop-library') }}</a></li>
<li class="link-list__item"><a href="{{ App::sortUrl('viewed') }}"{!! ($_GET['order_by']==='viewed') ? ' aria-current="true"' : '' !!}>{{ __('Most viewed', 'coop-library') }}</a></li>
<li class="link-list__item"><a href="{{ App::sortUrl('favorited') }}"{!! ($_GET['order_by']==='favorited') ? ' aria-current="true"' : '' !!}>{{ __('Most favorited', 'coop-library') }}</a></li>
</ul>
</div>
Expand Down