Skip to content

Commit

Permalink
Merge pull request #75 from Sameera-05/master
Browse files Browse the repository at this point in the history
Created Fun Fact Card
  • Loading branch information
akanshSirohi authored Oct 11, 2024
2 parents 4697ea7 + d9e69ec commit 093d1ee
Show file tree
Hide file tree
Showing 7 changed files with 628 additions and 226 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ Here is a list of cards that can currently be used:
| `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) |

| `fun-fact-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/fun-fact-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/fun-fact-card?theme=dark) |

| `github-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/github-facts-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/github-facts-card?theme=dark) |
| `random-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-facts-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-facts-card?theme=dark) |


## Themes

### Options
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const available_cards = {
"/spanish-quote-card": require("./src/cards/spanish-quote"),
"/top-tweets-card": require("./src/cards/top-tweets"),
"/github-facts-card": require("./src/cards/github-facts"),
"/random-facts-card": require("./src/cards/random-facts")
"/random-facts-card": require("./src/cards/random-facts"),
"/fun-fact-card": require("./src/cards/fun-fact-card"),
};

app.use(express.json());
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"node" : ">=16.0.0"
},
"dependencies": {
"axios": "^1.7.7",
"canvas": "2.11.2",
"express": "^4.21.1",
"satori": "^0.11.2",
"satori-html": "^0.3.2"
}
}
}
56 changes: 56 additions & 0 deletions src/cards/fun-fact-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// src/cards/fun-fact-card.js
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/fun_facts.json";
const DEFAULT_THEME = "light";

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

