Skip to content

Instantly share code, notes, and snippets.

View jacmaes's full-sized avatar

Jacques Maes jacmaes

View GitHub Profile
@jacmaes
jacmaes / fastest-google-fonts.html
Created January 19, 2021 13:07
Fastest Google Fonts #css
// From: https://csswizardry.com/2020/05/the-fastest-google-fonts/
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" as="style" href="$CSS&amp;display=swap">
<link rel="stylesheet" href="$CSS&amp;display=swap" media="print" onload="this.media='all'">
<noscript>
<link rel="stylesheet" href="$CSS&amp;display=swap">
</noscript>
@jacmaes
jacmaes / pw-pagination.php
Created February 14, 2020 14:43
PW pagination in <head> #pw #php
// From Kreativan's gist: https://gist.github.com/kreativan/bddcfa1c923f563d968ff40f2fb4e32e
<?php
//-----------------------------------------------------------------------
// Add rel="next" and rel="prev" tags for pagination in head section
//-----------------------------------------------------------------------
$wire->addHookAfter('Page::render', function(HookEvent $event) {
$page = $event->object;
if($page->template == 'admin') return;
@jacmaes
jacmaes / google-maps-distance.js
Created February 14, 2020 14:41
Google Maps distance #js
// From Kreativan's gist: https://gist.github.com/kreativan/0ea5ea16dce287c324b5494a57c20286
/**
* Need to include google maps api with initMap callback
* @function initMap
*
*/
function initMap() {
@jacmaes
jacmaes / pw-user-login.php
Created February 14, 2020 14:40
PW user login #pw #php
// From Kreativan's gist: https://gist.github.com/kreativan/4f58bf3a8f35cc307ef2effe3a27086d
<?php
// logout
if($input->get->logout) {
$session->logout();
$session->redirect($page->url);
}
@jacmaes
jacmaes / find-pages-by-date.php
Created February 14, 2020 14:39
Find pages by date #pw #php
// From Kreativan's gist: https://gist.github.com/kreativan/85c697b18b286a9cc0be70e35acb0a9d
<?php
// Find Pages by date
$year = date('Y');
$month = date("F");
$startTime = strtotime("1 $month $year");
$endTime = strtotime("next month", $startTime);
@jacmaes
jacmaes / remove-inline-styles.js
Created October 16, 2019 15:11
remove inline styles from CKeditor #js #pw
// Place in site/modules/InputfieldCKEditor/config.js in Processwire to disallow inline styles.
CKEDITOR.editorConfig = function( config ) {
config.disallowedContent = '*{*}'; // All styles disallowed
};
@jacmaes
jacmaes / add-www-and-https.txt
Last active September 12, 2019 15:04
Add www and https #htaccess
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
@jacmaes
jacmaes / google-fonts.html
Created June 22, 2019 19:13
Google Fonts #html
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css?family=Roboto|Open+Sans:400,400i,600&amp;display=swap" rel="stylesheet">
# Host Google fonts locally:
https://google-webfonts-helper.herokuapp.com/fonts
@jacmaes
jacmaes / save-external-image-and-save-it.php
Created May 23, 2019 15:18
Save external image and rename it in Processwire #pw
<?php
// 1. We generate a static image from Mapbox's static Maps API.
// 2. We save it to an image field
// 3. We rename it to a more comprehensible filename, and then we add an extension (png by default for Mapbox).
// View investigacioncontemporanea.com -> "university" template for example of implementation.
if (!$page->image) {
$p = $page;
$p->of(false);
@jacmaes
jacmaes / Advanced selectors for PW search engine
Last active May 20, 2019 16:07
advanced-selectors-search-engine.php #pw #php
<?php
# https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#new-selectors-as-regular-arrays
# New selectors as associative or regular arrays
$results = $pages->find([
'template' => ['basic-page', 'product'],
'title|body%=' => $sanitizer->text($input->get('q')),
'categories' => $sanitizer->intArray($input->get('categories')),
'sort' => '-created'