This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function episodeParser(data) { | |
| const { id, | |
| title, | |
| description, | |
| optionalField, | |
| anotherOptionalField | |
| } = data | |
| const parsedEpisode = { guid: id, title, summary: description } | |
| if (optionalField) { | |
| parsedEpisode.optionalField = optionalField |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function episodeParser({ | |
| id, | |
| title, | |
| description = 'No summary', | |
| optionalField, | |
| anotherOptionalField | |
| }) { | |
| return { | |
| guid: id, | |
| title, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = { | |
| id: 1, | |
| title: 'An episode', | |
| description: 'An episode summary', | |
| anotherOptionalField: 'some data' | |
| } | |
| episodeParser(data) | |
| //> { guid: 1, title: 'An episode', summary: 'An episode summary', anotherOptionalField: 'some data' } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This is an example script on how to export content from | |
| * the blog schemas out to markdown. | |
| * | |
| * Run this script in a Sanity project folder with | |
| * $ sanity exec markdown.js > blogposts.md | |
| * on a public dataset, and | |
| * $ sanity exec --with-user-token markdown.js > blogposts.md | |
| * on a private dataset | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Webtask.io Serverless Comments for Sanity.io based blog projects with SPAM protection | |
| * | |
| * Get Akismet API token (free for non-commercial projects): https://akismet.com/development/ | |
| * Make an API token with write permissions in manage.sanity.io/projects/<ProjectId> | |
| * | |
| * Remember to add Secrets and NPM Modules | |
| */ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const algoliasearch = require('algoliasearch'); | |
| const request = require('request'); | |
| const ndjson = require('ndjson'); | |
| const {bindNodeCallback} = require('rxjs'); | |
| const {streamToRx} = require('rxjs-stream'); | |
| const {bufferCount, map, mergeMap, toArray, tap} = require('rxjs/operators'); | |
| // Algolia configuration | |
| const algoliaApp = 'your_app_id'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "sanity-schema": { | |
| "prefix": "schema", | |
| "body": [ | |
| "export default {\n name: '$1',\n type: '${2|document,object|}',\n title: '$1',\n fields: [\n $3\n ]\n}\n" | |
| ], | |
| "description": "Makes a new Sanity schema" | |
| }, | |
| "sanity-type": { | |
| "prefix": "type", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require("axios"); | |
| const sanityClient = require('@sanity/client') | |
| const client = token => sanityClient({ | |
| projectId: '3do82whm', | |
| dataset: 'production', | |
| token | |
| }) | |
| const NPM_API_SEARCH = "https://api.npms.io/v2/search/suggestions" | |
| const NPM_API_PGKINFO = "https://api.npms.io/v2/package/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Fragment } from 'react' | |
| import { BlockEditor } from 'part:@sanity/form-builder' | |
| class EditorWithToC extends React.PureComponent { | |
| generateToC = portableText => { | |
| if (!portableText) { return [] } | |
| const defaultHeadings = /h[1-4]/ | |
| const headings = portableText.filter(({ style }) => style.match(defaultHeadings)) | |
| return ( | |
| <Fragment> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Fragment } from 'react' | |
| import { BlockEditor } from 'part:@sanity/form-builder' | |
| import calculateLix from 'lix-index' | |
| const lixIllustration = lix => { | |
| if (lix > 55) return '😭' // very difficult | |
| if (lix > 45) return '😟' // difficult | |
| if (lix > 35) return '😐' // medium | |
| if (lix > 25) return '🙂' // easy | |
| if (lix > 10) return '😃' // very easy |