|
21 | 21 |
|
22 | 22 | let res: ReturnType<typeof runQuery>; |
23 | 23 | let sortedResults: any[] = []; |
| 24 | + let queryResult: string = ''; |
24 | 25 |
|
25 | 26 | function executeQuery() { |
26 | 27 | res = runQuery() |
27 | 28 | .then((result) => { |
28 | 29 | sortedResults = sortResult(result?.map(([item]) => item)); |
| 30 | + queryResult = JSON.stringify(sortedResults, null, 2); // Set queryResult to display JSON by default |
29 | 31 | }); |
30 | 32 | } |
31 | 33 |
|
|
54 | 56 | } |
55 | 57 | } |
56 | 58 |
|
57 | | - function downloadMarkdown() { |
| 59 | + function generateMarkdown() { |
58 | 60 | if (!sortedResults.length) return; |
59 | 61 |
|
60 | 62 | const markdownContent = sortedResults |
|
78 | 80 | }) |
79 | 81 | .join('\n\n---\n\n'); |
80 | 82 |
|
81 | | - const blob = new Blob([markdownContent], { type: 'text/markdown;charset=utf-8' }); |
82 | | - saveAs(blob, 'results.md'); |
| 83 | + queryResult = markdownContent; // Update the query-result area with markdown |
| 84 | + } |
| 85 | +
|
| 86 | + function downloadContent() { |
| 87 | + if (!queryResult) return; |
| 88 | +
|
| 89 | + const blob = new Blob([queryResult], { type: 'text/plain;charset=utf-8' }); |
| 90 | + saveAs(blob, 'results.txt'); |
83 | 91 | } |
84 | 92 | </script> |
85 | 93 |
|
|
90 | 98 | <div class="control-group"> |
91 | 99 | <label for="sort-order">Sort Order:</label> |
92 | 100 | <select id="sort-order" bind:value={sortOrder}> |
93 | | - <option value="asc">Sort Asc</option> |
94 | | - <option value="desc">Sort Desc</option> |
| 101 | + <option value="asc">Asc</option> |
| 102 | + <option value="desc">Desc</option> |
95 | 103 | </select> |
96 | 104 | </div> |
97 | 105 | <div class="control-group"> |
|
115 | 123 | </select> |
116 | 124 | </div> |
117 | 125 | <div class="control-group"> |
118 | | - <button on:click={downloadMarkdown}>Download as Markdown</button> |
| 126 | + <button on:click={generateMarkdown}>Generate Markdown</button> |
| 127 | + <div class="vertical-separator"></div> |
| 128 | + <button on:click={downloadContent}>Download Content</button> |
119 | 129 | </div> |
120 | 130 | </div> |
121 | 131 | </div> |
122 | 132 | <div class="query-result"> |
123 | 133 | {#await res} |
124 | 134 | <pre>...running query</pre> |
125 | 135 | {:then result} |
126 | | - <pre>{JSON.stringify(sortedResults, null, 2)}</pre> |
| 136 | + <pre>{queryResult}</pre> |
127 | 137 | {:catch error} |
128 | 138 | <pre class="error">{error.message}</pre> |
129 | 139 | {/await} |
|
0 commit comments