From 8e1a1f588633381ac48f3f2940405b4c365f6f05 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 7 Aug 2023 11:12:45 -0300 Subject: [PATCH] aider: Add condition to convert non-raw GitHub gist URLs into raw URLs. # Aider chat conversation: USER: if the mdurl is a non-raw github gist like this `https://gist.github.com/paul-gauthier/2a4ac695b77f6374c923b0b165a6872b` pull out the hash and turn into a raw url like this: `https://gist.githubusercontent.com/paul-gauthier/2a4ac695b77f6374c923b0b165a6872b/raw/4fd2ac290d164100e51206fb6874e9ac20644fcd` ASSISTANT: To implement this change, we need to modify the `share/index.md` file. We will add a condition to check if the `mdurl` parameter is a non-raw GitHub gist URL. If it is, we will extract the gist ID and convert it into a raw URL. Here is the proposed change: ```markdown share/index.md <<<<<<< ORIGINAL var conv = urlParams.get('mdurl'); if (!conv) { return; } fetch(conv) ======= var conv = urlParams.get('mdurl'); if (!conv) { return; } // Check if the URL is a non-raw GitHub gist var gistRegex = /^https:\/\/gist\.github\.com\/[^\/]+\/([a-f0-9]+)$/; var match = gistRegex.exec(conv); if (match) { // If it is, convert it into a raw URL conv = 'https://gist.githubusercontent.com/' + match[1] + '/raw'; } fetch(conv) >>>>>>> UPDATED ``` This change adds a regular expression to match non-raw GitHub gist URLs. If the `mdurl` parameter matches this pattern, the gist ID is extracted and used to construct a raw URL. The fetch operation then uses this raw URL instead of the original URL. --- share/index.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/share/index.md b/share/index.md index 03784289c..c3776e1d5 100644 --- a/share/index.md +++ b/share/index.md @@ -15,6 +15,13 @@ window.onload = function() { if (!conv) { return; } + // Check if the URL is a non-raw GitHub gist + var gistRegex = /^https:\/\/gist\.github\.com\/[^\/]+\/([a-f0-9]+)$/; + var match = gistRegex.exec(conv); + if (match) { + // If it is, convert it into a raw URL + conv = 'https://gist.githubusercontent.com/' + match[1] + '/raw'; + } fetch(conv) .then(response => response.text()) .then(markdown => {