Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
onefriendaday / Plugin.js
Created January 7, 2019 11:42
Storyblok decision plugin
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div>
<div class="uk-form-label">Do you have a headset?</div>
<label><input type="radio" v-model="model.has_headset" :value="true" /> Yes</label>
<label><input type="radio" v-model="model.has_headset" :value="false" class="uk-margin-small-left" /> No</label>
<div v-if="model.has_headset" class="uk-margin-small-top">
<div class="uk-form-label">How many?</div>
<input class="uk-width-1-1" v-model="model.number_of_headsets" type="number" />
</div>
@onefriendaday
onefriendaday / cleanup-script.js
Last active November 29, 2018 18:19
Script to cleanup stories from _editable attribute
const StoryblokClient = require('storyblok-js-client')
// Insert your oauth token and folder id
const Storyblok = new StoryblokClient({
oauthToken: 'YOUR_OAUTH_TOKEN'
})
// Insert your source space and folder id
const spaceId = 'YOUR_SPACE_ID'
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div><input class="uk-width-1-1" v-model="model.number" /></div>`,
methods: {
initWith() {
return {
plugin: 'number-plugin',
number: '0'
}
},
@onefriendaday
onefriendaday / fieldtype.js
Created November 22, 2018 13:28
SEO fieldtype
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `
<div>Google snippet preview:
<div style="margin:5px 0 15px;padding:10px;color:#000;background:#fff">
<div style="color:blue;text-decoration:underline">{{ model.title }}</div>
<div style="color:green">yoursite.com/example</div>
<div>{{ model.description }}</div>
</div>
<div class=uk-form-row>
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div>
<div v-if="modalIsOpen">Modal is open</div>
<div v-if="!modalIsOpen">Modal is closed</div>
<a @click="doOpen">Open modal</a>
<a @click="doClose">Close modal</a>
<select v-model="options"><option value="1"></option></select>
</div>`,
data() {
@onefriendaday
onefriendaday / modal-fieldtype-example.js
Created November 20, 2018 13:53
Example of toggle a Storyblok fieldtype to fullscreenmode
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div>
<div v-if="modalIsOpen">Modal is open</div>
<div v-if="!modalIsOpen">Modal is closed</div>
<a @click="doOpen">Open modal</a>
<a @click="doClose">Close modal</a>
</div>`,
data() {
return {
fetch('https://api.storyblok.com/v1/cdn/datasource_entries?datasource=github-repositories&token=' + window.storyblok.config.accessToken)
.then(response => response.json())
.then(myJson => {
console.log(myJson)
})
const Promise = require('bluebird')
const path = require('path')
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
const storyblokEntry = path.resolve('src/templates/storyblok-entry.js')
graphql(
@onefriendaday
onefriendaday / index.js
Created October 9, 2018 18:49
Simple contact form with Storyblok and Nodejs
/*
Instructions:
1. Install the dependencies with "npm init" and "npm install storyblok-js-client http"
1. Create a content type with a "message" field type
2. Exchange oauthToken (from the my account section of Storyblok) and spaceId
3. Start the server with "node index.js" and execute following curl request
curl -X POST \
http://127.0.0.1:3020 \
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div><textarea class="uk-width-1-1" v-model="model.rte_content" ref="mytextarea" id="mytextarea">Hello, World!</textarea></div>`,
methods: {
initWith() {
return {
plugin: 'atlas_rte',
rte_content: 'Hello world!'
}
},