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
<section> | |
<div class="top"></div> | |
<div class="middle"></div> | |
<div class="bottom"></div> | |
</section> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
body { |
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
<?php | |
add_filter('get_algolia_index_name', 'get_algolia_index_name'); | |
// Filter to construct canonical index names | |
function get_algolia_index_name($name = '') { | |
global $wpdb; | |
$env_prefix = getenv('ALGOLIA_INDEX_PREFIX') ?: ''; // local, dev, stage, or prod | |
$base_prefix = $wpdb->base_prefix; // wp_ | |
return "${env_prefix}_${base_prefix}${name}"; |
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
{ | |
"hitsPerPage": 20, | |
"searchableAttributes": [ | |
"unordered(title)", | |
"unordered(content)", | |
], | |
"distinct": true, | |
"attributesForFaceting": [], | |
"attributesToSnippet": ["content:10", "title:10"], | |
"attributesToHighlight": null, |
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
<?php | |
define('THEME_PATH', get_stylesheet_directory() . '/'); | |
function algolia_get_settings($index_name) { | |
$settings_file_path = THEME_PATH . 'algolia-json/' . $index_name . '-settings.json'; | |
if (!file_exists($settings_file_path)) { | |
return false; | |
} |
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
<?php | |
public function set_config($args, $assoc_args) { | |
global $algolia; | |
$canonical_index_name = apply_filters('algolia_index_name', 'global_search'); | |
$index = $algolia->initIndex($canonical_index_name); | |
// Set index settings if '--settings' flag exists | |
if (isset($assoc_args['settings'])) { |
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
<?php | |
add_action('save_post', 'algolia_save_post', 10, 3); | |
function algolia_save_post($id, $post, $update) { | |
global $algolia; | |
$post_type = $post->post_type; | |
$post_status = $post->post_status; |
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
<?php | |
class AlgoliaSerializer { | |
public function run() { | |
add_filter('post_to_record', array($this, 'post_to_record')); | |
... | |
} | |
// Converts a Post to an Algolia record | |
function post_to_record($post) { |
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
<?php | |
public function reindex($args, $assoc_args) { | |
// Init global index | |
$index = $algolia->initIndex('global_search'); | |
// Clear all objects in the index | |
$index->clearObjects()->wait(); | |
// Get all blog IDs in multisite network |
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
<?php | |
if (! (defined('WP_CLI') && WP_CLI)) { | |
return; | |
} | |
class Algolia_Command { | |
public function reindex($args, $assoc_args) { | |
... | |
} | |
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
// Inspired by Vue: https://alligator.io/vuejs/global-event-bus/ | |
// Sending events: EventBus.emit('clicky', clickArg); | |
// Receiving events: EventBus.on('clicky', clickArg => console.log(clickArg)); | |
const EventBus = { | |
events: {}, | |
emit(event, data) { | |
if (!this.events[event]) { | |
return; | |
} |
NewerOlder