// Middleware to handle options like custom themes
const handleOptions = (req, res, next) => {
if (req.theme === "my_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();
};

// Route to display fun fact card
router.get("/", handleTheme, handleOptions, async (req, res) => {
try {
const facts = JSON.parse(await fs.readFile(DATA_FILE_PATH, "utf8"));
const random_fact = facts[Math.floor(Math.random() * facts.length)];

const fact_card = await generateCard(
random_fact.fact,
req.theme,
req.options,
Languages.ENGLISH
);

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

module.exports = router;
305 changes: 305 additions & 0 deletions src/data/fun_facts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
[
{
"fact": "Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible."
},
{
"fact": "Bananas are berries, but strawberries are not."
},
{
"fact": "A day on Venus is longer than a year on Venus."
},
{
"fact": "Sharks have been around longer than trees."
},
{
"fact": "Octopuses have three hearts."
},
{
"fact": "An adult human has 206 bones, but a newborn baby has around 270."
},
{
"fact": "Wombat poop is cube-shaped."
},
{
"fact": "There are more stars in the universe than grains of sand on Earth."
},
{
"fact": "Cows have best friends and can become stressed when separated from them."
},
{
"fact": "Humans share 60% of their DNA with bananas."
},
{
"fact": "It takes 8 minutes and 20 seconds for light from the Sun to reach Earth."
},
{
"fact": "Butterflies taste with their feet."
},
{
"fact": "The Eiffel Tower can grow more than 6 inches during the summer due to the expansion of iron in the heat."
},
{
"fact": "The unicorn is the national animal of Scotland."
},
{
"fact": "Humans are the only animals that blush."
},
{
"fact": "The smell of freshly cut grass is actually a plant distress signal."
},
{
"fact": "A single teaspoon of honey represents the life work of 12 bees."
},
{
"fact": "Koalas sleep up to 22 hours a day."
},
{
"fact": "A group of flamingos is called a 'flamboyance'."
},
{
"fact": "The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after 38 minutes."
},
{
"fact": "Slugs have four noses."
},
{
"fact": "There are more trees on Earth than stars in the Milky Way galaxy."
},
{
"fact": "A bolt of lightning contains enough energy to toast 100,000 slices of bread."
},
{
"fact": "Elephants are the only animals that can't jump."
},
{
"fact": "A crocodile cannot stick its tongue out."
},
{
"fact": "An ostrich's eye is bigger than its brain."
},
{
"fact": "Tomatoes were once considered poisonous in Europe."
},
{
"fact": "There are more fake flamingos in the world than real flamingos."
},
{
"fact": "Hot water freezes faster than cold water, known as the Mpemba effect."
},
{
"fact": "The world's smallest reptile was discovered in 2021. It is a tiny chameleon that fits on the tip of a finger."
},
{
"fact": "Sea otters hold hands while sleeping to avoid drifting apart."
},
{
"fact": "If you lift a kangaroo’s tail off the ground, it can't hop."
},
{
"fact": "The heart of a shrimp is located in its head."
},
{
"fact": "The human nose can detect over 1 trillion different scents."
},
{
"fact": "A snail can sleep for three years."
},
{
"fact": "There is only one letter that doesn't appear in any U.S. state name: Q."
},
{
"fact": "Polar bears have black skin under their white fur."
},
{
"fact": "The inventor of the Frisbee was turned into a Frisbee after he died."
},
{
"fact": "The wood frog can hold its pee for up to eight months."
},
{
"fact": "The longest hiccuping spree lasted for 68 years."
},
{
"fact": "Tigers have striped skin, not just striped fur."
},
{
"fact": "The average person will spend six months of their life waiting for red lights to turn green."
},
{
"fact": "A group of owls is called a parliament."
},
{
"fact": "A jiffy is an actual unit of time—1/100th of a second."
},
{
"fact": "The blob of toothpaste that sits on your toothbrush is called a 'nurdle.'"
},
{
"fact": "Dolphins have names for each other."
},
{
"fact": "Humans and giraffes have the same number of neck vertebrae—seven."
},
{
"fact": "The average human body contains enough fat to make seven bars of soap."
},
{
"fact": "The Great Wall of China is not visible from space without aid."
},
{
"fact": "Your fingernails grow faster on your dominant hand."
},
{
"fact": "Cows have almost 360-degree panoramic vision."
},
{
"fact": "Dragonflies have six legs but can't walk."
},
{
"fact": "It’s impossible to hum while holding your nose."
},
{
"fact": "The Empire State Building has its own zip code."
},
{
"fact": "One piece of space junk returns to Earth every day."
},
{
"fact": "Venus is the only planet in the solar system that rotates clockwise."
},
{
"fact": "Carrots were originally purple, not orange."
},
{
"fact": "A group of porcupines is called a 'prickle.'"
},
{
"fact": "The average human sheds around 600,000 particles of skin every hour."
},
{
"fact": "The Guinness World Record for the longest hiccuping spree lasted for 68 years."
},
{
"fact": "In Switzerland, it is illegal to own just one guinea pig."
},
{
"fact": "Apples float because they are 25% air."
},
{
"fact": "Walt Disney was afraid of mice."
},
{
"fact": "The dot over the letter 'i' and 'j' is called a 'tittle.'"
},
{
"fact": "Bees can recognize human faces."
},
{
"fact": "It takes a photon 40,000 years to travel from the core of the Sun to its surface, but only 8 minutes to reach Earth."
},
{
"fact": "Squirrels plant thousands of new trees each year simply by forgetting where they put their acorns."
},
{
"fact": "Sloths can take up to a month to digest a single leaf."
},
{
"fact": "Pineapples were so expensive when they first arrived in Europe that people would rent them for parties."
},
{
"fact": "The longest place name on the planet is 85 letters long."
},
{
"fact": "Giraffes have no vocal cords."
},
{
"fact": "The average person walks the equivalent of five times around the world in their lifetime."
},
{
"fact": "There are more cells of bacteria in your body than there are human cells."
},
{
"fact": "Wombat poop is cube-shaped to prevent it from rolling away."
},
{
"fact": "The oceans contain enough salt to cover all the continents in nearly 500 feet of salt."
},
{
"fact": "Human thigh bones are stronger than concrete."
},
{
"fact": "A day on Mercury lasts 1,408 hours."
},
{
"fact": "Elephants are the only animals that can’t jump."
},
{
"fact": "The oldest 'your mom' joke was discovered on a 3,500-year-old Babylonian tablet."
},
{
"fact": "Cows moo in regional accents."
},
{
"fact": "Ants don’t sleep."
},
{
"fact": "Sharks are older than the rings of Saturn."
},
{
"fact": "The inventor of the match died by setting himself on fire."
},
{
"fact": "A group of jellyfish is called a 'smack.'"
},
{
"fact": "A group of crows is called a 'murder.'"
},
{
"fact": "It is physically impossible for pigs to look up into the sky."
},
{
"fact": "A crocodile can’t stick out its tongue."
},
{
"fact": "An eagle can kill a young deer and fly away with it."
},
{
"fact": "Penguins propose to their mates with a pebble."
},
{
"fact": "The average person spends six months of their lifetime waiting for a red light to turn green."
},
{
"fact": "A giraffe's tongue is so long it can lick its own ears."
},
{
"fact": "Octopuses have blue blood and nine brains."
},
{
"fact": "When in danger, the sea cucumber expels its internal organs."
},
{
"fact": "Tarantulas can survive for more than two years without food."
},
{
"fact": "Banging your head against a wall burns 150 calories an hour."
},
{
"fact": "If you sneeze too hard, you can fracture a rib."
},
{
"fact": "An apple, potato, and onion all taste the same if you eat them with your nose plugged."
},
{
"fact": "There are more cells of bacteria in your body than there are human cells."
},
{
"fact": "Wombat poop is cube-shaped to prevent it from rolling away."
},
{
"fact": "The oceans contain enough salt to cover all the continents in nearly 500 feet of salt."
},
{
"fact": "Human thigh bones are stronger than concrete."
}
]
Loading

0 comments on commit 093d1ee

Please sign in to comment.