Skip to content

Instantly share code, notes, and snippets.

View bjoerge's full-sized avatar

Bjørge Næss bjoerge

View GitHub Profile
@bjoerge
bjoerge / find-missing-assets.ts
Created March 27, 2020 09:44
Find missing assets in dataset
import got from "got"
import createClient from "@sanity/client"
import {asyncScheduler, concat, defer, EMPTY, from} from "rxjs"
import {
map,
mergeMap,
retry,
scan,
takeLast,
tap,
@bjoerge
bjoerge / recover-schema.md
Last active October 4, 2024 15:04
How to recover lost schema from *.sanity.studio.md

First, go to https://<yourname>.sanity.studio (or to the url of your studio if it's hosted elsewhere). Then open the developer console (usually by one of the keyboard shortcuts Command+Option+I, F12 or Control+Shift+I depending on what browser/platform you are using)

Steps

  1. Open the Sources tab
  2. Find the app.bundle.js file in the sidebar tree view.
  3. Hit the pretty print source button
  4. Locate your schema types by searching (e.g. try searching for one of your custom types) it in the source view.
@bjoerge
bjoerge / SvgFileToStringInput.jsx
Created June 13, 2019 09:44
SvgFileToStringInput.jsx
import React from 'react'
import PropTypes from 'prop-types'
import {PatchEvent, set} from 'part:@sanity/form-builder/patch-event'
import FormField from 'part:@sanity/components/formfields/default'
export default class SvgFileToStringInput extends React.Component {
inputRef = React.createRef()
static propTypes = {
value: PropTypes.string,
type: PropTypes.object,
@bjoerge
bjoerge / ExternalDataInput.js
Created December 21, 2018 12:46
Example of a custom sanity input that allows the user to select from a list of values retrieved from an external API
import React from 'react'
import SearchableSelect from 'part:@sanity/components/selects/searchable'
import FormField from 'part:@sanity/components/formfields/default'
import {PatchEvent, set, unset} from 'part:@sanity/form-builder/patch-event'
const STREET_NAMES = [
'Thorvald Meyers gate',
'Champs-Élysées',
'Lombard Street',
'Abbey Road',
@bjoerge
bjoerge / default-slug.js
Created June 25, 2018 10:53
Generate default slug w/listener
const {deburr, kebabCase} = require('lodash')
const sanityClient = require('@sanity/client')
const client = sanityClient({
projectId: '<your priojectId>',
dataset: '<your dataset>',
token: '<your auth token>',
useCdn: false
})
@bjoerge
bjoerge / .babelrc
Last active June 11, 2018 10:59
multiplex-ws
{
"presets": [
[
"env",
{
"targets": {
"node": "6",
"chrome": "59",
"safari": "10",
"firefox": "56",
@bjoerge
bjoerge / translate.js
Last active April 21, 2021 23:01
Translate all locale strings with missing translations in a Sanity dataset - https://sanity.io
/* eslint-disable no-console */
import client from 'part:@sanity/base/client'
import reduce from 'json-reduce'
// see https://github.com/sanity-io/sanity/blob/next/packages/example-studio/schemas/languages.js for an example
import {SUPPORTED_LANGUAGES} from '../schemas/languages'
import Translate from '@google-cloud/translate'
const translateAPI = new Translate({
@bjoerge
bjoerge / stateContainer.js
Last active April 9, 2018 12:46
stateContainer.js
import {Subject} from 'rx/Subject'
import {of} from 'rx/observable/of'
import {publishReplay, refCount, concat} from 'rxjs/observable'
function createState(initial) {
const onChange$ = new Subject()
function onChange(...args) {
onChange$.next(args)
}
@bjoerge
bjoerge / treeify.js
Created September 27, 2017 13:34
treeify
const assert = require('assert')
// takes a flat structure like this
const input = [
{
level: 1,
title: '1'
},
{
level: 1,
@bjoerge
bjoerge / package.json
Last active September 13, 2017 07:29
npx test
{
"name": "gist-test",
"version": "0.0.0",
"bin": "./run.js"
}