diff --git a/parse.js b/parse.js new file mode 100644 index 0000000..f02643f --- /dev/null +++ b/parse.js @@ -0,0 +1,52 @@ +const fs = require('fs'); + +const html = fs.readFileSync('menu.txt', 'utf8'); + +const items = []; +const regexCategory = /
([\s\S]*?)<\/div>\s*<\/div>/g; +const regexTitle = /class="restaurant-menu-category">([^<]+)<\/a>/; +const regexPosition = /
([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/g; // wait, the structure is a bit complex for simple regex. + +// Let's use basic string splitting. + +const cats = html.split('
'); +cats.shift(); // remove first empty + +const result = []; + +cats.forEach(catHtml => { + const titleMatch = catHtml.match(/class="restaurant-menu-category">([^<]+)<\/a>/); + const categoryName = titleMatch ? titleMatch[1].trim() : ''; + + const itemsMatches = catHtml.split('
{ + const idMatch = itemHtml.match(/data-position="([^"]*)"/); + const catIdMatch = itemHtml.match(/data-category-id="([^"]*)"/); + const tagMatch = itemHtml.match(/data-tag="([^"]*)"/); + const imgMatch = itemHtml.match(/]+src="([^"]+)"/); + const titleTextMatch = itemHtml.match(/

([^<]+)/); + const descMatch = itemHtml.match(/([^<]*)<\/span>/); + const priceMatch = itemHtml.match(/
\s*([^<]+)<\/span>/); + + categoryItems.push({ + position: idMatch ? idMatch[1] : '', + categoryId: catIdMatch ? catIdMatch[1] : '', + tag: tagMatch ? tagMatch[1] : '', + image: imgMatch ? imgMatch[1] : '', + title: titleTextMatch ? titleTextMatch[1].trim() : '', + description: descMatch ? descMatch[1].trim() : '', + price: priceMatch ? priceMatch[1].trim() : '' + }); + }); + + result.push({ + categoryName, + items: categoryItems + }); +}); + +fs.writeFileSync('public/menu.json', JSON.stringify(result, null, 2)); +console.log('Saved public/menu.json'); diff --git a/public/app.html b/public/app.html index c9bbca9..92b319e 100644 --- a/public/app.html +++ b/public/app.html @@ -113,67 +113,8 @@ -
-
-
Na dobry początek
-
-
- -
-

Wędzony łosoś na chrupkim placku ziemniaczanymze śmietaną i sosem a'la duńskim

-
-
31,00
-
-
- -
-

Skiśnięte ogórki i smolec swojej roboty z pieczywem

-
-
28,00
-
-
- -
-

Tatar siekany z wołowiny z piklami i pieczywem

-
-
62,00
-
-
-
- -
-
Polywki
-
-
- -
-

Żurek na wędzonce z jajkiem w chlebie

-
-
31,00
-
-
- -
-

Rosół wiejski z trzech rodzajów mięs z makaronem

-
-
19,00
-
-
-
- -
-
Co przez gospodarza lubiane
-
-
- -
-

Schab po zbóju z ogórkiem kiszonym podany z białym sosem i ziemniakami opiekanymi

-
-
53,00
-
-
-
- +
@@ -198,10 +139,10 @@ 📖 Menu

-