-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
770 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php namespace App; | ||
|
||
/** | ||
* Add postMessage support | ||
*/ | ||
add_action('customize_register', function (\WP_Customize_Manager $wp_customize) { | ||
$wp_customize->get_setting('blogname')->transport = 'postMessage'; | ||
}); | ||
|
||
/** | ||
* Customizer JS | ||
*/ | ||
add_action('customize_preview_init', function () { | ||
wp_enqueue_script('sage/customizer', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php namespace App; | ||
|
||
use Roots\Sage\Template; | ||
use Roots\Sage\Template\Wrapper; | ||
|
||
/** | ||
* Determine which pages should NOT display the sidebar | ||
* @link https://codex.wordpress.org/Conditional_Tags | ||
*/ | ||
add_filter('sage/display_sidebar', function ($display) { | ||
/** The sidebar will NOT be displayed if ANY of the following return true. */ | ||
return $display ? !in_array(true, [ | ||
is_404(), | ||
is_front_page(), | ||
is_page_template('template-custom.php'), | ||
]) : $display; | ||
}); | ||
|
||
/** | ||
* Add <body> classes | ||
*/ | ||
add_filter('body_class', function (array $classes) { | ||
// Add page slug if it doesn't exist | ||
if (is_single() || is_page() && !is_front_page()) { | ||
if (!in_array(basename(get_permalink()), $classes)) { | ||
$classes[] = basename(get_permalink()); | ||
} | ||
} | ||
|
||
// Add class if sidebar is active | ||
if (display_sidebar()) { | ||
$classes[] = 'sidebar-primary'; | ||
} | ||
|
||
return $classes; | ||
}); | ||
|
||
/** | ||
* Clean up the_excerpt() | ||
*/ | ||
add_filter('excerpt_more', function () { | ||
return ' … <a href="' . get_permalink() . '">' . __('Continued', 'sage') . '</a>'; | ||
}); | ||
|
||
|
||
/** | ||
* Use Wrapper by default | ||
*/ | ||
add_filter('template_include', function ($main) { | ||
if (!is_string($main) || !(string) $main) { | ||
return $main; | ||
} | ||
$main = basename($main, '.php'); | ||
return Template::wrap(new Wrapper($main, 'layouts/base.php'))->locate(); | ||
}, 109); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php namespace App; | ||
|
||
use Roots\Sage\Asset; | ||
use Roots\Sage\Assets\JsonManifest; | ||
use Roots\Sage\Template; | ||
|
||
/** | ||
* @param string $slug | ||
* @param array $context | ||
*/ | ||
function template_unwrap($slug = '', $context = []) { | ||
if ($file = Template::unwrap($slug, $context)->locate()) { | ||
/** @noinspection PhpIncludeInspection */ | ||
include $file; | ||
} | ||
} | ||
|
||
/** | ||
* @param array $context | ||
*/ | ||
function template_sidebar($context = []) { | ||
template_part('sidebar', $context); | ||
} | ||
|
||
/** | ||
* @param $template | ||
* @param array $context | ||
*/ | ||
function template_part($template, $context = []) { | ||
if ($file = (new Template($template, $context))->locate()) { | ||
/** @noinspection PhpIncludeInspection */ | ||
include $file; | ||
} | ||
} | ||
|
||
/** | ||
* @param $filename | ||
* @return string | ||
*/ | ||
function asset_path($filename) { | ||
static $manifest; | ||
isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json'); | ||
return (string) new Asset($filename, $manifest); | ||
} | ||
|
||
/** | ||
* Determine whether to show the sidebar | ||
* @return bool | ||
*/ | ||
function display_sidebar() { | ||
static $display; | ||
isset($display) || $display = apply_filters('sage/display_sidebar', true); | ||
return $display; | ||
} | ||
|
||
/** | ||
* Page titles | ||
* @return string | ||
*/ | ||
function title() { | ||
if (is_home()) { | ||
if ($home = get_option('page_for_posts', true)) { | ||
return get_the_title($home); | ||
} | ||
return __('Latest Posts', 'sage'); | ||
} | ||
if (is_archive()) { | ||
return get_the_archive_title(); | ||
} | ||
if (is_search()) { | ||
return sprintf(__('Search Results for %s', 'sage'), get_search_query()); | ||
} | ||
if (is_404()) { | ||
return __('Not Found', 'sage'); | ||
} | ||
return get_the_title(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace Roots\Sage; | ||
|
||
use Roots\Sage\Assets\IManifest; | ||
|
||
/** | ||
* Class Template | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
class Asset { | ||
|
||
public static $dist = '/dist'; | ||
|
||
/** @var IManifest Currently used manifest */ | ||
protected $manifest; | ||
|
||
protected $asset; | ||
|
||
protected $dir; | ||
|
||
public function __construct($file, IManifest $manifest = null) { | ||
$this->manifest = $manifest; | ||
$this->asset = basename($file); | ||
$this->dir = dirname($file) != '.' ? dirname($file) : ''; | ||
} | ||
|
||
public function __toString() { | ||
return $this->getUri(); | ||
} | ||
|
||
public function getUri() { | ||
$file = self::$dist . '/' . $this->dir . '/' . ($this->manifest ? $this->manifest->get($this->asset) : $this->asset); | ||
return get_template_directory_uri() . $file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php namespace Roots\Sage\Assets; | ||
|
||
/** | ||
* Interface IManifest | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
interface IManifest { | ||
|
||
/** | ||
* Get the cache-busted filename | ||
* | ||
* If the manifest does not have an entry for $file, then return $file | ||
* | ||
* @param string $file The original name of the file before cache-busting | ||
* @return string | ||
*/ | ||
public function get($file); | ||
|
||
/** | ||
* Get the asset manifest | ||
* | ||
* @return array | ||
*/ | ||
public function getAll(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php namespace Roots\Sage\Assets; | ||
|
||
/** | ||
* Class JsonManifest | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
class JsonManifest implements IManifest { | ||
/** @var array */ | ||
protected $manifest = []; | ||
|
||
/** | ||
* JsonManifest constructor | ||
* @param string $manifestPath Local filesystem path to JSON-encoded manifest | ||
*/ | ||
public function __construct($manifestPath) { | ||
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : []; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function get($file) { | ||
return isset($this->manifest[$file]) ? $this->manifest[$file] : $file; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function getAll() { | ||
return $this->manifest; | ||
} | ||
} |
Oops, something went wrong.