Skip to content

Instantly share code, notes, and snippets.

View konstantinmuenster's full-sized avatar
🙌

Konstantin Münster konstantinmuenster

🙌
View GitHub Profile
@konstantinmuenster
konstantinmuenster / Understanding-Async-Await-2.js
Created September 19, 2019 09:39
Understanding Async/Await - Resolved Example
const fetchData = async (url) => {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch(error) {
// Handle errors as needed
}
}
@konstantinmuenster
konstantinmuenster / Understanding-Async-Await.js
Last active September 19, 2019 19:13
Understanding Async/Await (Medium) - Example
const fetchData = async (url) => {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch(error) {
// Handle errors as needed
}
}
@konstantinmuenster
konstantinmuenster / gatsby-node.js
Created December 22, 2019 18:14
Example createRedirect for Netlify redirects
exports.createPages = ({ actions }) => {
const { createRedirect } = actions;
createRedirect({
fromPath: "https://yoursubdomain.netlify.com/*",
toPath: "https://www.yourcustomdomain.com/:splat",
isPermanent: true,
force: true
});
};
@konstantinmuenster
konstantinmuenster / _redirects
Last active December 23, 2019 11:19
Example Netlify Redirect
# Redirect default Netlify subdomain to primary domain
https://yoursubdomain.netlify.com/* https://www.yourcustomdomain.com/:splat 301!
@konstantinmuenster
konstantinmuenster / sw.fetch.js
Created January 24, 2020 15:23
Service Worker Rendering - Fetch Event
self.addEventListener('fetch', function(event) {
var requestURL = new URL(event.request.url);
if (/^\/post\//.test(requestURL.pathname)) {
event.respondWith(
Promise.all([
caches.match('/post/', {ignoreSearch: true}).then(function(response) {
return response.text();
}),
@konstantinmuenster
konstantinmuenster / sw.install.js
Created January 24, 2020 15:24
Service Worker Rendering - Install Event
importScripts('./js/handlebars.min.js');
importScripts('./templates/post.precompiled.js');
var CACHE_NAME = 'cache-v1';
var urlsToCache = [
'/',
'/templates/index.precompiled.js',
'/post/',
'/templates/post.precompiled.js',
'/css/style.css',
@konstantinmuenster
konstantinmuenster / index.js
Created May 24, 2020 14:37
index.js (1) - How To Gatsby Portfolio
import React from "react"
const IndexPage = () => {
return <h1>Hi there</h1>
}
export default IndexPage
@konstantinmuenster
konstantinmuenster / layout.js
Created May 24, 2020 17:12
layout.js (1) - How To Gatsby Portfolio
import React from "react"
import styled from "styled-components"
import GlobalStyle from "./globalStyle"
import Header from "./header"
import Footer from "./footer"
const StyledLayout = styled.div`
width: 100%;
min-height: 100vh;
@konstantinmuenster
konstantinmuenster / index.js
Created May 24, 2020 17:25
index.js (2) - How To Gatsby Portfolio
import React from "react"
import Layout from "../components/layout"
const IndexPage = () => {
return (
<Layout>
I am a good-looking page, right?
</Layout>
)
@konstantinmuenster
konstantinmuenster / hero.js
Created May 24, 2020 17:47
hero.js (1) - How To Gatsby Portfolio
import React from "react"
import styled from "styled-components"
const StyledSection = styled.section`
.title {
margin-bottom: 0;
}
.subtitle {
margin-top: 0;
}