Browse Source

feat: allow custom pages for catalog

pull/351/head
Ricardo Aragon 2 years ago
parent
commit
f35dad2989
  1. 2
      assets/scripts/aldine.js
  2. 2
      assets/styles/layouts/_header.scss
  3. 10
      assets/styles/layouts/_page-catalog.scss
  4. 6
      dist/mix-manifest.json
  5. 2
      dist/scripts/aldine.js
  6. 2
      dist/scripts/catalog-admin.js
  7. 2
      dist/styles/aldine.css
  8. 7
      inc/actions/namespace.php
  9. 9
      inc/activation/namespace.php
  10. 13
      inc/helpers/namespace.php
  11. 20706
      package-lock.json
  12. 20
      partials/content-front-page.php

2
assets/scripts/aldine.js

@ -11,7 +11,7 @@ const routes = new Router( {
// Home page // Home page
home, home,
// Catalog page // Catalog page
catalog, pageTemplatePageCatalog: catalog,
} ); } );
// Load Events // Load Events

2
assets/styles/layouts/_header.scss

@ -73,7 +73,7 @@
} }
} }
.page.catalog { .page.page-template-page-catalog {
.header { .header {
height: rem(381); height: rem(381);
} }

10
assets/styles/layouts/_page-catalog.scss

@ -121,7 +121,7 @@ fieldset {
margin: 0 1rem; margin: 0 1rem;
} }
.catalog { .page-template-page-catalog {
.books { .books {
width: calc(100% - 1rem); width: calc(100% - 1rem);
padding: 0; padding: 0;
@ -240,7 +240,7 @@ fieldset {
margin-left: 0; margin-left: 0;
} }
.catalog .book { .page-template-page-catalog .book {
height: 16.25rem; height: 16.25rem;
width: calc(100% / 3 - 1rem); width: calc(100% / 3 - 1rem);
margin: 0 1rem 1rem 0; margin: 0 1rem 1rem 0;
@ -248,7 +248,7 @@ fieldset {
} }
@media #{$breakpoint-large} { @media #{$breakpoint-large} {
.catalog #content { .page-template-page-catalog #content {
width: calc(100% - 1rem); width: calc(100% - 1rem);
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
@ -279,13 +279,13 @@ fieldset {
margin-left: 0; margin-left: 0;
} }
.catalog .books { .page-template-page-catalog .books {
width: 75%; width: 75%;
float: right; float: right;
margin-left: 0; margin-left: 0;
} }
.catalog .book { .page-template-page-catalog .book {
height: 16.25rem; height: 16.25rem;
max-width: calc(100% / 3 - 1rem); max-width: calc(100% / 3 - 1rem);
margin: 0 1rem 1rem 0; margin: 0 1rem 1rem 0;

6
dist/mix-manifest.json vendored

@ -1,12 +1,12 @@
{ {
"/scripts/aldine.js": "/scripts/aldine.js?id=f7e0ad5cfcc135b918f6", "/scripts/aldine.js": "/scripts/aldine.js?id=5ecff462d448444a549b",
"/scripts/call-to-action.js": "/scripts/call-to-action.js?id=33370b66c7af12320fc0", "/scripts/call-to-action.js": "/scripts/call-to-action.js?id=33370b66c7af12320fc0",
"/scripts/catalog-admin.js": "/scripts/catalog-admin.js?id=e8d84fb090536b8e49e9", "/scripts/catalog-admin.js": "/scripts/catalog-admin.js?id=2bc3bfa90831ab142ee9",
"/scripts/customizer.js": "/scripts/customizer.js?id=14dca3944228dd789c27", "/scripts/customizer.js": "/scripts/customizer.js?id=14dca3944228dd789c27",
"/scripts/customizer-toggle.js": "/scripts/customizer-toggle.js?id=c31594589675d7c5662a", "/scripts/customizer-toggle.js": "/scripts/customizer-toggle.js?id=c31594589675d7c5662a",
"/scripts/page-section.js": "/scripts/page-section.js?id=19d5c30146ea1a763bcf", "/scripts/page-section.js": "/scripts/page-section.js?id=19d5c30146ea1a763bcf",
"/styles/editor.css": "/styles/editor.css?id=b7c2449babe566571767", "/styles/editor.css": "/styles/editor.css?id=b7c2449babe566571767",
"/styles/aldine.css": "/styles/aldine.css?id=8d3bfb61118a9ee435a1", "/styles/aldine.css": "/styles/aldine.css?id=534450cda31e22f1f2a0",
"/fonts/pressbooks-theme.woff": "/fonts/pressbooks-theme.woff?id=2a7aae81673f4707bbe7", "/fonts/pressbooks-theme.woff": "/fonts/pressbooks-theme.woff?id=2a7aae81673f4707bbe7",
"/images/banner.jpg": "/images/banner.jpg?id=04a813e0b4f94ddfef19", "/images/banner.jpg": "/images/banner.jpg?id=04a813e0b4f94ddfef19",
"/images/catalog-header.jpg": "/images/catalog-header.jpg?id=223b9f7a23985f2a72df", "/images/catalog-header.jpg": "/images/catalog-header.jpg?id=223b9f7a23985f2a72df",

2
dist/scripts/aldine.js vendored

File diff suppressed because one or more lines are too long

2
dist/scripts/catalog-admin.js vendored

File diff suppressed because one or more lines are too long

2
dist/styles/aldine.css vendored

File diff suppressed because one or more lines are too long

7
inc/actions/namespace.php

@ -230,11 +230,12 @@ function hide_catalog_content_editor() {
if ( ! isset( $post_id ) ) { if ( ! isset( $post_id ) ) {
return; return;
} }
$pagename = get_the_title( $post_id ); $template = get_page_template_slug( $post_id );
if ( $pagename === 'Catalog' ) { if ( $template === 'page-catalog.php' ) {
add_action( add_action(
'edit_form_after_title', function() { 'edit_form_after_title', function() {
printf( '<p>%s</p>', __( 'This page displays your network catalog, so there is no content to edit.', 'pressbooks-aldine' ) ); // printf( '<p>%s</p>', __( 'This page displays your network catalog, so there is no content to edit.', 'pressbooks-aldine' ) );
printf( '<p>%s</p>', __( 'Note for devs: We want to allow to edit it but with some restrictions', 'pressbooks-aldine' ) );
} }
); );
remove_post_type_support( 'page', 'editor' ); remove_post_type_support( 'page', 'editor' );

9
inc/activation/namespace.php

@ -7,6 +7,8 @@
namespace Aldine\Activation; namespace Aldine\Activation;
use function Aldine\Helpers\get_catalog_page;
/** /**
* Create default page content, importing from Pressbooks Publisher, if possible. * Create default page content, importing from Pressbooks Publisher, if possible.
*/ */
@ -87,6 +89,9 @@ function create_default_content() {
'catalog' => [ 'catalog' => [
'post_title' => __( 'Catalog', 'pressbooks-aldine' ), 'post_title' => __( 'Catalog', 'pressbooks-aldine' ),
'post_content' => '', 'post_content' => '',
'meta_input' => [
'_wp_page_template' => 'page-catalog.php',
],
], ],
'home' => [ 'home' => [
'post_title' => __( 'Home', 'pressbooks-aldine' ), 'post_title' => __( 'Home', 'pressbooks-aldine' ),
@ -141,7 +146,7 @@ function create_menus() {
if ( ! wp_get_nav_menu_object( $menu_name ) ) { if ( ! wp_get_nav_menu_object( $menu_name ) ) {
$menu_id = wp_create_nav_menu( $menu_name ); $menu_id = wp_create_nav_menu( $menu_name );
$catalog = get_page_by_title( __( 'Catalog', 'pressbooks-aldine' ) ); $catalog = get_catalog_page();
if ( $catalog && defined( 'PB_PLUGIN_VERSION' ) ) { if ( $catalog && defined( 'PB_PLUGIN_VERSION' ) ) {
wp_update_nav_menu_item( wp_update_nav_menu_item(
$menu_id, $menu_id,
@ -177,7 +182,7 @@ function create_menus() {
); );
} }
$catalog = get_page_by_title( __( 'Catalog', 'pressbooks-aldine' ) ); $catalog = get_catalog_page();
if ( $catalog && defined( 'PB_PLUGIN_VERSION' ) ) { if ( $catalog && defined( 'PB_PLUGIN_VERSION' ) ) {
wp_update_nav_menu_item( wp_update_nav_menu_item(
$menu_id, $menu_id,

13
inc/helpers/namespace.php

@ -437,3 +437,16 @@ function maybe_truncate_string( $string, $length = 40 ) {
} }
return $string; return $string;
} }
/**
* Get catalog page.
*
* @return WP_Post|null
*/
function get_catalog_page(): ?\WP_Post {
$catalog_pages = get_pages( [
'meta_key' => '_wp_page_template',
'meta_value' => 'page-catalog.php',
]);
return $catalog_pages[0] ?? null;
}

20706
package-lock.json generated

File diff suppressed because it is too large Load Diff

20
partials/content-front-page.php

@ -7,14 +7,9 @@
* @package Aldine * @package Aldine
*/ */
?>
<?php
use function Aldine\Helpers\get_catalog_data; use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\has_sections; use function Aldine\Helpers\has_sections;
$front_page_catalog = get_option( 'pb_front_page_catalog' );
$pb_front_page_catalog_title = get_option( 'pb_front_page_catalog_title' ); $pb_front_page_catalog_title = get_option( 'pb_front_page_catalog_title' );
$latest_books_title = ( ! empty( $pb_front_page_catalog_title ) ) ? $pb_front_page_catalog_title : __( 'Our Latest Titles', 'pressbooks-aldine' ); $latest_books_title = ( ! empty( $pb_front_page_catalog_title ) ) ? $pb_front_page_catalog_title : __( 'Our Latest Titles', 'pressbooks-aldine' );
if ( get_option( 'pb_front_page_catalog' ) ) { if ( get_option( 'pb_front_page_catalog' ) ) {
@ -24,6 +19,11 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
$next_page = $page + 1; $next_page = $page + 1;
} }
$catalog_page = \Aldine\Helpers\get_catalog_page();
if ( $catalog_page ) {
$catalog_permalink = get_permalink( $catalog_page->ID );
}
?> ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
@ -55,10 +55,10 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
<?php if ( get_option( 'pb_front_page_catalog' ) && ! empty( $catalog_data['books'] ) ) : ?> <?php if ( get_option( 'pb_front_page_catalog' ) && ! empty( $catalog_data['books'] ) ) : ?>
<div id="latest-books" class="latest-books"> <div id="latest-books" class="latest-books">
<h2 id="latest-books-title"><?php echo $latest_books_title; ?></h2> <h2 id="latest-books-title"><?php echo $latest_books_title; ?></h2>
<div class="slider" role="region" aria-labelledby="latest-books-title" data-total-pages="<?php echo $catalog_data['pages']; ?>" <div class="slider" role="region" aria-labelledby="latest-books-title" data-total-pages="<?php echo $catalog_data['pages']; ?>"
<?php <?php
if ( $next_page <= $catalog_data['pages'] ) : if ( $next_page <= $catalog_data['pages'] ) :
?> ?>
data-next-page="<?php echo $next_page; ?>"<?php endif; ?>> data-next-page="<?php echo $next_page; ?>"<?php endif; ?>>
<ul class="books"> <ul class="books">
<?php <?php
@ -73,7 +73,7 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
?> ?>
</div> </div>
<p class="catalog-link"> <p class="catalog-link">
<a class="call-to-action" href="<?php echo network_home_url( '/catalog/' ); ?>"><?php _e( 'View Complete Catalog', 'pressbooks-aldine' ); ?></a> <a class="call-to-action" href="<?php echo $catalog_permalink ?? ''; ?>"><?php _e( 'View Complete Catalog', 'pressbooks-aldine' ); ?></a>
</p> </p>
</div> </div>
<?php endif; ?> <?php endif; ?>

Loading…
Cancel
Save