Skip to content

Instantly share code, notes, and snippets.

View rshackleton's full-sized avatar
🏠

Richard Shackleton rshackleton

🏠
View GitHub Profile
@rshackleton
rshackleton / gated-content.ts
Created March 3, 2021 21:54
Serverless function to load gated content
import dns from 'dns';
import { NextApiRequest, NextApiResponse } from 'next';
import { getGatedContentItem } from '../../lib/getGatedContentItem';
export default async function exit(req: NextApiRequest, res: NextApiResponse) {
// Handle potential Googlebot request.
const isGoogleAgent = req.headers?.['user-agent']?.toLowerCase()?.includes('googlebot') ?? false;
if (isGoogleAgent) {
let verified = false;
@rshackleton
rshackleton / index.tsx
Last active March 27, 2021 13:48
Next.js page with partial content
import { GetStaticProps } from 'next';
import { useRouter } from 'next/router';
import Head from 'next/head';
import React, { useEffect, useState } from 'react';
import { getGatedContentItem } from '../lib/getGatedContentItem';
export type ContentItemModel = {
date: string;
freeContent: string;
gatedContent: string;
@rshackleton
rshackleton / Layout.jsx
Created August 22, 2020 11:04
Smart Link SDK with Gatsby
import KontentSmartLink from '@kentico/kontent-smart-link';
import '@kentico/kontent-smart-link/dist/kontent-smart-link.styles.css';
export default function Layout({ children }) {
useEffect(() => {
const kontentSmartLink = KontentSmartLink.initialize({
queryParam: 'preview-mode'
});
return () => {
kontentSmartLink.destroy();
@rshackleton
rshackleton / Crash_2020_6_6_15-48-37.txt
Created June 6, 2020 14:51
Crash_2020_6_6_15-48-37.txt
Unhandled native exception occurred at 0x7FF6CEBE72DF (SkyrimSE.exe+C072DF) on thread 6716!
FrameworkName: NetScriptFramework
FrameworkVersion: 9
FrameworkArchitecture: x64
GameLibrary: SkyrimSE
GameLibraryVersion: 13
ApplicationName: SkyrimSE.exe
ApplicationVersion: 1.5.97.0
VersionInfo: Successfully loaded
@rshackleton
rshackleton / preview.ts
Created May 11, 2020 11:57
Handle a preview request with next.js
import { NextApiRequest, NextApiResponse } from 'next';
import ArticleService from '../../services/ArticleService';
export default async (req: NextApiRequest, res: NextApiResponse) => {
// Validate the incoming request.
if (req.query.secret !== process.env.PREVIEW_TOKEN) {
return res.status(401).json({ message: 'Invalid token' });
}
@rshackleton
rshackleton / article.tsx
Last active May 11, 2020 12:05
Get preview content with next.js
/**
* Execute server-side data fetching.
*/
export const getStaticProps: GetStaticProps = async ({ params, preview }) => {
console.log(`Loading article content, preview mode is ${!!preview}`);
const slug = params?.slug as string;
const service = new ArticleService(preview ?? false);
const article = await service.getArticle(slug);