Commit graph

12 commits

Author SHA1 Message Date
Paul Gauthier
097a9ebf20 aider: The JavaScript code now adds the mdurl as an href on the <a> tag.
# Aider chat conversation:

USER: have the js add the mdurl as an href on the <a>

ASSISTANT: To add the `mdurl` as an `href` on the `<a>` tag, we need to modify the `share/index.md` file.

Here are the steps:

1. Find the `<a>` tag that we want to modify.
2. Add a JavaScript code snippet that will get the `mdurl` from the URL parameters and set it as the `href` of the `<a>` tag.

Here is the *edit block* for the change:

<source>markdown
share/index.md
<<<<<<< HEAD
A user has shared the following transcript of a pair programming chat session
created using <a href="https://aider.chat">aider</a>.
=======
A user has shared the following
^C KeyboardInterrupt

USER: have the js add the mdurl as an href on the <a>

ASSISTANT: To add the `mdurl` as an `href` on the `<a>` tag, we need to modify the `share/index.md` file.

Here are the steps:

1. Find the `<a>` tag that we want to modify.
2. Add a JavaScript code snippet that will get the `mdurl` from the URL parameters and set it as the `href` of the `<a>` tag.

Here is the *edit block* for the change:

<source>markdown
share/index.md
<<<<<<< HEAD
The transcript is based on <a id="mdurl">this chat transcript data</a>.
=======
The transcript is based on <a id="mdurl" href="">this chat transcript data</a>.
>>>>>>> updated
</source>

<source>javascript
share/index.md
<<<<<<< HEAD
    var conv = urlParams.get('mdurl');
    if (!conv) {
        return;
    }
=======
    var conv = urlParams.get('mdurl');
    if (!conv) {
        return;
    }
    document.getElementById('mdurl').href = conv;
>>>>>>> updated
</source>
2023-08-14 14:40:47 -03:00
Paul Gauthier
bc908da360 copy 2023-08-10 22:36:58 -03:00
Paul Gauthier
94e5aeac62 copy 2023-08-07 13:00:21 -03:00
Paul Gauthier
b12899f8f3 copy 2023-08-07 11:35:20 -03:00
Paul Gauthier
14c683bfdf more specific selector 2023-08-07 11:33:06 -03:00
Paul Gauthier
68f043bd96 copy 2023-08-07 11:30:22 -03:00
Paul Gauthier
0f682570a4 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: `4fd2ac290d
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.
2023-08-07 11:16:56 -03:00
Paul Gauthier
8e1a1f5886 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: `4fd2ac290d`

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.
2023-08-07 11:12:45 -03:00
Paul Gauthier
7aed0438fe aider: If the fetch fails, skip the rest.
# Aider chat conversation:

USER: if the fetch fails, skip the rest

ASSISTANT: To handle fetch failures, we need to modify the `share/index.md` file. We will add a `.catch` block to the fetch promise chain to handle any errors that occur during the fetch operation.

Here is the proposed change:

```markdown
share/index.md
<<<<<<< ORIGINAL
fetch(conv)
.then(response => response.text())
.then(markdown => {
    // Ensure every line that starts with '>' ends with exactly 2 spaces
    markdown = markdown.split('\n').map(function(line) {
        if (line.startsWith('>')) {
            return line.trimEnd() + '  ';
        }
        return line;
    }).join('\n');
    var html = marked.parse(markdown);
    var divElement = document.querySelector('.chat-transcript');
    divElement.innerHTML = html;
});
=======
fetch(conv)
.then(response => response.text())
.then(markdown => {
    // Ensure every line that starts with '>' ends with exactly 2 spaces
    markdown = markdown.split('\n').map(function(line) {
        if (line.startsWith('>')) {
            return line.trimEnd() + '  ';
        }
        return line;
    }).join('\n');
    var html = marked.parse(markdown);
    var divElement = document.querySelector('.chat-transcript');
    divElement.innerHTML = html;
})
.catch(error => {
    console.error('Error fetching markdown:', error);
});
>>>>>>> UPDATED
```

This change adds a `.catch` block to the fetch promise chain. If an error occurs during the fetch operation, the error will be logged to the console and the rest of the script will be skipped.
2023-08-07 11:11:02 -03:00
Paul Gauthier
c5d80e9f7a aider: Check if there is a mdurl param and skip the rest if not.
# Aider chat conversation:

USER: check to make sure there is a mdurl param, skip the rest if not

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 exists before proceeding with the rest of the script.

Here is the proposed change:

```markdown
share/index.md
<<<<<<< ORIGINAL
window.onload = function() {
    var urlParams = new URLSearchParams(window.location.search);
    var conv = urlParams.get('mdurl');
    fetch(conv)
=======
window.onload = function() {
    var urlParams = new URLSearchParams(window.location.search);
    var conv = urlParams.get('mdurl');
    if (!conv) {
        return;
    }
    fetch(conv)
>>>>>>> UPDATED
```

This change checks if `conv` (which holds the value of the `mdurl` parameter) is not present. If it's not, the function returns immediately, skipping the rest of the script.
2023-08-07 11:10:28 -03:00
Paul Gauthier
49b1b228bd aider: Add script tag to load marked.min.js from CDN.
# Aider chat conversation:

USER: also load https://cdn.jsdelivr.net/npm/marked/marked.min.js

ASSISTANT: To load the `marked.min.js` library from the CDN, we need to add a script tag in the `index.md` file. Here is the change:

```markdown
share/index.md
<<<<<<< ORIGINAL
<script>
window.onload = function() {
=======
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
window.onload = function() {
>>>>>>> UPDATED
```

This change adds a new script tag before the existing script tag. The new script tag loads the `marked.min.js` library from the CDN. The existing script tag remains unchanged.
2023-08-07 11:06:35 -03:00
Paul Gauthier
4f8627e81f Add script to fetch and display a shared aider chat transcript. 2023-08-07 11:06:14 -03:00