Skip to content

Commit

Permalink
Merge pull request #60 from JoanJaraBosch/JoanJaraBranch
Browse files Browse the repository at this point in the history
spanish quotes jokes
  • Loading branch information
akanshSirohi authored Oct 9, 2024
2 parents 24797dc + f602c36 commit 95be1b2
Show file tree
Hide file tree
Showing 6 changed files with 855 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.prettierignore
.prettierignore
.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Here is a list of cards that can currently be used:
| `random-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-card)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-card) |
| `programming-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/programming-facts-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/programming-facts-card?theme=dark) |
| `top-tweets-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/top-tweets-card)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/top-tweets-card) |
| `spanish-quote-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/spanish-quote-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/spanish-quote-card?theme=dark) |

## Themes

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const available_cards = {
"/team-work-quote-card" : require("./src/cards/team-work-quote"),
"/bhagavad-geeta-card" : require("./src/cards/bhagavad-geeta-quotes"),
"/programming-facts-card": require("./src/cards/programming-facts"),
"/spanish-quote-card": require("./src/cards/spanish-quote"),
"/top-tweets-card": require("./src/cards/top-tweets")
};

Expand Down
60 changes: 60 additions & 0 deletions src/cards/spanish-quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const express = require("express");
const router = express.Router();
const fs = require("fs").promises;
const { generateCard, CARD_AGE, Languages } = require("../card-generator");
const { parseOptions } = require("../options-parser");

const DATA_FILE_PATH = "./src/data/spanish_jokes.json"; // Updated for Spanish jokes
const DEFAULT_THEME = "light";

const handleTheme = (req, res, next) => {
req.theme = req.query.theme || DEFAULT_THEME;
next();
};

const handleOptions = (req, res, next) => {
// Custom theme moderation
if (req.theme === "mi_tema") { // Spanish naming for the custom theme
req.theme = "pattern_3";
req.options = {
card_color: "#ffffffc2",
font_color: "#000",
shadow: false,
};
} else if (req.theme === "custom") {
req.options = parseOptions(req.query);
}
next();
};

router.get("/", handleTheme, handleOptions, async (req, res) => {
try {
const jokes = JSON.parse(await fs.readFile(DATA_FILE_PATH, "utf8"));
const random_joke = jokes[Math.floor(Math.random() * jokes.length)];

let joke_content;
if (random_joke.type === "single") {
joke_content = random_joke.joke;
} else if (random_joke.type === "double") {
joke_content = `P. ${random_joke.joke.q}\n\nR. ${random_joke.joke.a}`; // Spanish joke structure
}

const joke_card = await generateCard(
joke_content,
req.theme,
req.options,
Languages.ENGLISH
);

res.writeHead(200, {
"Content-Type": "image/svg+xml",
"Cache-Control": `public, max-age=${CARD_AGE}`,
});
res.end(joke_card);
} catch (error) {
console.error("Error:", error);
res.status(500).send("Internal Server Error");
}
});

module.exports = router;
Loading

0 comments on commit 95be1b2

Please sign in to comment.