diff --git a/bin/richieMaker.ts b/bin/richieMaker.ts index 600e9ef..794d040 100644 --- a/bin/richieMaker.ts +++ b/bin/richieMaker.ts @@ -1,4 +1,4 @@ -import { rmSync } from "fs"; +import { rmSync, existsSync } from "fs"; import { readFile } from "fs/promises"; import { globSync } from "glob"; import { dirname, join, relative, basename } from "path"; @@ -30,7 +30,7 @@ export async function makeRichie( options = { ...richieDefaultOptions, ...options }; //remove previous op dir and files - if (!options.norm) { + if (!options.norm && existsSync(options.destDir as string)) { rmSync(options.destDir as string, { recursive: true }); } diff --git a/lib/sweeper.ts b/lib/sweeper.ts new file mode 100644 index 0000000..151d675 --- /dev/null +++ b/lib/sweeper.ts @@ -0,0 +1,155 @@ +import { CheerioAPI, load } from "cheerio"; +import configuration from "../configLoader"; +import { richies } from "./options"; + +const { reservedNames } = configuration; + +export function sweep(richieName: richies, htmlSource: string): string { + const htmlDOM: CheerioAPI = load(htmlSource); + + switch (richieName) { + case "article": + return _cleanArticle(htmlDOM); + + case "restaurant": + case "crestaurant": + return _cleanRestaurant(htmlDOM); + + case "course": + case "ccourse": + return _cleanCourse(htmlDOM); + + case "event": + return _cleanEvents(htmlDOM); + + case "video": + return _cleanVideo(htmlDOM); + + case "localbusiness": + return _cleanLocalBusiness(htmlDOM); + + case "product": + case "productwv": + return _cleanProduct(htmlDOM); + + case "software": + return _cleanSoftwareApp(htmlDOM); + + default: + return "null"; + } +} + +function _cleanArticle(DOMTree: CheerioAPI): string { + DOMTree("body").removeAttr(`data-${reservedNames.article.articleType}`); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanCourse(DOMTree: CheerioAPI) { + DOMTree(`[data-${reservedNames.course.language}]`).removeAttr( + `data-${reservedNames.course.language}`, + ); + + DOMTree(`[data-${reservedNames.course.courseFrequency}]`).removeAttr( + `data-${reservedNames.course.courseFrequency}`, + ); + + DOMTree(`[data-${reservedNames.course.courseRepeatation}]`).removeAttr( + `data-${reservedNames.course.courseRepeatation}`, + ); + + DOMTree(`[data-${reservedNames.common.currencyDataVar}]`).removeAttr( + `data-${reservedNames.common.currencyDataVar}`, + ); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanRestaurant(DOMTree: CheerioAPI): string { + DOMTree( + `[data-${reservedNames.businessEntity.reservationDataVar}]`, + ).removeAttr(`data-${reservedNames.businessEntity.reservationDataVar}`); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanSoftwareApp(DOMTree: CheerioAPI): string { + DOMTree(`[data-${reservedNames.common.currencyDataVar}]`).removeAttr( + `data-${reservedNames.common.currencyDataVar}`, + ); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanVideo(DOMTree: CheerioAPI): string { + DOMTree(`[data-${reservedNames.video.startOffsetDataVar}]`).removeAttr( + `data-${reservedNames.video.startOffsetDataVar}`, + ); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanLocalBusiness(DOMTree: CheerioAPI): string { + DOMTree( + `[data-${reservedNames.businessEntity.reservationDataVar}]`, + ).removeAttr(`data-${reservedNames.businessEntity.reservationDataVar}`); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanEvents(DOMTree: CheerioAPI): string { + DOMTree(`[data-${reservedNames.common.MO}]`).removeAttr( + `data-${reservedNames.common.MO}`, + ); + + DOMTree(`[data-${reservedNames.events.status}]`).removeAttr( + `data-${reservedNames.events.status}`, + ); + + DOMTree(`[data-${reservedNames.common.currencyDataVar}]`).removeAttr( + `data-${reservedNames.common.currencyDataVar}`, + ); + + const htmlString = DOMTree.html(); + return htmlString; +} + +function _cleanProduct(DOMTree: CheerioAPI): string { + DOMTree(`[data-${reservedNames.common.currencyDataVar}]`).removeAttr( + `data-${reservedNames.common.currencyDataVar}`, + ); + + DOMTree(`[data-${reservedNames.product.offer.availability}]`).removeAttr( + `data-${reservedNames.product.offer.availability}`, + ); + + DOMTree( + `[data-${reservedNames.product.offer.itemCondition}]`, + ).removeAttr(`data-${reservedNames.product.offer.itemCondition}`); + + DOMTree( + `[data-${reservedNames.product.offer.shippingDetails.deliveryOver}]`, + ).removeAttr( + `data-${reservedNames.product.offer.shippingDetails.deliveryOver}`, + ); + + DOMTree( + `[data-${reservedNames.product.offer.shippingDetails.rangeDataVar}]`, + ).removeAttr( + `data-${reservedNames.product.offer.shippingDetails.rangeDataVar}`, + ); + + DOMTree(`[data-${reservedNames.product.variesByDataVar}]`).removeAttr( + `data-${reservedNames.product.variesByDataVar}`, + ); + + const htmlString = DOMTree.html(); + return htmlString; +} diff --git a/richie.ts b/richie.ts index d613e98..395e1e4 100644 --- a/richie.ts +++ b/richie.ts @@ -31,6 +31,7 @@ import { richies, } from "./lib/options"; import { createJsonLD, writeOutput } from "./lib/utilities"; +import { sweep } from "./lib/sweeper"; const functionMap: Record = { article: { @@ -150,8 +151,9 @@ export async function richie( const serializedData = serializer(...serializerParams); const richResultSnippet = createJsonLD(serializedData); + const cleanSource = sweep(richieName, source); - writeOutput(source, destinationFile, richResultSnippet) + writeOutput(cleanSource, destinationFile, richResultSnippet) .then(() => { resolve(); }) diff --git a/test/outputs/OP_Of_(1) article.html b/test/outputs/OP_Of_(1) article.html index 9e4eb7e..f355618 100644 --- a/test/outputs/OP_Of_(1) article.html +++ b/test/outputs/OP_Of_(1) article.html @@ -38,7 +38,7 @@ - +

2024-02-06 08:37 PM

diff --git a/test/outputs/OP_Of_(10) courses.html b/test/outputs/OP_Of_(10) courses.html index 98084e5..59bf01e 100644 --- a/test/outputs/OP_Of_(10) courses.html +++ b/test/outputs/OP_Of_(10) courses.html @@ -118,7 +118,7 @@
-

Python Crash Course

+

Python Crash Course

@@ -141,13 +141,11 @@

-

- 68 Hours -

+

68 Hours

-

100 USD

+

100 USD

@@ -163,9 +161,7 @@
-

- Node.Js introduction -

+

Node.Js introduction

@@ -190,13 +186,11 @@

-

- 24 Hours -

+

24 Hours

-

2000 USD

+

2000 USD

@@ -207,9 +201,7 @@
-

- Java Intermediate to Advanced -

+

Java Intermediate to Advanced

English

@@ -237,13 +229,11 @@

-

- 1 Months -

+

1 Months

-

2000 RS

+

2000 RS

diff --git a/test/outputs/OP_Of_(11) events.html b/test/outputs/OP_Of_(11) events.html index 00caa03..d0adb73 100644 --- a/test/outputs/OP_Of_(11) events.html +++ b/test/outputs/OP_Of_(11) events.html @@ -153,20 +153,14 @@

-

- Attendance Mode: - Online -

+

Attendance Mode: Online

-

- Event Status: - Scheduled -

+

Event Status: Scheduled

@@ -205,10 +199,7 @@ -

- Event Fee: - FREE -

+

Event Fee: FREE

-

- Attendance Mode: - Offline -

+

Attendance Mode: Offline

- Event Status: - Moved to Online + Event Status: Moved to Online

@@ -313,10 +298,7 @@ -

- Event Fee: - 200 INR -

+

Event Fee: 200 INR

Attendance Mode: - Online and Offline + Online and Offline

-

- Event Status: - Cancelled -

+

Event Status: Cancelled

@@ -423,10 +400,7 @@ -

- Event Fee: - 10 USD -

+

Event Fee: 10 USD

- + - - - FAQ Page - - -
- - Can you provide a content management system (CMS) that allows me to - update the website easily? - - -

- Certainly! We take pride in crafting custom Content Management - Systems (CMS) tailored exclusively to your requirements. - Unlike common pre-made template CMS, our solutions are designed with - your unique needs in mind. With Cresteem, managing your website's - content is not only simple but also seamlessly integrated for a truly - personalized experience. -

-
- -
- - Do you offer any additional services, such as digital marketing, SEO, or - social media management, to help promote the website? - - -

- Absolutely! Beyond website development, Cresteem offers an array - of comprehensive services. Our immersive - digital marketing strategies are finely tuned to captivate your - potential clients, ensuring rapid growth. We deploy strategic operations to optimize - your website's performance, and our expertise extends to captivating - your target audience on various social media platforms. - We're your one-stop solution for a powerful online presence. -

-
- -
- - Will the website be optimized for fast loading times and performance? - - -

- At Cresteem, - yes optimizing website performance is our top priority. We're - dedicated to creating - highly accessible, lightning-fast, and reliable web applications, - landing pages, or e-commerce platforms - tailored to your business. Our commitment is evident in our - track record of achieving load times consistently below 2 seconds. - We employ a range of cutting-edge tools and techniques, including Google - PageSpeed Insights, responsive design, and emulated devices, to ensure - your website maintains the highest quality and speed. -

-
+ null diff --git a/test/outputs/OP_Of_(13) videos.html b/test/outputs/OP_Of_(13) videos.html index c95f1db..4a73e4f 100644 --- a/test/outputs/OP_Of_(13) videos.html +++ b/test/outputs/OP_Of_(13) videos.html @@ -19,7 +19,7 @@ "interactionStatistic": { "@type": "InteractionCounter", "interactionType": { "@type": "WatchAction" }, - "userInteractionCount": 44316 + "userInteractionCount": 46150 }, "expires": "3023-11-24T22:30:41+05:30", "hasPart": [ @@ -59,7 +59,7 @@ "interactionStatistic": { "@type": "InteractionCounter", "interactionType": { "@type": "WatchAction" }, - "userInteractionCount": 616857 + "userInteractionCount": 619109 }, "expires": "3022-08-02T09:38:18+05:30", "hasPart": [ @@ -95,9 +95,9 @@
    -
  • Photo Testing
  • -
  • Video Testing
  • -
  • Cinematic Testing
  • +
  • Photo Testing
  • +
  • Video Testing
  • +
  • Cinematic Testing
- - -
    -
  • Biryani recipe
  • -
  • Authentic biryani
  • -
  • Homemade biryani
  • -
  • Indian biryani
  • -
  • Chicken biryani
  • -
  • Vegetable biryani
  • -
  • Spicy biryani
  • -
  • Easy biryani recipe
  • -
  • Delicious biryani
  • -
  • Traditional biryani dish
  • -
-
- - -
- -

Classic Oatmeal

- - - - - -

Your Name

- - -

2024-04-26

- - -

- Classic oatmeal is a nutritious and comforting breakfast option. Made - from rolled oats and simmered in milk or water, it's a versatile dish - that can be customized with various toppings to suit your taste - preferences. -

- - -

10 minutes

- - -

5 minutes

- - -

2

- - -

Breakfast

- - -

American

- - -
- -

150

-
- - -
    -
  • Rolled oats - 1 cup
  • -
  • Milk or water - 2 cups
  • -
  • Optional toppings: fruits, nuts, honey, cinnamon, etc.
  • -
- - -
- -
-

Cook the Oats:

- - - -

- In a saucepan, bring the milk or water to a gentle boil over - medium heat. Stir in the rolled oats and reduce the heat to low. - Simmer uncovered, stirring occasionally, for about 5 minutes or - until the oats are soft and the mixture has thickened to your - desired consistency. -

-
- - -
-

Serve:

- - - -

- Once cooked, remove the oatmeal from heat and let it sit for a - minute before serving. Pour into bowls and top with your favorite - toppings such as fresh fruits, nuts, a drizzle of honey, or a - sprinkle of cinnamon. Enjoy your warm and nutritious bowl of - oatmeal! -

-
-
- - - -
- -

5

- -

4.5

- -

500

-
- - -
    -
  • Oatmeal recipe
  • -
  • Classic oatmeal
  • -
  • Breakfast dish
  • -
  • Healthy breakfast
  • -
  • Quick oats
  • -
  • Cinnamon oats
  • -
  • Simple oatmeal
  • -
  • Nutritious breakfast
  • -
  • Warm breakfast
  • -
- - -
- + null diff --git a/test/outputs/OP_Of_(4) recipies.html b/test/outputs/OP_Of_(4) recipies.html index 4ff4de6..7f598ed 100644 --- a/test/outputs/OP_Of_(4) recipies.html +++ b/test/outputs/OP_Of_(4) recipies.html @@ -1,13 +1,5 @@ - - + - - - Recipe - - -
-
- -

Biryani

- - - - - - -

Darsan

- - -

2023-01-12

- - -

- Biryani is a flavorful and aromatic rice dish originating from the - Indian subcontinent. It consists of long-grain rice cooked with a - blend of spices such as cumin, cardamom, and saffron, layered with - marinated meats or vegetables. Biryani offers a rich and complex taste - profile and is often served with accompaniments like raita or salad. -

- - - - -

25 minutes

- - - - - - -

20 minutes

- - - -

4

- - -

Rich Dishes

- - -

Indian

- - -
- -

300

-
- - -
    -
  • Basmati Rice - 2 cups
  • -
  • Meat (chicken, lamb, or beef) or Vegetables - 500 grams
  • -
  • Aromatic Spices
  • -
  • Yogurt - 1/2 cup
  • -
  • Saffron - A pinch (soaked in 2 tablespoons of warm milk)
  • -
  • Rose Water - 1 tablespoon
  • -
- - -
- -
-

Prepare the Rice:

- - - -

- Rinse 2 cups of basmati rice under cold water until the water runs - clear. Soak the rice in water for 30 minutes, then drain. In a - large pot, bring water to a boil and add the drained rice along - with a pinch of salt. Cook until the rice is 70% done, then drain - and set aside. -

-
- - -
-

Prepare the Meat or Vegetables:

- - - -

- Marinate 500 grams of meat (chicken, lamb, or beef) or vegetables - in a mixture of yogurt and aromatic spices (cumin, cardamom, - cloves, cinnamon, bay leaves). Allow the meat or vegetables to - marinate for at least 30 minutes to absorb the flavors. -

-
- - -
-

Layering:

- - - -

- In a heavy-bottomed pot, layer the partially cooked rice and - marinated meat or vegetables alternately. Drizzle saffron soaked - in warm milk and rose water over the layers for added fragrance - and color. Optionally, sprinkle fried onions and chopped mint - leaves between the layers. -

-
- - -
-

Cooking:

- - - -

- Cover the pot with a tight-fitting lid and cook on low heat for - 20-25 minutes, allowing the flavors to meld together and the rice - to fully cook. Alternatively, you can place the pot in a preheated - oven at 350°F (180°C) for the same duration. -

-
- - -
-

Serve:

- - - -

- Once cooked, gently fluff the biryani with a fork, ensuring the - layers remain intact. Serve hot garnished with additional fried - onions, chopped cilantro, and a side of raita or salad for a - complete meal experience. Enjoy your flavorful homemade biryani! -

-
-
- - - -
- -

100

- -

99

- -

1200

-
- - - - - -
    -
  • Biryani recipe
  • -
  • Authentic biryani
  • -
  • Homemade biryani
  • -
  • Indian biryani
  • -
  • Chicken biryani
  • -
  • Vegetable biryani
  • -
  • Spicy biryani
  • -
  • Easy biryani recipe
  • -
  • Delicious biryani
  • -
  • Traditional biryani dish
  • -
-
- - -
- -

Classic Oatmeal

- - - - - -

Your Name

- - -

2024-04-26

- - -

- Classic oatmeal is a nutritious and comforting breakfast option. Made - from rolled oats and simmered in milk or water, it's a versatile dish - that can be customized with various toppings to suit your taste - preferences. -

- - -

10 minutes

- - -

5 minutes

- - -

2

- - -

Breakfast

- - -

American

- - -
- -

150

-
- - -
    -
  • Rolled oats - 1 cup
  • -
  • Milk or water - 2 cups
  • -
  • Optional toppings: fruits, nuts, honey, cinnamon, etc.
  • -
- - -
- -
-

Cook the Oats:

- - - -

- In a saucepan, bring the milk or water to a gentle boil over - medium heat. Stir in the rolled oats and reduce the heat to low. - Simmer uncovered, stirring occasionally, for about 5 minutes or - until the oats are soft and the mixture has thickened to your - desired consistency. -

-
- - -
-

Serve:

- - - -

- Once cooked, remove the oatmeal from heat and let it sit for a - minute before serving. Pour into bowls and top with your favorite - toppings such as fresh fruits, nuts, a drizzle of honey, or a - sprinkle of cinnamon. Enjoy your warm and nutritious bowl of - oatmeal! -

-
-
- - - -
- -

5

- -

4.5

- -

500

-
- - -
    -
  • Oatmeal recipe
  • -
  • Classic oatmeal
  • -
  • Breakfast dish
  • -
  • Healthy breakfast
  • -
  • Quick oats
  • -
  • Cinnamon oats
  • -
  • Simple oatmeal
  • -
  • Nutritious breakfast
  • -
  • Warm breakfast
  • -
- - -
-
+ null diff --git a/test/outputs/OP_Of_(5) movies.html b/test/outputs/OP_Of_(5) movies.html index 7c82a80..23e1354 100644 --- a/test/outputs/OP_Of_(5) movies.html +++ b/test/outputs/OP_Of_(5) movies.html @@ -1,9 +1,5 @@ - - + - - - Movies - - - -
- -

Dawn of Justice

- - - - - - -

2016-02-05

- - -

Zack Synder

-

Another director

- - -
- -

100

- - -

100

- - -

1000

-
- - -
- -
-

Darsan

- - -

100

- - -

98

- - -

IMDB

- -
- -
-

NotIndiaGlitz

- - -

5

- - -

4.5

- - -

RottenTomato

- -
-
- -
- - - -
- -

Justice League

- - - - - - -

2017-04-10

- - -

Zack Synder

-

Joss Whedon

- - -
- -

95

- - -

100

- - -

800

-
- - -
- -
-

Darsan

- - -

100

- - -

90

- - -

IMDB

- -
- -
-

NotIndiaGlitz

- - -

5

- - -

3.5

- - -

Rotten Tomato

- -
-
- -
- + null diff --git a/test/outputs/OP_Of_(6) movies.html b/test/outputs/OP_Of_(6) movies.html index bad3bf3..868e124 100644 --- a/test/outputs/OP_Of_(6) movies.html +++ b/test/outputs/OP_Of_(6) movies.html @@ -1,9 +1,5 @@ - - + - - - Movies - - - -
- -

Dawn of Justice

- - - - - - -

2016-02-05

- - -

Zack Synder

-

Another director

- - -
- -

100

- - -

100

- - -

1000

-
- - -
- -
-

Darsan

- - -

100

- - -

98

- - -

IMDB

- -
- -
-

NotIndiaGlitz

- - -

5

- - -

4.5

- - -

RottenTomato

- -
-
- -
- - - -
- -

Justice League

- - - - - - -

2017-04-10

- - -

Zack Synder

-

Joss Whedon

- - -
- -

95

- - -

100

- - -

800

-
- - -
- -
-

Darsan

- - -

100

- - -

90

- - -

IMDB

- -
- -
-

NotIndiaGlitz

- - -

5

- - -

3.5

- - -

Rotten Tomato

- -
-
- -
- + null diff --git a/test/outputs/OP_Of_(7) restaurants.html b/test/outputs/OP_Of_(7) restaurants.html index cdbbdcd..71a287c 100644 --- a/test/outputs/OP_Of_(7) restaurants.html +++ b/test/outputs/OP_Of_(7) restaurants.html @@ -260,7 +260,7 @@ -

+91-84259372x3

+

+91-84259372x3

Asian

@@ -404,7 +404,7 @@ -

+1 212-380-8x60

+

+1 212-380-8x60

American

diff --git a/test/outputs/OP_Of_(8) restaurants.html b/test/outputs/OP_Of_(8) restaurants.html index f7fa814..55dac04 100644 --- a/test/outputs/OP_Of_(8) restaurants.html +++ b/test/outputs/OP_Of_(8) restaurants.html @@ -270,7 +270,7 @@ -

+91-84259372x3

+

+91-84259372x3

Asian

@@ -414,7 +414,7 @@ -

+1 212-380-8x60

+

+1 212-380-8x60

American

diff --git a/test/outputs/OP_Of_(9) courses.html b/test/outputs/OP_Of_(9) courses.html index bc8c3e5..dd52b5a 100644 --- a/test/outputs/OP_Of_(9) courses.html +++ b/test/outputs/OP_Of_(9) courses.html @@ -105,7 +105,7 @@