Skip to content

Instantly share code, notes, and snippets.

View d4rekanguok's full-sized avatar
💭
I may be slow to respond.

Derek Nguyen d4rekanguok

💭
I may be slow to respond.
  • Pen & Pillow
  • Lisbon, PT
View GitHub Profile
const { default: Schema } = require("@sanity/schema");
const { htmlToBlocks, randomKey } = require("@sanity/block-tools");
const { JSDOM } = require("jsdom");
const schemaBlog = Schema.compile({
name: "myBlog",
types: [
{
title: "Hjelpeartikkel",
name: "hjelpeartikkel",
@d4rekanguok
d4rekanguok / webpack.config.js
Last active March 11, 2023 09:52
Config Storybook to avoid conflicts with SVGR
const path = require('path');
const pathToInlineSvg = path.resolve(__dirname, '../resources/icons');
module.exports = (_, _, defaultConfig) => {
const rules = defaultConfig.module.rules;
// modify storybook's file-loader rule to avoid conflicts with svgr
const fileLoaderRule = rules.find(rule => rule.test.test('.svg'));
fileLoaderRule.exclude = pathToInlineSvg;
@d4rekanguok
d4rekanguok / component.svelte
Last active January 31, 2022 14:14
A svelte component you can drop into your svelte kit app to view a list of all your components (poor man's Storybook)
// updated to add props editting, rendering component inside iframe & allowing resizing viewer
<script context="module">
const modules = import.meta.globEager('/src/sections/*.svelte')
const componentNames = Object.keys(modules)
</script>
<script lang="ts">
import cx from 'clsx'
import { browser } from '$app/env'
@d4rekanguok
d4rekanguok / desk-structure.js
Created October 22, 2021 15:25
Monkey patch document list to hide create menu
import S from '@sanity/desk-tool/structure-builder'
const DocumentListSansCreate = ({ title, filter }) => {
const _documentList = S.documentList()
.title(title)
.filter(filter)
_documentList.__serialize = _documentList.serialize.bind(_documentList)
_documentList.serialize = (...args) => {
const { menuItems, ...rest } = _documentList.__serialize(...args)
@d4rekanguok
d4rekanguok / fetch-meta.js
Last active August 2, 2021 16:15
Script to fetch metadata w/ Sanity before initiating Gatsby/Next/etc.
const path = require('path')
const fs = require('fs/promises')
require('dotenv').config({
// vvvvvvvvvv replace w/ your env
path: path.resolve(process.cwd(), '.env.local')
})
const createClient = require('@sanity/client')
const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
<script lang="ts">
export let name = 'World'
</script>
<div>Hello {name}</div>
const fs = require('fs')
const path = require('path')
const toUpperCase = ([first, ...rest]) => [first.toUpperCase(), ...rest].join('')
exports.sourceNodes = ({ actions, createContentDigest, store }) => {
const { directory } = store.getState().program
const raw = fs.readFileSync(path.join(directory, 'package.json'))
@d4rekanguok
d4rekanguok / widget-id.js
Last active August 29, 2019 03:00
ID widget for netlifyCMS
/**
* This is now a npm package!
* Please find the better version of this gist here:
* https://github.com/d4rekanguok/netlify-cms-widgets/blob/master/packages/widget-id/src/control.tsx
*/
const unified = require('unified')
const remarkParse = require('remark-parse')
const remarkHtml = require('remark-html')
exports.createResolvers = ({
createResolvers,
}) => {
const toHTML = async (source) => {
const vfile = await unified()
.use(remarkParse)
@d4rekanguok
d4rekanguok / utils.ts
Created July 18, 2019 12:55
custom reorder widget for netlify cms
import differenceBy from 'lodash/differenceBy'
export const hasItem = <T>(data: T[], item: T, key: keyof T): boolean => {
return data.some(datum => datum[key] === item[key])
}
export const removeOutdatedItem = <T>(
data: T[],
outdated: T[],
key: keyof T