Skip to content

Instantly share code, notes, and snippets.

View kmelve's full-sized avatar
💬
is typing

Knut Melvær kmelve

💬
is typing
View GitHub Profile
@kmelve
kmelve / makeNewEntryFromSlack.js
Created March 31, 2017 06:38
Webtask.io function that takes an `/command word;definition` from Slack and puts it into a graph.cool database.
require('isomorphic-fetch')
// your graph.cool project id
const projectId = 'stammesprak'
module.exports = (context, cb) => {
const text = context.body.text.split(';')
const definition = text[1]
const word = text[0]
/*
@kmelve
kmelve / header.twig
Created September 30, 2017 14:15
header.twig
{% set title = title is defined ? title : '' %}
{% set excerpt = excerpt is defined ? excerpt : '' %}
{% set noPaddingTop = noPaddingTop is defined ? noPaddingTop : false %}
{% set visuallyHideTitle = visuallyHideTitle is defined ? visuallyHideTitle : false %}
<header class="c-page__header {% if noPaddingTop %}u-p-none{% endif %}">
<h1 class="c-page__title {% if visuallyHideTitle %}u-visually-hidden{% endif %}">{{ title }}</h1>
{% if excerpt | length %}
<p class="c-page__intro">{{ excerpt }}</p>
{% endif %}
@kmelve
kmelve / header.twig
Created September 30, 2017 14:15
header.twig
{% set title = title is defined ? title : '' %}
{% set excerpt = excerpt is defined ? excerpt : '' %}
{% set noPaddingTop = noPaddingTop is defined ? noPaddingTop : false %}
{% set visuallyHideTitle = visuallyHideTitle is defined ? visuallyHideTitle : false %}
<header class="c-page__header {% if noPaddingTop %}u-p-none{% endif %}">
<h1 class="c-page__title {% if visuallyHideTitle %}u-visually-hidden{% endif %}">{{ title }}</h1>
{% if excerpt | length %}
<p class="c-page__intro">{{ excerpt }}</p>
{% endif %}
@kmelve
kmelve / blockContent.vue
Created January 11, 2018 14:37
Sanity BlockContent in Vue
<style lang="scss">
a.button {
text-decoration: none;
display: inline-block;
}
.blurb, .quote > * {
padding-bottom: 1rem;
@media(min-width: 800px) {
padding-bottom: 0;
@kmelve
kmelve / fullfillment.js
Last active March 11, 2018 18:32
Intent and fullfillment in Sanity
export default {
name: 'fullfillments',
title: 'Fullfillments',
description: 'Short texts that represent this content as chatbot fullfillments',
type: 'array',
of: [
{
type: 'string'
}
]
@kmelve
kmelve / fullfillmentFromSanity.js
Last active March 12, 2018 05:57
Webtask.io function for returning a fullfillment to Dialogflow.
/**
* @param context {WebtaskContext}
*/
/*
* Set up your Sanity client with an project id, and the
* name of your dataset. If you have set custom permissions
* you'll also need to set it up with a access token, which
* can be placed in webtask’s secrets. Note that in that case
* you should also add some authentication to incoming requests.
@kmelve
kmelve / markdown.js
Last active June 1, 2018 22:05
Block content to Markdown script
/* eslint-disable no-console */
/**
* Generate a markdown document in a dev.to format.
* This runs from the studio folder and requires additional
* dependencies:
* - @sanity/block-content-to-markdown
* - minimist
*
* Run this with $ sanity exec markdown.js -- --id=<document id>
*/
@kmelve
kmelve / BlockContentToVue.vue
Created June 26, 2018 14:42
Block Content To Hyperscript implementation for Vue
<template>
<div class="content">
<div v-html="renderHtml(indexedContent)"></div>
</div>
</template>
<script>
/**
*** Run block content from Sanity through serializers
**/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):"object"==typeof exports?exports.Dropzone=t(require("react"),require("prop-types")):e.Dropzone=t(e.React,e.PropTypes)}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r
@kmelve
kmelve / webtask-photo-map-slack-updater.js
Created July 27, 2018 09:09
Serverless task for updating slack about new photos in https://codepen.io/kmelve/pen/VdqPbV?editors=0010
require('babel-polyfill');
const SanityClient = require('@sanity/client');
const axios = require('axios');
const client = SanityClient({
projectId: 'anokeucs',
dataset: 'sanitycsstricks',
useCdn: false
})
/**
* @param context {WebtaskContext}