Skip to content

Instantly share code, notes, and snippets.

View bouveng's full-sized avatar

Johan Bouveng bouveng

View GitHub Profile
@bouveng
bouveng / ig.js
Created May 29, 2024 22:02
js for fetching instagram posts
const limit = '9' || 6;
const token = 'XXXXXXXXXXXXXXXXXXX';
const active = '1' || 0;
const doc = document;
const get = () => {
if ( !token || !active ) {
return;
}
@bouveng
bouveng / lazy.js
Created May 29, 2024 21:56
Lazyloading breakdance sections
document.addEventListener( 'DOMContentLoaded', function(){
let els = document.querySelectorAll( '.bde-section-lazy' ),
lazy = new IntersectionObserver( ( els, o ) => {
els.forEach( e => {
if ( e.isIntersecting ) {
let el = e.target;
el.classList.remove( 'bde-section-lazy' );
o.unobserve( el );
@bouveng
bouveng / img.php
Created April 28, 2024 14:12
wp image sizes
add_action( 'init', function() {
remove_image_size( '1536x1536' );
remove_image_size( '2048x2048' );
}, 100 );
add_filter( 'intermediate_image_sizes', fn( $sizes ) => array_diff( $sizes, [ 'medium_large' ] ));
@bouveng
bouveng / loadImage.js
Created August 29, 2020 21:42
loadImage.js
export function loadImage(url) {
return new Promise(resolve => {
const image = new Image();
image.addEventListener('load', () => {
resolve(image);
});
image.src = url;
});
}
import Entity from '../Entity.js';
import Trait from '../Trait.js';
import Killable from '../traits/Killable.js';
import {loadSpriteSheet} from '../loaders/sprite.js';
export function loadCheepSlow() {
return loadSpriteSheet('cheep-gray')
.then(createCheepSlowFactory);
}
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|webp|svg|gif|woff|woff2|js|css)$">
Header set Cache-Control "max-age=31536000, public"
Header append Vary: Accept-Encoding
Header set Access-Control-Allow-Origin “*”
</filesMatch>
<ifmodule mod_deflate.c>
<ifmodule mod_mime.c>
AddType application/x-font-ttf .ttf
AddType application/font-woff .woff
function createTileCandidateLayer(tileResolver) {
const resolvedTiles = [];
const tileSize = tileResolver.tileSize;
const getByIndexOriginal = tileResolver.getByIndex;
tileResolver.getByIndex = function getByIndexFake(x, y) {
resolvedTiles.push({x, y});
return getByIndexOriginal.call(tileResolver, x, y);
}
$jq_integrity = 'sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=';
$jq_crossorigin = 'anonymous';
$jq_cdn = 'https://code.jquery.com/jquery-3.5.0.min.js';
$jq_version = '3.5.0';
if(! is_admin()){
function add_cdn_attrs( $tag, $handle, $src ) {
global $jq_integrity, $jq_crossorigin;
@bouveng
bouveng / functions.php
Created April 26, 2020 15:06
exclude pages from wp search
// exclude pages from wp search
if ( !is_admin() ) {
function exclude_pages( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
@bouveng
bouveng / functions.php
Created April 15, 2020 16:16
add webp mime to wp
add_filter( 'upload_mimes', 'add_webp', 1, 1 );
function add_webp( $mime_types ) {
$mime_types['webp'] = 'image/webp';
return $mime_types;
}