avatarJerry Ng

Summary

The web content provides instructions on how to embed a specific file from a multi-file GitHub Gist into a Medium article.

Abstract

The article titled "How to Embed Single File From a Multiple Files Gist on Medium" offers a solution to a common issue faced by software developers when sharing code snippets on Medium. Typically, Medium attempts to display all files from a GitHub Gist when embedded, which is not ideal for multi-file Gists. The author outlines a method to embed only a single desired file by appending a query parameter to the Gist URL. This ensures that only the specified file, such as schema.py, is rendered in the Medium post, avoiding clutter and improving readability. The article also includes visual aids and concludes with final notes on the process, emphasizing the need to repaste the URL if changes are made to the Gist files. Additionally, the author promotes their other articles and an AI service called ZAI.chat.

Opinions

  • The author believes that embedding specific code files from a multi-file Gist is preferable to displaying all files, as it enhances the reader's experience.
  • Creating separate Gists for each file is seen as an inefficient solution that can lead to an unnecessary proliferation of Gists.
  • The author endorses the use of an AI service, ZAI.chat, as a cost-effective alternative to ChatGPT Plus (GPT-4), suggesting it offers similar performance and functionality.
  • The article implies that the described embedding technique is not widely known or is a workaround to Medium's default behavior when embedding Gists.

How to Embed Single File From a Multiple Files Gist on Medium

Tips on Embedding a Specific Code File From a Multi-Files Github Gist on Medium

Photo by Jess Bailey on Unsplash

As software developers, we often make use of GitHub Gist to instantly share our code snippets here on Medium, plus it looks amazing here.

How to Embed a GitHub Gist In Medium

Quick Steps

Copy and paste this in Medium to embed the code in your article
  1. Go to your Gist, copy the Gist path i.e.— https://gist.github.com/ngshiheng/d63434f91834c4d3d842358c210398ae from your browser
  2. Paste in your Medium article
  3. Hit ‘Enter’ on your keyboard
  4. Done. Your Gist will be embedded beautifully in your post

Problem

However, if you were to have a multiple file Gist, such as this, Medium will try to render all the files in the Gist in one go — which is not really what we wanted.

Previously, to render a single file, we would have to create separate Gist to do so, which is also not ideal as our account will be flooded in no time by the power of exponential.

Solution

Quick Steps

  1. Copy the multi-file Gist path, i.e. — https://gist.github.com/ngshiheng/d63434f91834c4d3d842358c210398ae from your browser
  2. Paste it somewhere else than the Medium article. Like in a search bar of a new tab in your browser or Notepad
  3. Append the query parameter for the file to the URL. i.e. — https://gist.github.com/ngshiheng/d63434f91834c4d3d842358c210398ae?file=schema.py , take note that ?file=schema.py at the end of the URL
  4. Paste the entire URL as an unformatted plain text back to Medium and hit ‘Enter’

Done. Simple as that.

Final Result

You should see that only the specified schema.py file is rendered here in this article rather than all the files.

Final Notes

  • Make sure you copy an unformatted plain text and paste it in Medium
  • If you were to make any changes in your Gist files, you will have to paste the URL in Medium again

Read my other articles at jerrynsh.com

Writing
Writing Tips
Github
Code
Writer
Recommended from ReadMedium