Skip to content

Instantly share code, notes, and snippets.

View rexxars's full-sized avatar

Espen Hovlandsdal rexxars

View GitHub Profile
@rexxars
rexxars / sanity-v5-codeshift.js
Created January 12, 2023 21:32
JSCodeShift for Sanity client v5 (default import => named import)
const importName = 'createClient'
v5ClientImport.parser = 'tsx'
module.exports = v5ClientImport
function v5ClientImport(fileInfo, api) {
const j = api.jscodeshift
const root = j(fileInfo.source)
// Imports
@rexxars
rexxars / groqHookToSlack.groq
Last active August 23, 2022 20:41
GROQ-hook projection example for Slack Block Kit
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": coalesce(title, "Untitled article"),
"emoji": true
}
},
@rexxars
rexxars / bundleChecker.js
Last active March 16, 2021 21:06
Sanity studio bundle update checker
import {useEffect} from 'react'
import config from 'config:sanity'
const BUNDLE_CHECK_INTERVAL = 15 * 1000
async function getCurrentHash() {
const basePath = (config.project && config.project.basePath) || '/'
const html = await fetch(basePath).then((res) => res.text())
const [, hash] = html.match(/app\.bundle\.js\?(\w+)/) || []
return hash
@rexxars
rexxars / ProductInput.js
Created February 5, 2021 23:59
Custom product input, barebones
import React from 'react'
import Preview from 'part:@sanity/base/preview'
import FormField from 'part:@sanity/components/formfields/default'
import SearchableSelect from 'part:@sanity/components/selects/searchable'
import PatchEvent, {set, setIfMissing, unset} from 'part:@sanity/form-builder/patch-event'
const products = [
{
title: 'Adidas Superstar Canvas Green',
handle: 'canvas-grene',

Keybase proof

I hereby claim:

  • I am rexxars on github.
  • I am rexxars (https://keybase.io/rexxars) on keybase.
  • I have a public key ASAZscecEP8CIxmTKGtiZKIwB3c9jOYVvQMG5QE0OO_0zQo

To claim this, I am signing this object:

@rexxars
rexxars / npm-use-yarn-if-lockfile.zsh
Created May 4, 2020 02:04
Use yarn instead of npm if there is a `yarn.lock`
npm() {
if [[ ($1 == "i" || $1 == "install") && -e yarn.lock ]]; then
read "REPLY?Use yarn (Y/n)? "
echo ""
if [[ $REPLY =~ ^[Yy]$ || $REPLY == "" ]]; then
if [[ $2 == "--save-dev" ]]; then
echo "yarn add --dev ${@:3}"
command yarn add --dev "${@:3}"
return $?
elif [[ $2 == "--save" ]]; then
@rexxars
rexxars / blocksToHtml.vue
Created February 14, 2018 11:33
Temporary "block content to vue"
<template>
<div v-html="renderHtml(content)"></div>
</template>
<script>
const blocksToHtml = require("@sanity/block-content-to-html")
const h = blocksToHtml.h
const serializers = {
<?php
require_once './vendor/autoload.php';
$client = new Sanity\Client([
'projectId' => '3do82whm',
'dataset' => 'production',
'useCdn' => true,
]);
$doc = $client->getDocument('47abbe60-f184-4eff-99e0-3a85c5c07c3a');
$html = Sanity\BlockContent::toHtml($doc['body'], [
@rexxars
rexxars / input.js
Created December 1, 2017 14:01
Uglify JS bug
// Reduced/boiled down from a webpack bundle, obviously not the real thing
var zing = {};
(function foo(module, exports, __webpack_require__) {
"use strict";
exports.default = sortableContainer;
function sortableContainer(WrappedComponent) {
var _class,
@rexxars
rexxars / index.js
Last active November 10, 2017 17:45
Webpack test
var React = require('react');
var ReactDOM = require('react-dom');
var ReactMarkdown = require('react-markdown');
var input = '# This is a header\n\nAnd this is a paragraph';
ReactDOM.render(
React.createElement(ReactMarkdown, {source: input}),
document.getElementById('container')
);