<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Richard Shackleton on Medium]]></title>
        <description><![CDATA[Stories by Richard Shackleton on Medium]]></description>
        <link>https://medium.com/@rshackleton?source=rss-d9b8321b0085------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*W1ADfVtbYcKHQxu_q7PEhA.jpeg</url>
            <title>Stories by Richard Shackleton on Medium</title>
            <link>https://medium.com/@rshackleton?source=rss-d9b8321b0085------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 07:14:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rshackleton/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Gated content and the Jamstack. Is it achievable? Of course!]]></title>
            <link>https://medium.com/front-end-weekly/gated-content-and-the-jamstack-is-it-achievable-of-course-6408f1ccf7e8?source=rss-d9b8321b0085------2</link>
            <guid isPermaLink="false">https://medium.com/p/6408f1ccf7e8</guid>
            <category><![CDATA[jamstack]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[headless-cms]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Richard Shackleton]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 19:44:41 GMT</pubDate>
            <atom:updated>2021-03-29T19:44:41.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEgHxHzK6Nc3YGJG2wUodg.png" /></figure><p>Something we often hear in regards to Jamstack is the notion that “a static site cannot do <em>that</em>”. However, the nature of the Jamstack is to statically-generate websites, not to generate static websites.</p><p>Recently, I needed to provide an example of functionality that is often viewed as impossible with a statically-generated website — gated content. I was sure that this was something we could achieve using Jamstack but there weren’t any resources around how to implement this, recommended approaches or even best practices. The closest articles I found were orientated towards marketers, selling the effectiveness of gated content for conversions.</p><p>So, here is an article that is developer-focused, provides a recommended approach, is accompanied by a working example, and includes best practices outlined by Google for paywalled content.</p><p><em>If you want to jump straight to the point then you can find links to the working example and source code at the end of the article.</em></p><h3>What is gated content?</h3><p>First things first, a <em>gate </em>is a step or barrier between a user and something they wish to access. A common example is an age-gate, often used when a user wishes to access products or content that require them to be older than a specific age e.g. for purchasing alcohol.</p><p>In our case we are referring to content gating; typically used in lead generation. The intention is that a report or article is enticing enough for a user to provide contact details.</p><p>A gate requires some things to be true to function correctly.</p><ol><li>A user can complete an exchange; for example by providing contact details or signing up for a subscription.</li><li>A user will receive something as part of the exchange; for example, a report or article.</li><li>The platform, or website, can restrict access to this content until the user completes the exchange.</li></ol><p>These requirements are often expected to be problematic for a statically generated website as the content would be generated upfront and therefore cannot be served to the user dynamically when they complete the exchange.</p><p>However, this is not true!</p><p>With the modern web, we can serve partial content upfront and retrieve the desired content using JavaScript dynamically and insert it into the DOM to allow the user to read the article or report.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>What do we need to implement gated content?</h3><p>Ok, so we have covered off what gated content is, what will we need to implement it? The approach I am going to outline will make use of the following frameworks and platforms.</p><ul><li><a href="https://nextjs.org/">Next.js</a></li><li><a href="https://vercel.com/">Vercel</a></li><li><a href="https://kontent.ai/">Kentico Kontent</a></li></ul><p>These can be swapped out for your preferred option but the following needs to be considered.</p><p>Firstly, we need a Jamstack framework that allows us to generate pages with partial content upfront, and then allow us to modify the DOM to add our dynamic content later on. This can be done with any Jamstack framework, the key is using JavaScript to fetch data and to modify the DOM.</p><p>Secondly, we need a platform that will provide us with somewhere to do some server-side logic. In this example case, we’re using serverless functions on Vercel, but this approach works just as well when using Netlify or a separate platform like AWS Lambda or Azure Functions.</p><p>Finally, we need a platform to store and deliver our gated content. In this example, we’re using Kentico Kontent to manage our content and provide access via their Delivery API and JavaScript SDK.</p><p>There are additional platforms and services which may come into effect depending on what your gate needs to do. For example, you may need to store an email address in MailChimp or complete a transaction using Stripe. In this example, we’re keeping it as simple as possible and checking the user has entered a value in a field.</p><h3>How do we implement gated content?</h3><p>Time for the real meat of the article, how do we implement this?</p><p>Firstly, we need a page that includes the call-to-action for the user to access the gated content. It is often recommended to also include a snippet of the content if possible.</p><p>The following example is the complete page source code from <a href="https://nextjs-gated-content.vercel.app/">the demo.</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f13b42d5526cd803c690029b39b67f20/href">https://medium.com/media/f13b42d5526cd803c690029b39b67f20/href</a></iframe><p>We’re doing a lot here so let’s break things down.</p><p>The first takeaway from this file is that <a href="https://gist.github.com/rshackleton/d776a18fd79ef6a83d55189b2dc5cce1#file-index-tsx-L78">it includes some lead content</a>, this is a specific field in Kentico Kontent which allows a content editor to provide an enticing snippet of the gated content.</p><p>The second takeaway is the API call to retrieve the content from our serverless function. This call is executed under two scenarios.</p><ol><li><a href="https://gist.github.com/rshackleton/d776a18fd79ef6a83d55189b2dc5cce1#file-index-tsx-L81">If a user enters a value into the form and clicks submit.</a></li><li><a href="https://gist.github.com/rshackleton/d776a18fd79ef6a83d55189b2dc5cce1#file-index-tsx-L49">If we believe the incoming request is from Googlebot.</a></li></ol><p>The second scenario is important if we want our full content to be indexed, we will cover this in detail later in the article.</p><p>The third takeaway is the structured data we output. <a href="https://gist.github.com/rshackleton/d776a18fd79ef6a83d55189b2dc5cce1#file-index-tsx-L190">This includes two properties</a> for Google to understand that our content is gated.</p><p>Ok, so we have our page set up to display our lead content and the form, and also to request the full content if a request comes in from Google. Next, we need to take a look at the serverless function and how it works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/899ca920f45592fdf4efa796aefd3fe2/href">https://medium.com/media/899ca920f45592fdf4efa796aefd3fe2/href</a></iframe><p>First of all, we validate whether the incoming request is from Google with a reverse DNS lookup. If this passes then we return the gated content immediately so that Google can index it.</p><p>Next, we validate the incoming data to see if the user has provided us with the required information. Here you could complete a payment, subscribe them to a newsletter, etc. In our case we’re just checking the value was provided.</p><p>Finally, if the incoming data is valid we can return the gated content!</p><h3>What does Google say?</h3><p>The final step is to validate the page using the Google Search Console. The tool allows us to submit a URL to be crawled and checked by Google to ensure there are no issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSt-nVGVBF_63wZ8ZEtqBg.png" /><figcaption>Google can see our gated content! 🧐</figcaption></figure><p>I hope that this article has helped dispel the myth that you cannot implement functionality such as gated content with the Jamstack. A link to the demo and source code is located in the resources below.</p><p>If you’re interested in trying this out for yourself, you can also sign up for an extended trial of Kontent using the link below.</p><h3>Resources</h3><ul><li><a href="https://nextjs-gated-content.vercel.app/">Demo using Next.js on Vercel</a></li><li><a href="https://github.com/rshackleton/nextjs-gated-content">Source code for the demo</a></li><li><a href="https://kontent.ai/?utm_source=create_a_better_headless_preview_experience_with_web_spotlight_from_kentico_kontent&amp;utm_medium=mvp_379238&amp;utm_campaign=extended_trial">Check out Kentico Kontent with an extended trial</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6408f1ccf7e8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/gated-content-and-the-jamstack-is-it-achievable-of-course-6408f1ccf7e8">Gated content and the Jamstack. Is it achievable? Of course!</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create amazing scroll-based animations with GSAP ScrollTrigger and Framer Motion]]></title>
            <link>https://medium.com/front-end-weekly/how-to-create-amazing-scroll-based-animations-with-gsap-scrolltrigger-and-framer-motion-c17482ab3f4?source=rss-d9b8321b0085------2</link>
            <guid isPermaLink="false">https://medium.com/p/c17482ab3f4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[gsap]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[framer-motion]]></category>
            <dc:creator><![CDATA[Richard Shackleton]]></dc:creator>
            <pubDate>Thu, 25 Feb 2021 18:43:58 GMT</pubDate>
            <atom:updated>2021-02-25T18:43:58.471Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Utj4iAFFhgBUMA1qQKGcA.png" /><figcaption>Ok, so this looks simple… But check out the demo to see how smooth it feels! 🔥</figcaption></figure><p>When it comes to animation in React we really are spoiled for choice.</p><p>However, when looking for a simple way to handle scroll-based animations, specifically those which can be scrubbed through, there didn’t seem to be anything that would work out of the box.</p><p>In June 2020, GSAP released a new plugin called <a href="https://greensock.com/scrolltrigger/">ScrollTrigger</a> which can be considered a modern version of the old ScrollMagic library.</p><p>Here we will look into how to combine ScrollTrigger with my preferred React animation library, <a href="https://www.framer.com/motion/">Framer Motion</a>.</p><p><strong><em>TL;DR</em></strong><em> — There is a working CodeSandbox link at the end of the article if you just want to dive into the implementation yourself.</em></p><p><strong>Otherwise, let’s get started!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><p>First of all, we need to bring in our dependencies, GSAP and Framer Motion. They can both be found on NPM and installed with the following command:</p><pre>npm install framer-motion gsap</pre><p>Once we have those dependencies installed we’re ready to dive into setting up or ScrollTrigger instance.</p><p>There are a couple of ways we could approach this, my preference was to use a provider component and React context to expose the “progress” of the ScrollTrigger instance.</p><p>I like this as the code is abstracted away and it also takes care of the container element. We could use a React hook for this too, but we’d then need to handle assigning the element ref in all of our consumer components.</p><p>So firstly we need to create a new React context instance and an accompanying hook to allow our child components to consume it. I’m opting to use TypeScript here so we also define the context type as MotionValue — we’ll cover this later.</p><pre>const ScrollTriggerContext = React.createContext&lt;MotionValue&gt;(null);</pre><pre>const useScrollTrigger = () =&gt; useContext(ScrollTriggerContext);</pre><p>Now we need to create the provider component itself. This component will handle creating the ScrollTrigger instance.</p><p>We need to create two refs to provide a reference to the container element and also to store the GSAP Timeline instance. We’ll use the latter to handle clean-up if the component is unmounted.</p><pre>const refScrollTrigger = useRef&lt;HTMLDivElement&gt;(null);</pre><pre>const refTimeline = useRef&lt;gsap.core.Timeline&gt;();</pre><p>To integrate GSAP with Framer Motion we will also make use of the useMotionValue hook. This is an optimised, animatable value that Framer Motion can make use of.</p><pre>const progress = useMotionValue(0);</pre><p>The next step is to register the ScrollTrigger plugin with GSAP and then create a new Timeline instance with ScrollTrigger enabled. We pass our ref as the trigger element and include an onUpdate callback to update the progress motion value.</p><pre>useLayoutEffect(() =&gt; {</pre><pre>  gsap.registerPlugin(ScrollTrigger);</pre><pre>  if (refScrollTrigger.current) {</pre><pre>    refTimeline.current = gsap.timeline({</pre><pre>      scrollTrigger: {</pre><pre>        ...DEFAULT_OPTIONS,</pre><pre>        ...options,</pre><pre>        markers: debug,</pre><pre>        trigger: refScrollTrigger.current,</pre><pre>        onUpdate: (instance) =&gt; {</pre><pre>          progress.set(clamp(instance.progress, 0, 1));</pre><pre>        },</pre><pre>      },</pre><pre>    });</pre><pre>  }</pre><pre>  return () =&gt; {</pre><pre><em>    // Kill and clear the timeline and scrolltrigger instance when updated/unmounted.</em></pre><pre>    refTimeline.current?.scrollTrigger?.kill();</pre><pre>      refTimeline.current?.kill();</pre><pre>      refTimeline.current?.clear();</pre><pre>    };</pre><pre>}, [debug, options, progress]);</pre><p>Finally, we need to wrap the children in a div element with our ref.</p><pre>return (</pre><pre>  &lt;div ref={refScrollTrigger}&gt;</pre><pre>    &lt;ScrollTriggerContext.Provider value={progress}&gt;{children}&lt;/ScrollTriggerContext.Provider&gt;</pre><pre>  &lt;/div&gt;</pre><pre>);</pre><p>Ok. This is all of our setup for the provider component. You can see the complete provider code in the CodeSandbox at the end of the article.</p><p>Let’s move onto the consumer!</p><p>Fortunately this one is much shorter and simpler than our provider component. Here is the entire component, we’ll go through step-by-step afterwards.</p><pre>export type ScreenProps = {</pre><pre>  fadeIn?: boolean;</pre><pre>  title: string;</pre><pre>};</pre><pre>const Screen: React.FC&lt;ScreenProps&gt; = ({ fadeIn = true, title }) =&gt; {</pre><pre>  const progress = useScrollTrigger();</pre><pre><em>  // Fade background from start to finish.</em></pre><pre>  const bg = useTransform(progress, [0, 1], [&#39;#333399&#39;, &#39;#663399&#39;]);</pre><pre><em>  // Fade title in halfway and out at the end.</em></pre><pre>  const titleOpacity = useTransform(progress, [0, 0.5, 1], fadeIn ? [0, 1, 0] : [1, 1, 0]);</pre><pre>  return (</pre><pre>    &lt;motion.div className=&quot;screen&quot; style={{ backgroundColor: bg }}&gt;</pre><pre>      &lt;motion.h2 style={{ opacity: titleOpacity }}&gt;{title}&lt;/motion.h2&gt;</pre><pre>    &lt;/motion.div&gt;</pre><pre>  );</pre><pre>};</pre><p>We use the context hook from earlier to access our progress motion value.</p><pre>const progress = useScrollTrigger();</pre><p>We know that the value of this will be between 0 and 1, with 0 being the very start of the scroll animation and 1 being the very end. This allows us to make use of Framer Motion’s useTransform hook to transform our progress value to another value, such as a colour, based on the min/max range.</p><pre>const bg = useTransform(progress, [0, 1], [&#39;#333399&#39;, &#39;#663399&#39;]);</pre><p>Finally, we can use the transformed value in our “motion components” to change it’s styles as the user scrolls.</p><pre>&lt;motion.div className=&quot;screen&quot; style={{ backgroundColor: bg }}&gt;<br>  ...<br>&lt;/motion.div&gt;</pre><p>That is all there is to it! We now have the background of our section changing colour as the user scrolls. This same technique can be applied in various ways such as adjust opacity, using transform to create parallax effects, or even animating SVGs to indicate scroll progress!</p><p>Here is the final CodeSandbox as promised — I hope this helps you create some wonderful eye-catching animations! 🙏</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fhf1lw&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fhf1lw&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fhf1lw%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/a03241ddcc4e1868e4096eaa01db59a6/href">https://medium.com/media/a03241ddcc4e1868e4096eaa01db59a6/href</a></iframe><h3>Resources</h3><ul><li><a href="https://codesandbox.io/s/framer-motion-gsap-scrolltrigger-hf1lw">Working demo on CodeSandbox</a></li><li><a href="https://www.framer.com/motion/">Framer Motion</a></li><li><a href="https://greensock.com/scrolltrigger/">GSAP ScrollTrigger</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c17482ab3f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/how-to-create-amazing-scroll-based-animations-with-gsap-scrolltrigger-and-framer-motion-c17482ab3f4">How to create amazing scroll-based animations with GSAP ScrollTrigger and Framer Motion</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better headless preview experience with Web Spotlight]]></title>
            <link>https://medium.com/front-end-weekly/better-headless-preview-experience-with-web-spotlight-2d45d2ac87fa?source=rss-d9b8321b0085------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d45d2ac87fa</guid>
            <category><![CDATA[cms]]></category>
            <category><![CDATA[headless-cms]]></category>
            <category><![CDATA[static-site-generator]]></category>
            <category><![CDATA[kentico-kontent]]></category>
            <category><![CDATA[content-writing]]></category>
            <dc:creator><![CDATA[Richard Shackleton]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 15:48:13 GMT</pubDate>
            <atom:updated>2020-09-01T15:48:13.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRimJ-zuScgvVbMd5iQJag.png" /></figure><p>Developers like headless CMSs for their flexibility, but content editors are often complaining about missing WYSIWYG capabilities.</p><p>How can we better integrate the website front-end with headless CMS to improve the experience of content editors? After all, ensuring a good content editing experience allows us to keep working with the headless CMS we like.</p><p>In this article, we will review the common drawbacks of headless CMS previews, the benefits of the new feature called Web Spotlight that enables live content editing experience, and a showcase of how to enable and use it.</p><h4>What are the drawbacks of headless CMS previews?</h4><p>The most common approach to a preview mode within a headless CMS is to simply open a URL in a new window. This is the absolute bare minimum and hardly even counts as functional. Opening a preview URL could be done manually by the content editor, the “feature” is simply a <em>shortcut</em>.</p><p>This separation of content editing and content preview leads to a very frustrating experience for content editors. They hate:</p><ul><li>Navigating the website and content repository independently.</li><li>The mental overhead of understanding the abstract content structure often used while working with a headless CMS.</li></ul><p>Whilst I know we developers have our own problems, but ensuring a good content editing experience allows us to keep working with the headless CMS we like.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h4>What is Web Spotlight and how does it help?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pMzepCaDQqtqxcWJwAHYtQ.png" /></figure><p>Web Spotlight is a new addition to Kentico Kontent which lets you create web pages and see them right in your editor, providing immediate visual feedback.</p><p>It achieves this by enabling these features:</p><ul><li>Navigate the hierarchy of a website via the content tree</li><li>Manipulate the website hierarchy via the content tree</li><li>Preview changes via an embedded preview window</li><li>Live-edit pages from the embedded preview window</li></ul><p>This allows us to combine the editing and preview experiences within the same interface with only small adjustments on the implementation side.</p><h4>How do I try out Web Spotlight?</h4><p>First of all, you must purchase the Web Spotlight add on via the Kentico Kontent support team or your account manager.</p><p>Then, you will be able to access a new section via the main navigation. The globe icon will open the Web Spotlight section, and you will be greeted with a modal explaining the first steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*yNEPPa3I5zh8ZVUBYybnZA.png" /><figcaption>The new Globe icon will direct you to Web Spotlight 🌍</figcaption></figure><p>Firstly, you will need to initialise the new feature by clicking the button in the modal. This will make the following changes to your project:</p><ol><li>Create a new Homepage content model</li><li>Create a new Page content model</li><li>Allow usage of the new Subpages element type</li></ol><p>The new homepage content model is the root of your new content tree. You need to adjust it with any additional fields your project needs and create a root content item based on it.</p><p>The new page content model is optional, this can be used to represent a standard page on your website. However, if you already have an existing content model then you can update that instead.</p><p>To update an existing content model to work with the content tree, you will need to use the new Subpages element type. This can be added to a content model in the same way as any other fields. I’d recommend naming the new field “Subpages” to keep consistent with the new homepage model.</p><figure><img alt="A screenshot of the Article Listing content model with a subpages field" src="https://cdn-images-1.medium.com/max/1020/1*vPIoJ2XbP2X3sGwF5WYrxw.png" /><figcaption>Add the new Subpages element to all content models that should support child pages.</figcaption></figure><p>After you have updated your content models and created a new homepage content item you can begin using the Web Spotlight content tree. This new view of your content will allow you to visualise your website structure and interact with it by moving existing items around or creating new subpages directly from the parent.</p><p>That is great, but it’s hardly ground-breaking in isolation. The structure the new subpages element represents was already achievable using the linked pages element type and the content tree is a handy visualisation for content editors. The true power of Web Spotlight comes from the new <strong>Embedded Preview</strong> and the <strong>Smart Link SDK</strong>.</p><h4>Turn on the Embedded Preview</h4><p>Embedded Preview is the approach Kontent takes to include your website directly in their headless CMS. This is done using a combination of preview links and an iframe.</p><p>To enable the embedded preview you will need to set up preview links in your project settings. The URL can include placeholders to include the URL slug or language codename as required.</p><figure><img alt="An example of Preview Links in Kentico Kontent" src="https://cdn-images-1.medium.com/max/974/1*ELdNyIxt-BBZKj4EJZiqPg.png" /><figcaption>You can enable content preview for each content model by specifying it’s own link template.</figcaption></figure><p>The generated URL will be loaded in an iframe within the Kontent interface to make the preview experience more seamless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOGYvinsSJpM3YO1lirGAQ.png" /><figcaption>The new seamless embedded preview 🎉</figcaption></figure><p><strong>Tip:</strong> Ensure you have the appropriate <strong>X-Frame-Options</strong> and <strong>Content-Security-Policy</strong> headers configured for your website, otherwise the embedded preview will not load.</p><pre>Content-Security-Policy: frame-ancestors https://app.kontent.ai</pre><p>Now, whilst you can already benefit from the embedded preview window, the final step is to enable editable elements via the <strong>Smart Link SDK</strong>.</p><h4>Add Smart Links</h4><p>The Smart Link SDK is a package provide by Kentico Kontent to enable shortcuts on your preview window. These shortcuts will allow your editors to edit content without leaving the Web Spotlight interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*xL5d8WGhNsrGNbw021IsKg.png" /><figcaption>A Smart Link allows direct access to edit content from the preview window.</figcaption></figure><p>This will require making changes to the output HTML of your website, meaning this is compatible with all platforms and frameworks. The website I used as an example was developed using Gatsby and the setup is outlined in the <a href="https://www.npmjs.com/package/@kentico/kontent-smart-link#gatsby">Smark Link SDK readme</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/484f674fb005f48a33814c52b52c1f5f/href">https://medium.com/media/484f674fb005f48a33814c52b52c1f5f/href</a></iframe><p>Once this has been included in your website you can <a href="https://www.npmjs.com/package/@kentico/kontent-smart-link#data-attributes">annotate the pages and elements</a> to link them to your content items. This is done using a series of data attributes.</p><p>Firstly, you need to annotate your body element with the Project ID and Language Codename.</p><p>Secondly, you need to annotate an element with the Content Item ID it is associated with. For example, if the entire content of a page is managed through a single content item then it would be logical to include the data attribute at the highest level. Alternatively, if a particular section of a page is managed using a particular content item then that section should include the data attribute.</p><p>Finally, you can also annotate elements with the Element Codename, this will allow Kontent to pre-select the appropriate field when the element is clicked, for example allowing a title or summary to be selected directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cslagwzxyKhOBsLbIHXQGw.png" /></figure><p>Once you have annotated your mark-up with the appropriate data attributes you should be able to enable <strong>Show editable elements</strong> in Kontent and see areas highlighted in the preview window.</p><p>I implemented Web Spotlight in my blog during a live stream, check out the <a href="https://youtu.be/VYGbdFLcJXI">recording on YouTube</a> or try it out for yourself in <a href="https://kontent.ai/?utm_source=create_a_better_headless_preview_experience_with_web_spotlight_from_kentico_kontent&amp;utm_medium=mvp_379238&amp;utm_campaign=extended_trial">Kontent</a>.</p><h4>Resources</h4><ul><li><a href="https://webspotlight.kontent.ai/">Web Spotlight feature highlight</a></li><li><a href="https://docs.kontent.ai/tutorials/set-up-kontent/set-up-your-project/web-spotlight">Web Spotlight documentation</a></li><li><a href="https://dev.to/meandmyrobot/headless-cms-just-isn-t-good-enough-26a6">Michael Kinkaid’s run-down of why we deserve a better content preview</a></li><li><a href="https://kontent.ai/?utm_source=create_a_better_headless_preview_experience_with_web_spotlight_from_kentico_kontent&amp;utm_medium=mvp_379238&amp;utm_campaign=extended_trial">Check out Kentico Kontent with an extended trial</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d45d2ac87fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/better-headless-preview-experience-with-web-spotlight-2d45d2ac87fa">Better headless preview experience with Web Spotlight</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving content preview with Next.js Preview Mode]]></title>
            <link>https://medium.com/front-end-weekly/solving-content-preview-with-next-js-preview-mode-5f628f55d07a?source=rss-d9b8321b0085------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f628f55d07a</guid>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[jamstack]]></category>
            <category><![CDATA[kentico]]></category>
            <category><![CDATA[headless]]></category>
            <dc:creator><![CDATA[Richard Shackleton]]></dc:creator>
            <pubDate>Mon, 11 May 2020 12:04:51 GMT</pubDate>
            <atom:updated>2020-05-18T17:57:17.055Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSUuG0Whar_EscE584Q2xA.jpeg" /></figure><p>In this article I will explain why live previews are important for content editors’ experience and why are they such an issue these days. I’ll introduce Next.js, compare it with Gatsby, and share my experience working with both.</p><h3>Why is content preview so important?</h3><p>Content preview is the ability to view the unpublished, draft content created in a CMS within the context of your website design. Content editors and clients expect this functionality as standard. Why? Because all mainstream CMS products include a preview feature out of the box!</p><p>Asking a content editor to “trust” the website to display their content correctly is asking them to take a leap of faith. Whilst we know (or hope) that the website will render their content correctly, there is always the chance a bug could creep through, or the alignment of this content could be slightly incorrect.</p><p>Enabling content preview simply provides a level of confidence and security in a content editor’s workflow. Plus, we all know it’s a much easier conversation to fix a rendering bug in a preview environment <strong>before </strong>it hits the production environment!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>Why can preview be so complicated with JAMstack?</h3><p>The fact that headless CMS doesn’t use the traditional WYSIWYG editing experience editors have come to expect is by design. A headless CMS often contains content for multiple channels, therefore providing a visual representation within the confines of the CMS itself could introduce bias or be misleading for non-web channels.</p><p>Therefore, it is the responsibility of the website to allow draft content to be displayed for preview purposes. Unfortunately, for most Static Site Generators (SSGs) this requires the entire website to rebuilt with the draft content. As the number of content items increases, the build time for these sites could easily be several minutes. Content editors will not wish to wait that long to preview their content!</p><h3>Why use JAMstack, let’s just use a dynamic website. Right?</h3><p>A dynamically rendered website can easily handle rendering published content and draft content based on a toggle, such as via a query string value or a cookie. The draft content is retrieved on-demand, bypassing caches, and therefore provides a synchronous on-demand preview experience.</p><p>A static website cannot achieve this, even with an incremental build approach the preview experience is still an asynchronous process. If the build has not been completed before a content editor “previews” their content they will see stale data.</p><p>Conversely, a dynamically rendered website often cannot achieve the same level of performance as a static website. The content needs to be retrieved on-demand, hopefully from a cache, the output HTML needs to be generated and then served to the user. Even when cached this will include a degree of latency when compared to a static website served from a CDN.</p><p>Furthermore, optimisations like serving only the CSS and JS code needed to render the page and including offline support can be much trickier with a dynamic website.</p><p>Ok, so we want the benefits of on-demand preview but without compromising performance. Well, fortunately, we can use a hybrid approach.</p><h3>A hybrid approach is a solution</h3><p>What do we mean by a hybrid approach? Usually, we must choose between static generation (SSG) or server-side rendering (SSR). A hybrid solution supports both options on a per-page basis. We can use the server-side rendering approach to handle our on-demand previews but generate static pages at build time to produce optimised pages we can serve from a CDN.</p><p>Another advantage of a hybrid solution is the ability to use the same codebase to render both the SSG and SSR versions of a page. No duplicating code to handle both use-cases!</p><h3>Introducing Next.js</h3><p>So, the framework of choice for a hybrid solution is Next.js from Vercel (previously Zeit). Next.js is a zero-configuration framework for developing dynamic React applications; no more worrying about the complex configurations and plugins typically involved in supporting server-side rendering.</p><p>Next.js runs on any NodeJS server, although they often use their own Now service in examples. You can easily run the framework on your hardware, with your preferred cloud provider or with an integrated platform such as Now.</p><p>Most importantly, the recent 9.3 release introduced static site generation support and a powerful Preview Mode API. This allows us to achieve the holy grail of generating static versions of our pages whilst supporting on-demand previews!</p><h3>Next.js vs Gatsby</h3><p>GatsbyJS is one of the most popular static-site generators currently available. It provides a great developer experience, produces optimised static assets and has a suite of plugins available to streamline the development process.</p><p>However, Gatsby is 100% static only. Gatsby does provide a content preview option, but I find it to be far from perfect and it does not provide an <strong>on-demand</strong> preview.</p><p>Some of the key issues or concerns are:</p><ul><li>Using Gatsby Cloud’s content preview requires the “Real-time edit” feature, this is rate-limited to 25/day on their free tier or 3000/month on their Professional tier. For content-heavy websites, this can be restrictive.</li><li>Their content preview supports “first-class plugins” only, therefore not all data sources are supported.</li><li>It is possible to host your own preview mode by running your Gatsby site in dev mode (using gatsby develop) with the refresh endpoint enabled. However, this means hosting another instance of your website on a NodeJS server which is more hosting overhead.</li></ul><p>So, what happens if you’ve built a site using Gatsby and wish to migrate over to Next.js? Well, this is a relatively smooth process. First, you can migrate over your React components without significant changes as the presentational side of the React development is largely the same.</p><p>Some components provided by Gatsby such as the Link component would need to be replaced with Link component from Next.js and React Helmet would be replaced by the Head component.</p><p>The main difference is in data management and retrieval. Gatsby provides all data in the GraphQL schema via source plugins whereas Next.js expects you to source your content in the <strong>getStaticProps </strong>or <strong>getServerSideProps </strong>APIs.</p><h3>How do we enable Preview Mode in Next.js?</h3><p>The process is well explained by the Next.js documentation but here is the approach I’ve taken to connect Preview Mode to a Kentico Kontent instance.</p><p>First, you will need to create a page template in Next.js which uses content from your preferred provider.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ab5c8834d57bf912f3817c266a8fe3e/href">https://medium.com/media/2ab5c8834d57bf912f3817c266a8fe3e/href</a></iframe><p>In this case, I am fetching content with the Kentico Kontent SDK. The SDK provides the option to request content via their live or preview API. The <strong>getStaticProps</strong> export provides a boolean value indicating whether the current request should return live or preview content. This boolean value is passed through to the Kontent SDK.</p><p>Our template is now set up to support preview mode. 🎉</p><p>Ok, so the last step is a little more involved. Depending on your CMS you will need to define the preview URL for your content items. With Kontent this is done in the project configuration for each content model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*lQ30pYKPWFXMR0jeXCu0KA.png" /></figure><p>The URL is defined by a template with the URL slug and language being inserted as variables — e.g. {URLslug} above. You will want to point your preview URL to the path <strong>/api/preview.</strong> Now we can write the code that will handle that request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/294f8a0b72dacb813c8708ae59f3f4cc/href">https://medium.com/media/294f8a0b72dacb813c8708ae59f3f4cc/href</a></iframe><p>Firstly, we check the <strong>secret</strong> parameter to ensure this request is coming from a trusted source and that we have a valid slug value. Next, we check the type of the content item — this was a hard-coded value in the URL template. If we determine that a valid content item exists for the slug and content type then we will receive a new location value. Finally, we enable preview mode with the Next.js API and trigger a redirect to the correct URL.</p><p>The status is stored in a session cookie so all content will be loaded in preview mode until the current session has ended, or cookies have been cleared.</p><p>So we now have a working content preview thanks to Next.js Preview Mode!</p><h3>Resources</h3><p>Check the following links for documentation and further information on Next.js and Kentico Kontent:</p><ul><li><a href="https://nextjs.org/">Next.js home page</a></li><li><a href="https://nextjs.org/docs/advanced-features/preview-mode">Next.js Preview Mode documentation</a></li><li><a href="https://kontent.ai/?utm_source=solving-content-preview-with-next-js-preview-mode&amp;utm_medium=mvp_379238&amp;utm_campaign=extended_trial">Kentico Kontent</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f628f55d07a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/solving-content-preview-with-next-js-preview-mode-5f628f55d07a">Solving content preview with Next.js Preview Mode</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>