Skip to content

Instantly share code, notes, and snippets.

View nicooprat's full-sized avatar

Nico Prat nicooprat

View GitHub Profile
@nicooprat
nicooprat / prefetch.ts
Last active July 9, 2024 07:35
Vue-router prefetch plugin for router-links (Vue 3)
/**
* Prefetch pages to make navigation faster (from route to route)
* Monkey patch router-link to trigger async import when the link is in the viewport
* Use a queue & requestIdleCallback to prevent browser from freezing
* Install in Vue 3 with `import prefetch from './prefetch` then `app.use(prefetch)`
* */
import { watchPausable } from '@vueuse/core';
import { ref } from 'vue';
import { RouterLink, useRouter } from 'vue-router';
@nicooprat
nicooprat / barba.js
Created February 4, 2017 10:13
Concept for Barba v2
// Internally, do something like this
Promise
.all([
this.loadNewContent,
this.transitionOut({
fromRoute,
event,
oldContainer,
promise
@nicooprat
nicooprat / main.scss
Last active March 1, 2024 07:36
Sharing Tailwind config with SASS (Tailwind beta & Tailwind 1.0)
// Setting variables like this wouldn't be possible because SASS would
// get through this file before Tailwind does (because it's PostCSS)
$--color-primary: theme('colors.blue');
$--font-serif: theme('fontFamily.serif');
body {
color: rgba($--color-primary, .5);
font-family: $font-serif;
}
@nicooprat
nicooprat / custom-callback.php
Created October 22, 2018 17:22
Create an ACF block with Sage 9 & Blade
function my_acf_block_render_callback( $block ) {
$slug = str_replace('acf/', '', $block['name']);
$block['slug'] = $slug;
$block['classes'] = implode(' ', [$block['slug'], $block['className'], $block['align']]);
echo \App\template("blocks/${slug}", ['block' => $block]);
}
@nicooprat
nicooprat / .htaccess
Created July 17, 2017 08:10
W3 Total Cache conf
# BEGIN W3TC Browser Cache
<IfModule mod_mime.c>
AddType text/css .css
AddType text/x-component .htc
AddType application/x-javascript .js
AddType application/javascript .js2
AddType text/javascript .js3
AddType text/x-js .js4
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
@nicooprat
nicooprat / keyframes-mixin.less
Last active March 9, 2021 07:58
A simple and elegant keyframes mixin for LESS
// --------------
// Needs LESS compiler >= 1.7.0
// Docs : http://lesscss.org/features/#detached-rulesets-feature
// --------------
// 1. Define the mixin for cross browser keyframes
.keyframes(@name,@rules) {
@-webkit-keyframes @name {
@nicooprat
nicooprat / mailjet.js
Created June 13, 2020 08:46
Send a mail through Mailjet
const mailjet = nodeMailjet.connect(process.env.MAILJET_PUBLIC, process.env.MAILJET_PRIVATE)
// Send through Mailjet
mailjet.post('send', { version: 'v3.1' }).request({
Messages: [{
From: {
Email: sender.email,
Name: sender.name,
},
Subject: i18n.t('emails.a1.subject', { app: config.app }),
@nicooprat
nicooprat / mjml.js
Last active June 13, 2020 08:40
Render HTML from MJML
const mjml2html = require('mjml')
renderer.renderToString(app, (err, mjml) => {
if (err) throw err
// Remove illegal MJML attribute added by Vue to avoid warnings
mjml = mjml.replace('data-server-rendered="true"', '')
// Compile MJML to raw HTML
const { html, errors } = mjml2html(mjml)
@nicooprat
nicooprat / template.vue
Last active June 13, 2020 08:32
Render absolute path with vue-router
<template>
<router-link v-for="(action, i) in actions" :key="i" :to="action.href" v-slot="{ href }">
<mj-button :href="getAbsoluteURL(href)" font-family="Roboto, sans-serif" font-size="14px" :font-weight="action.type === 'primary' ? 'bold' : 'normal'" :background-color="action.type === 'primary' ? '#0072f0' : '#ffffff'" :color="action.type === 'primary' ? '#ffffff' : '#36404d'" padding-bottom="15px">
{{ action.label }}
</mj-button>
</router-link>
</template>
<script>
const app = new Vue({
@nicooprat
nicooprat / mjml.vue
Last active June 11, 2020 10:16
Example of MJML template with Vue
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-image v-if="image" width="100px" :src="image"></mj-image>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text :font-size="large ? '20px' : '16px'" color="#F45E43" font-family="helvetica">{{ text }}</mj-text>
<mj-button v-for="action in actions" :key="i" :href="action.href">
{{ action.label }}
</mj-button>