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. 18
      partials/content-front-page.php

2
assets/scripts/aldine.js

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

2
assets/styles/layouts/_header.scss

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

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

@ -121,7 +121,7 @@ fieldset {
margin: 0 1rem;
}
.catalog {
.page-template-page-catalog {
.books {
width: calc(100% - 1rem);
padding: 0;
@ -240,7 +240,7 @@ fieldset {
margin-left: 0;
}
.catalog .book {
.page-template-page-catalog .book {
height: 16.25rem;
width: calc(100% / 3 - 1rem);
margin: 0 1rem 1rem 0;
@ -248,7 +248,7 @@ fieldset {
}
@media #{$breakpoint-large} {
.catalog #content {
.page-template-page-catalog #content {
width: calc(100% - 1rem);
margin-left: auto;
margin-right: auto;
@ -279,13 +279,13 @@ fieldset {
margin-left: 0;
}
.catalog .books {
.page-template-page-catalog .books {
width: 75%;
float: right;
margin-left: 0;
}
.catalog .book {
.page-template-page-catalog .book {
height: 16.25rem;
max-width: calc(100% / 3 - 1rem);
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/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-toggle.js": "/scripts/customizer-toggle.js?id=c31594589675d7c5662a",
"/scripts/page-section.js": "/scripts/page-section.js?id=19d5c30146ea1a763bcf",
"/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",
"/images/banner.jpg": "/images/banner.jpg?id=04a813e0b4f94ddfef19",
"/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 ) ) {
return;
}
$pagename = get_the_title( $post_id );
if ( $pagename === 'Catalog' ) {
$template = get_page_template_slug( $post_id );
if ( $template === 'page-catalog.php' ) {
add_action(
'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' );

9
inc/activation/namespace.php

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

13
inc/helpers/namespace.php

@ -437,3 +437,16 @@ function maybe_truncate_string( $string, $length = 40 ) {
}
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

18
partials/content-front-page.php

@ -7,14 +7,9 @@
* @package Aldine
*/
?>
<?php
use function Aldine\Helpers\get_catalog_data;
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' );
$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' ) ) {
@ -24,6 +19,11 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
$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(); ?>>
@ -56,9 +56,9 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
<div id="latest-books" class="latest-books">
<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']; ?>"
<?php
if ( $next_page <= $catalog_data['pages'] ) :
?>
<?php
if ( $next_page <= $catalog_data['pages'] ) :
?>
data-next-page="<?php echo $next_page; ?>"<?php endif; ?>>
<ul class="books">
<?php
@ -73,7 +73,7 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
?>
</div>
<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>
</div>
<?php endif; ?>

Loading…
Cancel
Save