-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Chhavi9700225780/master
French Word Of The Day Card
- Loading branch information
Showing
7 changed files
with
359 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const fs = require("fs").promises; | ||
const { generateCard, Languages } = require("../card-generator"); | ||
const { parseOptions } = require("../options-parser"); | ||
|
||
const CARD_AGE = 86400; | ||
|
||
const DATA_FILE_PATH = "./src/data/french_word_of_the_day.json"; | ||
const DEFAULT_THEME = "light"; | ||
|
||
const handleTheme = (req, res, next) => { | ||
req.theme = req.query.theme || DEFAULT_THEME; | ||
next(); | ||
}; | ||
|
||
const handleOptions = (req, res, next) => { | ||
if (req.theme === "custom") { | ||
req.options = parseOptions(req.query); | ||
} | ||
next(); | ||
}; | ||
|
||
router.get("/", handleTheme, handleOptions, async (req, res) => { | ||
try { | ||
const FrenchwordOfTheDayData = JSON.parse( | ||
await fs.readFile(DATA_FILE_PATH, "utf8") | ||
); | ||
const randomWord = | ||
FrenchwordOfTheDayData[Math.floor(Math.random() * FrenchwordOfTheDayData.length)]; | ||
const FrenchwordContent = `${randomWord.french}\n\nMeaning: ${randomWord.english}`; | ||
|
||
const FrenchwordCard = await generateCard( | ||
FrenchwordContent, | ||
req.theme, | ||
req.options, | ||
Languages.ENGLISH | ||
); | ||
|
||
res.writeHead(200, { | ||
"Content-Type": "image/svg+xml", | ||
"Cache-Control": `public, max-age=${CARD_AGE}`, | ||
}); | ||
res.end(FrenchwordCard); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
res.status(500).send("Internal Server Error"); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
[ | ||
{ "french": "Bonjour", "english": "Hello" }, | ||
{ "french": "Merci", "english": "Thank you" }, | ||
{ "french": "S'il vous plaît", "english": "Please" }, | ||
{ "french": "Oui", "english": "Yes" }, | ||
{ "french": "Non", "english": "No" }, | ||
{ "french": "Au revoir", "english": "Goodbye" }, | ||
{ "french": "Amour", "english": "Love" }, | ||
{ "french": "Famille", "english": "Family" }, | ||
{ "french": "Ami", "english": "Friend" }, | ||
{ "french": "Maison", "english": "House" }, | ||
{ "french": "Chat", "english": "Cat" }, | ||
{ "french": "Chien", "english": "Dog" }, | ||
{ "french": "Voiture", "english": "Car" }, | ||
{ "french": "Fleur", "english": "Flower" }, | ||
{ "french": "Eau", "english": "Water" }, | ||
{ "french": "Pain", "english": "Bread" }, | ||
{ "french": "Soleil", "english": "Sun" }, | ||
{ "french": "Lune", "english": "Moon" }, | ||
{ "french": "Étoile", "english": "Star" }, | ||
{ "french": "Ciel", "english": "Sky" }, | ||
{ "french": "Terre", "english": "Earth" }, | ||
{ "french": "Montagne", "english": "Mountain" }, | ||
{ "french": "Mer", "english": "Sea" }, | ||
{ "french": "Plage", "english": "Beach" }, | ||
{ "french": "Ville", "english": "City" }, | ||
{ "french": "École", "english": "School" }, | ||
{ "french": "Travail", "english": "Work" }, | ||
{ "french": "Livre", "english": "Book" }, | ||
{ "french": "Musique", "english": "Music" }, | ||
{ "french": "Film", "english": "Movie" }, | ||
{ "french": "Chanson", "english": "Song" }, | ||
{ "french": "Art", "english": "Art" }, | ||
{ "french": "Danse", "english": "Dance" }, | ||
{ "french": "Jeu", "english": "Game" }, | ||
{ "french": "Sport", "english": "Sport" }, | ||
{ "french": "Nature", "english": "Nature" }, | ||
{ "french": "Histoire", "english": "History" }, | ||
{ "french": "Culture", "english": "Culture" }, | ||
{ "french": "Langue", "english": "Language" }, | ||
{ "french": "Pays", "english": "Country" }, | ||
{ "french": "Ville", "english": "Town" }, | ||
{ "french": "Route", "english": "Road" }, | ||
{ "french": "Pont", "english": "Bridge" }, | ||
{ "french": "Château", "english": "Castle" }, | ||
{ "french": "Parc", "english": "Park" }, | ||
{ "french": "Jardin", "english": "Garden" }, | ||
{ "french": "Chocolat", "english": "Chocolate" }, | ||
{ "french": "Glace", "english": "Ice cream" }, | ||
{ "french": "Fête", "english": "Party" }, | ||
{ "french": "Vacances", "english": "Vacation" }, | ||
{ "french": "Rêve", "english": "Dream" }, | ||
{ "french": "Espoir", "english": "Hope" }, | ||
{ "french": "Joie", "english": "Joy" }, | ||
{ "french": "Tristesse", "english": "Sadness" }, | ||
{ "french": "Colère", "english": "Anger" }, | ||
{ "french": "Peur", "english": "Fear" }, | ||
{ "french": "Confiance", "english": "Trust" }, | ||
{ "french": "Savoir", "english": "Knowledge" }, | ||
{ "french": "Réalité", "english": "Reality" }, | ||
{ "french": "Liberté", "english": "Freedom" }, | ||
{ "french": "Égalité", "english": "Equality" }, | ||
{ "french": "Fraternité", "english": "Brotherhood" }, | ||
{ "french": "École", "english": "School" }, | ||
{ "french": "Fleur", "english": "Flower" }, | ||
{ "french": "Café", "english": "Coffee" }, | ||
{ "french": "Thé", "english": "Tea" }, | ||
{ "french": "Fruits", "english": "Fruits" }, | ||
{ "french": "Légumes", "english": "Vegetables" }, | ||
{ "french": "Bureau", "english": "Office" }, | ||
{ "french": "Chaise", "english": "Chair" }, | ||
{ "french": "Table", "english": "Table" }, | ||
{ "french": "Fenêtre", "english": "Window" }, | ||
{ "french": "Porte", "english": "Door" }, | ||
{ "french": "Manteau", "english": "Coat" }, | ||
{ "french": "Chapeau", "english": "Hat" }, | ||
{ "french": "Chaussures", "english": "Shoes" }, | ||
{ "french": "Pantalon", "english": "Pants" }, | ||
{ "french": "Chemise", "english": "Shirt" }, | ||
{ "french": "Soleil", "english": "Sun" }, | ||
{ "french": "Lune", "english": "Moon" }, | ||
{ "french": "Cœur", "english": "Heart" }, | ||
{ "french": "Esprit", "english": "Mind" }, | ||
{ "french": "Corps", "english": "Body" }, | ||
{ "french": "Chanson", "english": "Song" }, | ||
{ "french": "Poème", "english": "Poem" }, | ||
{ "french": "Cadeau", "english": "Gift" }, | ||
{ "french": "Souvenir", "english": "Memory" }, | ||
{ "french": "Avion", "english": "Plane" }, | ||
{ "french": "Train", "english": "Train" }, | ||
{ "french": "Bateau", "english": "Boat" }, | ||
{ "french": "Vélo", "english": "Bicycle" }, | ||
{ "french": "Monde", "english": "World" }, | ||
{ "french": "Étoile", "english": "Star" }, | ||
{ "french": "Saison", "english": "Season" }, | ||
{"french": "travail", "english": "work"}, | ||
{"french": "valeur", "english": "value"}, | ||
{"french": "vérité", "english": "truth"}, | ||
{"french": "voix", "english": "voice"}, | ||
{"french": "absolu", "english": "absolute"}, | ||
{"french": "aventure", "english": "adventure"}, | ||
{"french": "bonté", "english": "kindness"}, | ||
{"french": "chance", "english": "luck"}, | ||
{"french": "défi", "english": "challenge"}, | ||
{"french": "énergie", "english": "energy"}, | ||
{"french": "esprit", "english": "spirit"}, | ||
{"french": "fantaisie", "english": "fantasy"}, | ||
{"french": "gentillesse", "english": "kindness"}, | ||
{"french": "intelligence", "english": "intelligence"}, | ||
{"french": "joie", "english": "joy"}, | ||
{"french": "libération", "english": "liberation"}, | ||
{"french": "mémoire", "english": "memory"}, | ||
{"french": "mystère", "english": "mystery"}, | ||
{"french": "noblesse", "english": "nobility"}, | ||
{"french": "optimisme", "english": "optimism"}, | ||
{"french": "persévérance", "english": "perseverance"} | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.