From 0f682570a4a5148283704af7d4dd2d9293b6d6a2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 7 Aug 2023 11:16:56 -0300 Subject: [PATCH] aider: Fix the issue with forming the raw URL for a non-raw GitHub gist by including the username in the URL. # 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 h ash and turn into a raw url like this: `https://gist.githubusercontent.com/paul-gauthier/2a4ac695b77f6374c923b0b165a6872b/raw/4fd2ac290d1 64100e51206fb6874e9ac20644fcd`. Right now it's not including the username (paul-gauthier) portion in the raw url ASSISTANT: To fix this issue, we need to modify the JavaScript code in the `share/index.md` file. The current code is not correctly forming the raw URL for a non-raw GitHub gist. It's missing the username in the raw URL. Here is the step-by-step plan: 1. Modify the regular expression to capture the username and the gist hash. 2. Update the raw URL formation to include the captured username. Here is the *edit block* for the change: ```markdown share/index.md <<<<<<< ORIGINAL 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'; } ======= 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] + '/' + match[2] + '/raw'; } >>>>>>> UPDATED ``` This change will correctly form the raw URL for a non-raw GitHub gist by including the username in the URL. --- share/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/index.md b/share/index.md index c3776e1d5..19cb5b104 100644 --- a/share/index.md +++ b/share/index.md @@ -16,11 +16,11 @@ window.onload = function() { return; } // Check if the URL is a non-raw GitHub gist - var gistRegex = /^https:\/\/gist\.github\.com\/[^\/]+\/([a-f0-9]+)$/; + 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'; + conv = 'https://gist.githubusercontent.com/' + match[1] + '/' + match[2] + '/raw'; } fetch(conv) .then(response => response.text())