Skip to content

Instantly share code, notes, and snippets.

View SebbeJohansson's full-sized avatar

Sebastian Johansson SebbeJohansson

View GitHub Profile
@SebbeJohansson
SebbeJohansson / link-helpers.js
Created May 10, 2023 08:48
Storyblok Richtext formatting for proper translated internal links and prevents "Cannot read properties of undefined (reading 'color')" error.
@SebbeJohansson
SebbeJohansson / useAsyncStoryblok.ts
Last active March 23, 2023 07:17
Custom useAsyncStoryblok with proper error handling
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
import type { ISbStoriesParams, StoryblokBridgeConfigV2, ISbStoryData, ISbError, ISbResult } from '@storyblok/vue';
export const useCustomAsyncStoryblok = async (
url: string,
apiOptions: ISbStoriesParams = {},
bridgeOptions: StoryblokBridgeConfigV2 = {},
) => {
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
const story = useState<ISbStoryData>(`${uniqueKey}-state`, () => ({} as ISbStoryData));
@SebbeJohansson
SebbeJohansson / Nuxt2StoryblokInternalLinkCorrection.vue
Last active April 6, 2023 11:05
Storyblok Richtext Link Correction for Nuxt2 (storyblok adds a language automatically at the start of the url that we dont use)
<script>
import { mapState } from 'vuex';
import { renderStoryblokRichText } from '~/utils/storyblok/rich-text-helpers';
export default {
props: {
blok: {
type: Object,
required: true,
},
@SebbeJohansson
SebbeJohansson / Custom useAsyncStoryblok - [...slug].vue
Last active January 28, 2023 19:00
Custom useAsyncStoryblok function with proper error handling
<!-- Example page -->
<script setup lang="ts">
import { ISbStoryData } from '@storyblok/vue/dist';
const route = useRoute();
const { locale } = useI18n();
let story = {} as ISbStoryData;
try {
@SebbeJohansson
SebbeJohansson / SsrStoryblokComponent.vue
Last active January 28, 2023 11:49
Custom nuxt3 storyblok component rendering - Previously needed for proper ssr rendering
<!-- This is not needed anymore, just using useStoryblok() or useAsyncStoryblok() should work. -->
<!-- https://github.com/storyblok/storyblok-nuxt/issues/155 -->
<script setup lang="ts">
import { SbBlokData } from '@storyblok/vue/dist';
const props = defineProps({
blok: {
type: Object,
required: true,
},
@SebbeJohansson
SebbeJohansson / Nuxt3 Discord Authentication Example - nuxt.config.ts
Last active April 7, 2024 19:02
Nuxt3 Discord Authentication Example
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [
'@nuxt-alt/auth', // https://www.npmjs.com/package/@nuxt-alt/auth
'@pinia/nuxt',
],
auth: {
redirect: {
login: '/auth/login',
logout: '/auth/logout',
@SebbeJohansson
SebbeJohansson / StoryblokLiveEditorWithManualFetch.vue
Created October 21, 2022 14:18
Storyblok doesnt allow for Live Editor update on edit when doing a manual fetch without their functions, so this is how I handle it.
<script setup lang="ts">
import { StoryData } from '@storyblok/vue/dist';
const route = useRoute();
const isPreview = !!(route.query._storyblok && route.query._storyblok !== '');
const version = isPreview ? 'draft' : 'published';
const story = ref({} as StoryData);
@SebbeJohansson
SebbeJohansson / Text.vue
Created September 29, 2022 21:19
In-Line Storyblok block rendering for Nuxt3 with SSR and Prerendering
<script setup lang="ts">
import { Richtext } from 'storyblok-js-client';
const props = defineProps({ blok: Object });
const nuxtApp = useNuxtApp();
const textObject = { ...props.blok.text };
const nodes = [];
// Proof of concept for custom handling of inline blok nodes.
Object.entries(textObject.content).forEach(([key, node]) => {
if (node.type === 'blok') {
@SebbeJohansson
SebbeJohansson / GithubGistEmbed.vue
Created August 30, 2022 21:22
Nuxt3 Github Gist Embed component
<script setup lang="ts">
const props = defineProps({
gistId: {
type: String,
required: true,
},
file: {
type: String,
required: false,
default: '',
@SebbeJohansson
SebbeJohansson / StoryblokDateTimeField.js
Last active July 23, 2022 16:53
A storyblok datetime field with a default value for today.
const Fieldtype = {
template: `
<div>
<div class="image__wrap uk-margin-small-bottom">
<input type="datetime-local" id="date" name="date" v-model="model.date">
</div>
</div>
`,
mixins: [window.Storyblok.plugin],
methods: {