Skip to content

Instantly share code, notes, and snippets.

View DominikAngerer's full-sized avatar
🏠
For sure working from somewhere 🤘

DominikAngerer DominikAngerer

🏠
For sure working from somewhere 🤘
View GitHub Profile
methods: {
...
storyblokImageUpload(fileblob, filename, success, failure) {
this.api.client.post(
`/spaces/${this.spaceId}/assets`,
{ filename: filename },
{ headers: { Authorization: this.options.oauthToken } }, // uses the option with the name `oauthToken` which needs to be configured in the schema definition of the field you're using the plugin in.
).then((response) => {
let request = new XMLHttpRequest()
@DominikAngerer
DominikAngerer / richTextField.js
Created April 16, 2020 22:10
RichText with sanitize-html
// npm install sanitize-html
const sanitizeHtml = require('sanitize-html');
// npm install storyblok-js-client
const StoryblokClient = require('storyblok-js-client')
// Storyblok is now available as variable which contains the richTextResolver functionality
const Storyblok = new StoryblokClient({})
function createMarkup(storyblokHTML) {
return {
@DominikAngerer
DominikAngerer / richTextField.js
Created April 16, 2020 22:07
RichText with DOMPurify
const StoryblokClient require('storyblok-js-client')
const createDOMPurify = require('dompurify')
const { JSDOM } = require('jsdom')
// Storyblok is now available as variable which contains the richTextResolver functionality
const Storyblok = new StoryblokClient({})
// For Node this needs to use the jhttps://github.com/cure53/DOMPurify#okay-makes-sense-lets-move-on
const jsDomWindow = new JSDOM('').window;
const DOMPurify = createDOMPurify(jsDomWindow);
@DominikAngerer
DominikAngerer / richTextField.js
Created March 20, 2020 13:06
Storyblok RichTextRenderer without token
import StoryblokClient from 'storyblok-js-client'
// Storyblok is now available as variable which contains the richTextResolver functionality
const Storyblok = new StoryblokClient({})
function createMarkup(storyblokHTML) {
return {
__html: Storyblok.richTextResolver.render(storyblokHTML),
}
}
const Storyblok = require('storyblok-js-client') // npm install storyblok-js-client
const MAPI_TOKEN = "your_oauth_token"
const spaceId = 73358 // your configured space id folder
const yourFolderId = 5663791 // your parent folder
let StoryblokClient = new Storyblok({
oauthToken: MAPI_TOKEN
})
@DominikAngerer
DominikAngerer / parse-storyblok-comments.php
Last active November 12, 2019 10:39
Manually parse the Storyblok HTML editable comments. Nginx SSI.
<?php
$blok = array("_editable" => "<!--#storyblok#{\"name\": \"column\", \"space\": \"48408\", \"uid\": \"7c44c5d8-0adb-4c01-a797-12d9b300b99b\", \"id\": \"307934\"}-->");
/**
* Manually parse the Storyblok HTML editable comments. Use your templating language to output
* keys = values as html attributes without quotes or with single quotes.
*
* @param array $blok This is your component object
* @param boolean $raw Decide if function should return raw array or inline string
@DominikAngerer
DominikAngerer / nuxt.config.generate.js
Last active August 11, 2019 17:35
Nuxt Generate function to create pages according to Storybloks Links API
// const axios = require('axios')
// Using Links API
generate: {
routes: function (callback) {
const token = `YOUR_TOKEN`
const version = 'published'
let cache_version = 0
@DominikAngerer
DominikAngerer / now.json
Created June 5, 2019 13:14
Nuxt Builder for Now
{
"version": 2,
"builds": [
{
"src": "nuxt.config.js",
"use": "@nuxtjs/now-builder",
"config": {}
}
],
"routes": [
..........................................................................................................
..........................................................................................................
...............................*..........................................................................
............................Y@@@@Y.....................................E@@@@E.............................
...........................E@@WR@@@...................................E@@WW@@@*...........................
.........................E@@@GGGG@@W.................................:@@WGGGW@@Y..........................
........................Y@@WGGGGGR@@E................................@@QGGGGGW@@G.........................
.......................E@@WGGGGGGGW@@:..........*YEYEEEE*...........@@@GGGGGGGG@@@........................
......................R@@GGGGGGGGGGQ@@...EEG@@@@@@@@@@@@@@@@@REY:..Y@@GGGGGGGGGGQ@@.......................
.....................G@@GGGGGGGGGGGG@@@@@@WWWWGGGGGGGGGGGGGRW
<template>
<section class="util__container">
<h1>Cache Cleared</h1>
<br>
<p>Old Cache Version: {{oldCacheVersion}}</p>
<p>New Cache Version: {{newCacheVersion}}</p>
</section>
</template>
<script>