Skip to content

Instantly share code, notes, and snippets.

is typing

Knut Melvær kmelve

is typing
View GitHub Profile
kmelve / create-community-newsletter.js
Created Dec 8, 2020
Create Mailchimp campaign document action proof of concept
View create-community-newsletter.js
const fetch = require('got');
const client = require('../client');
const HTML = require('../lib/newsletter-template');
const MAILCHIMP_URL = '';
const API_TOKEN = process.env.MAILCHIMP_TOKEN;
const QUERY = `//groq
kmelve / disable-js.html
Last active Nov 30, 2020
JavaScript-less no JS please. Inspired by
View disable-js.html
<title>No JS please</title>
kmelve / PTEditor.js
Last active Nov 25, 2020
Handle pasting of Github flavored markdown for the Portable Text array.
View PTEditor.js
import React, { useState, forwardRef, Fragment } from 'react'
import { BlockEditor } from 'part:@sanity/form-builder'
import Switch from 'part:@sanity/components/toggles/switch'
import css from './PTeditor.module.css'
import { handlePaste } from './handlePaste'
function CustomEditor(props, ref){
const [customPaste, setCustomPaste] = useState(false)
function handleCustomPaste () {
kmelve / opt-out-for-gif.js
Created Oct 28, 2020
GIFs with Portable Text in Gatsby
View opt-out-for-gif.js
import React from "react";
import Img from "gatsby-image";
import { getFluidGatsbyImage } from "gatsby-source-sanity";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";
import iconLinksList from "./iconLinksList.js";
import YouTube from "../components/YouTube.js";
import getYouTubeID from "get-youtube-id";
const sanityConfig = { projectId: "rx426fbd", dataset: "production" };
kmelve / GitHubSelector.module.css
Created Oct 21, 2020
Simple Github repo selector for Sanity Studio
View GitHubSelector.module.css
@import 'part:@sanity/base/theme/variables-style';
.item {
padding: var(--small-padding);
.searchableSelect {
composes: spacing from 'part:@sanity/components/buttons/default-style';
grid-column: span 2;
kmelve / migrateValues.js
Created Aug 29, 2020
Migrate categories in an array field on
View migrateValues.js
/* eslint-disable no-console */
import client from 'part:@sanity/base/client'
// Run this script with: `sanity exec --with-user-token migrations/migrateValues.js`
// This example shows how you may write a migration script that migrates a field value
// on a specific document type.
// This will migrate documents in batches of 100 and continue patching until no more documents are
// returned from the query.
kmelve / BlockContent.js
Created May 14, 2020
Mininal exampe of how to Twitter embeds with
View BlockContent.js
// Example of how to output this in a React frontend
import React from 'react'
import BlockContent from '@sanity/block-content-to-react'
import { TwitterTweetEmbed } from 'react-twitter-embed'
const Tweet = ({url}) => {
const exp = /\/status\/(\d+)($|[?/])/
const [, id] = exp.exec(url) || []
if (id) {
return <TwitterTweetEmbed className="sliderBoxes" tweetId={id} options={{conversation: 'none', 'hide-thread': true}} />
kmelve / import.js
Last active May 10, 2020
How to import documents, and add them as a new item in an array of references with
View import.js
* import.js
* Install dependencies:
* yarn add p-queue nanoid
* or
* npm i p-queue nanoid && sanity install
* Run this script with:
* sanity exec --with-user-token import.js
kmelve / entries-by-date-this-year.js
Created May 9, 2020
Structure definition for listing entries by date of the current year for Sanity Studio
View entries-by-date-this-year.js
import S from '@sanity/desk-tool/structure-builder'
import eachDayOfInterval from 'date-fns/eachDayOfInterval'
import startOfYear from 'date-fns/startOfYear'
import startOfDay from 'date-fns/startOfDay'
import endOfDay from 'date-fns/endOfDay'
let now = new Date()
export default () => S.listItem()
.title('Entries by day this year')
kmelve / gallery.js
Created May 9, 2020
A simple gallery type for
View gallery.js