Skip to content

Commit

Permalink
Begin work on Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Declan Chidlow committed Oct 16, 2023
1 parent 84e5cba commit 7386b4b
Show file tree
Hide file tree
Showing 3 changed files with 500 additions and 0 deletions.
49 changes: 49 additions & 0 deletions config/pages/demo/demo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# Demo

Try before you buy - or rather use. These blobby guys are free after all.

<table>
<tbody id="data">
<!-- Data will be put in here-->
</tbody>
</table>

<script src="tarball.js"></script>
<script>
const fetchSampleBlob = () =>
fetch("https://cors-anywhere.herokuapp.com/https://github.com/mutant-remix/mutant-remix/releases/download/v54/mtnt_v54_short_svg.tar.gz", { headers: { "X-Requested-With": "https://github.com" } });

const fetchStreamToDecompressionStream = (response) =>
response.body.pipeThrough(new DecompressionStream("gzip"));

const decompressionStreamToBlob = (decompressedStream) => new Response(decompressedStream).blob();

const blobToDir = (blob) => new tarball.TarReader().readFile(blob);

const renderDataInList = (data) => {
const tbody = document.getElementById('data');

data.forEach(item => {
if (item.type === 'directory') {
// If it's a directory item, create a heading
const heading = document.createElement('h2');
heading.textContent = item.name;
tbody.appendChild(heading);
} else {
// If it's a file item, create a list item and extract the file name
const listItem = document.createElement('li');
const fileName = item.name.split('/').pop();
listItem.textContent = fileName;
tbody.appendChild(listItem);
}
});
};

fetchSampleBlob()
.then(fetchStreamToDecompressionStream)
.then(decompressionStreamToBlob)
.then(blobToDir)
.then(data => {
console.log("Data received:", data);
renderDataInList(data);
})
.catch(error => console.error(error));
</script>

46 changes: 46 additions & 0 deletions docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,52 @@
<div id="content">
<h1>Demo</h1>
<p>Try before you buy - or rather use. These blobby guys are free after all.</p>
<table>
<tbody id="data">
<!-- Data will be put in here-->
</tbody>
</table>
<script src="tarball.js"></script>
<script>
const fetchSampleBlob = () =>
fetch("https://cors-anywhere.herokuapp.com/https://github.com/mutant-remix/mutant-remix/releases/download/v54/mtnt_v54_short_svg.tar.gz", { headers: { "X-Requested-With": "https://github.com" } });

const fetchStreamToDecompressionStream = (response) =>
response.body.pipeThrough(new DecompressionStream("gzip"));

const decompressionStreamToBlob = (decompressedStream) => new Response(decompressedStream).blob();

const blobToDir = (blob) => new tarball.TarReader().readFile(blob);

const renderDataInList = (data) => {
const tbody = document.getElementById('data');

data.forEach(item => {
if (item.type === 'directory') {
// If it's a directory item, create a heading
const heading = document.createElement('h2');
heading.textContent = item.name;
tbody.appendChild(heading);
} else {
// If it's a file item, create a list item and extract the file name
const listItem = document.createElement('li');
const fileName = item.name.split('/').pop();
listItem.textContent = fileName;
tbody.appendChild(listItem);
}
});
};

fetchSampleBlob()
.then(fetchStreamToDecompressionStream)
.then(decompressionStreamToBlob)
.then(blobToDir)
.then(data => {
console.log("Data received:", data);
renderDataInList(data);
})
.catch(error => console.error(error));
</script>


<footer>
Expand Down
Loading

0 comments on commit 7386b4b

Please sign in to comment.