Skip to content

Instantly share code, notes, and snippets.

is typing

Knut Melvær kmelve

is typing
View GitHub Profile
View sanity.config.ts
import {defineConfig, type Role} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'
export const EDITOR_TYPES = ['post']
const isAdmin = (roles: Role[]) => !roles?.find(({name = ''}) => name === 'administrator')
export default defineConfig({
kmelve / handlePaste.js
Last active October 7, 2022 21:38
Markdown Paste Handling for Sanity Studio v2 using micromark
View handlePaste.js
/* Remember:
sanity install @sanity/code-input
yarn add micromark 
import { micromark } from 'micromark'
import { htmlToBlocks } from '@sanity/block-tools'
export async function handlePaste(input) {
const { event, type, path } = input
const text = event.clipboardData.getData('text/plain')
kmelve / import_json_from_sanity_appsscript.js
Last active September 22, 2022 07:31 — forked from paulgambill/import_json_appsscript.js
Adjusted script for working with the Sanity API
View import_json_from_sanity_appsscript.js
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
# Assumes that you have the Netlify and jq CLI tools installed and that you are logged in.
# Only been tested on macOS and zsh
# Will change the build image for all sites in a Netlify account to the specified image
# Usage: sh ./
# This assumes that you have logged in with the CLI fairly recently and that you're on macOS
# For other systems:
NETLIFY_AUTH=$(cat ~/Library/Preferences/netlify/config.json|jq -r ".users[].auth.token")
kmelve / posts.blade.php
Created August 10, 2022 11:51
Minimal implementation of content in Laraval using the offical example app as a starting point.
View posts.blade.php
<!-- resources/views/posts.blade.php -->
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
kmelve / TheProject.html
Created April 6, 2022 07:05
The HTML for The World Wide Web project (
View TheProject.html
<TITLE>The World Wide Web project</TITLE>
<NEXTID N="55">
<H1>World Wide Web</H1>The WorldWideWeb (W3) is a wide-area<A
NAME=0 HREF="WhatIs.html">
hypermedia</A> information retrieval
initiative aiming to give universal
kmelve / route.js
Created February 11, 2022 17:48
Simple A/B testing abstraction used on
View route.js
export default {
name: 'route',
type: 'document',
title: 'Route',
fields: [
name: 'title',
type: 'string',
description: 'This title populates meta-tags on the webpage'
kmelve / _middleware.js
Created November 12, 2021 04:27
Proof of concepts simple page views with Next.js middleware
View _middleware.js
// posts/_middleware.js
import { NextResponse } from 'next/server'
const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
apiVersion: '2021-10-21',
const baseUrl = cdn => `https://${config.projectId}.api${cdn ? 'cdn' : ''}${config.apiVersion}`
const queryUrl = baseUrl() + `/data/query/${config.dataset}/`
kmelve / migration.js
Created November 10, 2021 22:15
Simple migration script that can be run with `sanity exec` in a Sanity Studio
View migration.js
// migration.js
* Run:
* sanity exec --with-user-token migration.js
import sanityClient from 'part:@sanity/base/client'
const client = sanityClient.withConfig({ apiVersion: '2021-11-10' })
// Patch 1000 at a time
const query = `*[_type == "stream"][0...999]{title, publishedDate, _id, _rev}`
kmelve / blurhash.js
Last active February 19, 2022 20:44
Retroactively add Blurhash strings to image assets in your Sanity Content Lake.
View blurhash.js
* Retroactively add Blurhash strings to image assets in your Sanity Content Lake.
* 1. yarn add got sharp blurhash
* 2. run sanity exec blurhash --with-user-token
* 3. repeat (patches 100 assets in 1 transaction pr run)
* Some images might take a while to process.
import client from 'part:@sanity/base/client'
import got from 'got'