Skip to content

Instantly share code, notes, and snippets.

View M-Drummond's full-sized avatar
🦨

mackinley M-Drummond

🦨
  • 01:25 (UTC +10:00)
View GitHub Profile
@M-Drummond
M-Drummond / splitUrlParameters.ts
Created March 22, 2024 00:42
Split URL Parameters
export function splitUrlParameters( url : string ) {
const params = new URLSearchParams(url);
const paramObject = {} as Object;
for (const [key, value] of params.entries()) {
if (paramObject[key]) {
if (Array.isArray(paramObject[key])) {
paramObject[key].push(value);
} else {
paramObject[key] = [paramObject[key], value];
@M-Drummond
M-Drummond / webp.py
Last active March 14, 2024 04:17
Python: Convert WebP All Images In Dir To WebP
#run via: $ python3 webp.py
import os
# Present working directory
directory = "."
# Loop through each file
for file in os.listdir(directory):
if os.path.isfile(os.path.join(directory, file)):
@M-Drummond
M-Drummond / images.sh
Created March 5, 2024 00:17
Bulk Create WebP Images via the CLI
#!/bin/bash
# place this file in your images dir, run `bash images.sh`
# this present working dir
directory="."
# Loop through each file
for file in "$directory"/*; do
if [ -f "$file" ]; then
@M-Drummond
M-Drummond / vite.config.js
Created March 3, 2024 22:15
ViteJS Config for Wordpress Theme Dev
import legacy from '@vitejs/plugin-legacy'
import ViteRestart from 'vite-plugin-restart';
import 'dotenv/config'
import tailwindConfig from './tailwind.config';
// https://vitejs.dev/config/
export default ({ command }) => ({
base: command === 'serve' ? '' : '/dist/',
build: {
manifest: true,
@M-Drummond
M-Drummond / functions.php
Created March 3, 2024 22:14
Wordpress + ViteJS
function vite_scripts() {
// wp-config needs: define( 'FRONTEND_DEV_MODE' , true ); added
if ( FRONTEND_DEV_MODE ) {
echo '<!-- vite time -->
<script type="module" src="https://localhost:3000/@vite/client"></script>
<script type="module" src="https://localhost:3000/src/js/app.ts"></script>
' ;
} else {
echo '
@M-Drummond
M-Drummond / dropdown.php
Last active March 3, 2024 10:02
WP / AlpineJS / TailwindCSS - dropdown for a list of venues
<?php
// component: dropdown
function filter_dropdown( $label, $type , $tax ) { ?>
<div class="relative w-full md:w-auto x-cloak" id="filter_<?php echo $type ;?>" x-data="{ menuListOpen : false }" >
<button
@click.away="menuListOpen = false"
@click="menuListOpen = ! menuListOpen "
:class="{ '' : menuListOpen } "
class="uppercase cursor-pointer border dropdown-button flex flex-row items-center justify-between self-end mr-0 ml-auto px-4 border-solid border-current h-[42px] w-full md:w-[216px]"
@M-Drummond
M-Drummond / icons.ts
Created March 3, 2024 09:58
AlpineJS - Define SVG Icons
import Alpine from 'alpinejs'
export default Alpine.store('icons', {
close: `<svg width="42" height="36" viewBox="0 0 42 36" fill="none" xmlns="http://www.w3.org/2000/svg">
<line x1="10.6464" y1="27.8597" x2="31.8596" y2="6.6465" stroke="currentColor"/>
<line x1="10.7471" y1="7.03982" x2="31.9603" y2="28.253" stroke="currentColor"/>
</svg>`,
open: `
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
@M-Drummond
M-Drummond / getProductsFromAPI.ts
Last active March 3, 2024 09:59
Vue/Axios - Fetch products via Axios and assign to a Pinia store
import axios from 'axios'
import { useGlobalStore } from '@/stores/global'
export async function getChildProductDataFromApi(child: { child_article_nbr: any }) {
const options = {
decompress: false
}
const url = `/apis/ui/products/${child.child_article_nbr}`
@M-Drummond
M-Drummond / media.twig
Last active March 3, 2024 09:58
CraftCMS - get the webp/jpeg version of a a sourceset.
{% macro imageSourceTags( image ) %}
{% if image.extension is defined %}
{% if image | length >= 1 and image.extension != 'svg' %}
{% set formats = ['webp', 'jpg'] %}
{% for format in formats %}
{% set srcset = image.getSrcset([185, 576, 768, 960, 1454, 1920, 2560], { format: format }) %}
<source srcset="{{ srcset }}" type="image/{{ format }}" sizes="100vw">
{% endfor %}
@M-Drummond
M-Drummond / filteredProducts.ts
Last active March 3, 2024 10:00
Vue - Computed property to filter an array of products.
export function filteredProducts() {
// get the total list of products
let filteredProducts = useGlobalStore().products;
// set criteria - examples var names here.
const stamina = useGlobalStore().decisions.stamina
const type = useGlobalStore().decisions.type
const group = useGlobalStore().decisions.group