fix build + simplify logic + add deploy note

This commit is contained in:
Felix Roos 2022-12-28 17:09:18 +01:00
parent cb8b65f6f3
commit 16b4058a8b
3 changed files with 18 additions and 31 deletions

View file

@ -17,7 +17,10 @@ const myPatterns = await getMyPatterns();
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-2 p-2 select-none">
{
Object.entries(myPatterns).map(([name, tune]) => (
<a class="rounded-md bg-slate-900 hover:bg-slate-700 cursor-pointer relative" href={`/#${btoa(tune)}`}>
<a
class="rounded-md bg-slate-900 hover:bg-slate-700 cursor-pointer relative"
href={`/#${btoa(tune as string)}`}
>
<div class="absolute w-full h-full flex justify-center items-center">
<span class="bg-slate-800 p-2 rounded-md text-white">{name}</span>
</div>

View file

@ -1,36 +1,13 @@
import fs from 'fs';
import path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
async function readTextFiles(folder) {
const absolutePath = path.resolve(__dirname, folder);
// Use `fs.promises.readdir()` to get a list of all the files in the folder
const files = await fs.promises.readdir(absolutePath);
// Filter the list of files to only include those with a `.txt` extension
const textFiles = files.filter((file) => file.endsWith('.txt'));
// Initialize an empty object to store the file contents
const fileContents = {};
// Use `fs.promises.readFile()` to read the contents of each text file
for (const file of textFiles) {
const filePath = `${absolutePath}/${file}`;
const data = await fs.promises.readFile(filePath, 'utf8');
fileContents[file] = data;
}
// Return the object with the filenames as keys and the file contents as values
return fileContents;
}
export function getMyPatterns() {
return readTextFiles('../../../../my-patterns');
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
return Object.fromEntries(
Object.entries(my) //
.filter(([name]) => name.endsWith('.txt')) //
.map(([name, raw]) => [name.split('/').slice(-1), raw]), //
);
}
export async function get({ params, request }) {
export async function get() {
const all = await getMyPatterns();
return {
body: JSON.stringify(all),