diff --git a/README.md b/README.md index 51ddc2d..e6d4836 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Here is a list of cards that can currently be used: | `security-tips-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/security-tips-card?theme=dark)` | | `french-word-of-the-day-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/french-word-of-the-day-card)` | | `travel-destinations-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/travel-destinations-card?theme=dark)` | +| `health-tip-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/health-tip-card?theme=dark)` | ## Themes diff --git a/index.js b/index.js index bd6325c..5ab0e22 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,7 @@ const available_cards = { "/harry-potter-spell-card": require("./src/cards/harry-potter-spells"), "/travel-destinations-card": require("./src/cards/travel_destinations"), "/french-word-of-the-day-card": require("./src/cards/french_word_of_the_day"), + "/health-tip-card": require("./src/cards/health-tip-card"), }; app.use(express.json()); diff --git a/src/cards/health-tip-card.js b/src/cards/health-tip-card.js new file mode 100644 index 0000000..f56aef3 --- /dev/null +++ b/src/cards/health-tip-card.js @@ -0,0 +1,53 @@ +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/health-tips.json"; +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 === "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(); +}; + +router.get("/", handleTheme, handleOptions, async (req, res) => { + try { + const healthTips = JSON.parse(await fs.readFile(DATA_FILE_PATH, "utf8")); + const random_tip = healthTips[Math.floor(Math.random() * healthTips.length)]; + + const health_tip_card = await generateCard( + random_tip.content, + req.theme, + req.options, + Languages.ENGLISH + ); + + res.writeHead(200, { + "Content-Type": "image/svg+xml", + "Cache-Control": `public, max-age=${CARD_AGE}`, + }); + res.end(health_tip_card); + } catch (error) { + console.error("Error:", error); + res.status(500).send("Internal Server Error"); + } +}); + +module.exports = router; diff --git a/src/data/health-tips.json b/src/data/health-tips.json new file mode 100644 index 0000000..22ed690 --- /dev/null +++ b/src/data/health-tips.json @@ -0,0 +1,482 @@ +[ + { + "index": 0, + "tip": "Drink plenty of water throughout the day." + }, + { + "index": 1, + "tip": "Eat a balanced diet rich in fruits and vegetables." + }, + { + "index": 2, + "tip": "Exercise regularly, aiming for at least 30 minutes a day." + }, + { + "index": 3, + "tip": "Get enough sleep – aim for 7-8 hours per night." + }, + { + "index": 4, + "tip": "Practice good hygiene, including regular handwashing." + }, + { + "index": 5, + "tip": "Avoid smoking and excessive alcohol consumption." + }, + { + "index": 6, + "tip": "Limit your intake of processed foods and sugary snacks." + }, + { + "index": 7, + "tip": "Keep a positive outlook and manage stress effectively." + }, + { + "index": 8, + "tip": "Practice deep breathing exercises to improve lung function." + }, + { + "index": 9, + "tip": "Include fiber-rich foods in your diet for better digestion." + }, + { + "index": 10, + "tip": "Take time for yourself daily to relax and recharge." + }, + { + "index": 11, + "tip": "Practice mindfulness or meditation regularly." + }, + { + "index": 12, + "tip": "Seek professional help if you're feeling overwhelmed or anxious." + }, + { + "index": 13, + "tip": "Keep a journal to process your thoughts and emotions." + }, + { + "index": 14, + "tip": "Practice gratitude – write down things you're thankful for daily." + }, + { + "index": 15, + "tip": "Limit screen time, especially on social media." + }, + { + "index": 16, + "tip": "Stay connected with friends and family." + }, + { + "index": 17, + "tip": "Set realistic goals and celebrate small victories." + }, + { + "index": 18, + "tip": "Avoid comparing yourself to others; focus on your own journey." + }, + { + "index": 19, + "tip": "Make time for hobbies and activities you enjoy." + }, + { + "index": 20, + "tip": "Eat breakfast daily to kickstart your metabolism." + }, + { + "index": 21, + "tip": "Opt for whole grains over refined grains." + }, + { + "index": 22, + "tip": "Include lean proteins, such as chicken, fish, or tofu, in your meals." + }, + { + "index": 23, + "tip": "Limit red meat consumption." + }, + { + "index": 24, + "tip": "Eat a variety of colorful fruits and vegetables." + }, + { + "index": 25, + "tip": "Include healthy fats like olive oil, avocados, and nuts." + }, + { + "index": 26, + "tip": "Avoid sugary drinks; opt for water or herbal teas." + }, + { + "index": 27, + "tip": "Control portion sizes to avoid overeating." + }, + { + "index": 28, + "tip": "Plan your meals in advance to avoid impulsive eating." + }, + { + "index": 29, + "tip": "Limit your salt intake to maintain healthy blood pressure." + }, + { + "index": 30, + "tip": "Incorporate both cardio and strength training into your routine." + }, + { + "index": 31, + "tip": "Take the stairs instead of the elevator when possible." + }, + { + "index": 32, + "tip": "Stretch regularly to improve flexibility." + }, + { + "index": 33, + "tip": "Go for a walk after meals to aid digestion." + }, + { + "index": 34, + "tip": "Try a new physical activity, such as yoga or Pilates." + }, + { + "index": 35, + "tip": "Set fitness goals and track your progress." + }, + { + "index": 36, + "tip": "Take breaks from sitting every hour to move around." + }, + { + "index": 37, + "tip": "Warm up before exercise to prevent injury." + }, + { + "index": 38, + "tip": "Stay consistent with your workout routine." + }, + { + "index": 39, + "tip": "Don’t skip rest days; your body needs time to recover." + }, + { + "index": 40, + "tip": "Monitor your blood pressure regularly." + }, + { + "index": 41, + "tip": "Include omega-3 fatty acids in your diet for heart health." + }, + { + "index": 42, + "tip": "Avoid trans fats and limit saturated fats." + }, + { + "index": 43, + "tip": "Stay active to maintain a healthy heart." + }, + { + "index": 44, + "tip": "Reduce your stress to keep your heart healthy." + }, + { + "index": 45, + "tip": "Limit caffeine intake to avoid elevated blood pressure." + }, + { + "index": 46, + "tip": "Get regular check-ups to monitor your cholesterol levels." + }, + { + "index": 47, + "tip": "Maintain a healthy weight to reduce strain on your heart." + }, + { + "index": 48, + "tip": "Avoid smoking, as it increases the risk of heart disease." + }, + { + "index": 49, + "tip": "Stay hydrated to support overall cardiovascular health." + }, + { + "index": 50, + "tip": "Eat foods rich in vitamin C, like oranges and bell peppers." + }, + { + "index": 51, + "tip": "Get enough vitamin D through sunlight or supplements." + }, + { + "index": 52, + "tip": "Include probiotics in your diet for a healthy gut." + }, + { + "index": 53, + "tip": "Get vaccinated to prevent illness." + }, + { + "index": 54, + "tip": "Minimize stress to maintain a strong immune system." + }, + { + "index": 55, + "tip": "Eat garlic for its immune-boosting properties." + }, + { + "index": 56, + "tip": "Include zinc-rich foods, like nuts and seeds, in your diet." + }, + { + "index": 57, + "tip": "Exercise regularly to keep your immune system active." + }, + { + "index": 58, + "tip": "Practice good sleep hygiene to boost immunity." + }, + { + "index": 59, + "tip": "Avoid excessive sugar intake, which can weaken immunity." + }, + { + "index": 60, + "tip": "Consume calcium-rich foods like dairy or leafy greens." + }, + { + "index": 61, + "tip": "Get enough vitamin K from foods like broccoli and spinach." + }, + { + "index": 62, + "tip": "Do weight-bearing exercises, like walking or lifting weights." + }, + { + "index": 63, + "tip": "Stretch daily to keep joints flexible." + }, + { + "index": 64, + "tip": "Maintain a healthy weight to reduce strain on your joints." + }, + { + "index": 65, + "tip": "Include omega-3 fatty acids to reduce inflammation." + }, + { + "index": 66, + "tip": "Avoid high heels or uncomfortable shoes that can stress your joints." + }, + { + "index": 67, + "tip": "Practice good posture to reduce joint strain." + }, + { + "index": 68, + "tip": "Stay hydrated to keep your joints lubricated." + }, + { + "index": 69, + "tip": "Use sunscreen daily, even on cloudy days." + }, + { + "index": 70, + "tip": "Avoid overexertion and listen to your body's limits." + }, + { + "index": 71, + "tip": "Drink plenty of water to keep your skin hydrated." + }, + { + "index": 72, + "tip": "Eat a diet rich in antioxidants for healthy skin." + }, + { + "index": 73, + "tip": "Avoid smoking, which can damage your skin." + }, + { + "index": 74, + "tip": "Use gentle, natural skin care products." + }, + { + "index": 75, + "tip": "Get enough sleep to reduce dark circles and puffiness." + }, + { + "index": 76, + "tip": "Limit hot showers, which can dry out your skin." + }, + { + "index": 77, + "tip": "Wash your face twice a day to keep it clean." + }, + { + "index": 78, + "tip": "Use conditioner regularly for healthy hair." + }, + { + "index": 79, + "tip": "Avoid excessive heat styling to prevent hair damage." + }, + { + "index": 80, + "tip": "Brush your teeth twice daily for two minutes." + }, + { + "index": 81, + "tip": "Floss daily to remove plaque between teeth." + }, + { + "index": 82, + "tip": "Limit sugary snacks and drinks that can cause cavities." + }, + { + "index": 83, + "tip": "Visit the dentist regularly for check-ups and cleanings." + }, + { + "index": 84, + "tip": "Drink water after meals to rinse your mouth." + }, + { + "index": 85, + "tip": "Avoid tobacco products, which can damage your teeth and gums." + }, + { + "index": 86, + "tip": "Use fluoride toothpaste for added protection." + }, + { + "index": 87, + "tip": "Eat crunchy fruits and vegetables for natural teeth cleaning." + }, + { + "index": 88, + "tip": "Replace your toothbrush every three months." + }, + { + "index": 89, + "tip": "Chew sugar-free gum to stimulate saliva production." + }, + { + "index": 90, + "tip": "Get regular health screenings, such as blood pressure and cholesterol." + }, + { + "index": 91, + "tip": "Limit alcohol intake to reduce the risk of health issues." + }, + { + "index": 92, + "tip": "Keep your home and work environment clean." + }, + { + "index": 93, + "tip": "Avoid sitting for extended periods; take breaks to move around." + }, + { + "index": 94, + "tip": "Use ergonomically designed furniture to avoid strain." + }, + { + "index": 95, + "tip": "Wear sunglasses to protect your eyes from UV rays." + }, + { + "index": 96, + "tip": "Practice safe sex to prevent STIs." + }, + { + "index": 97, + "tip": "Avoid prolonged exposure to loud noises to protect your hearing." + }, + { + "index": 98, + "tip": "Quit smoking or avoid exposure to secondhand smoke." + }, + { + "index": 99, + "tip": "Follow your doctor’s advice and take medications as prescribed." + }, + { + "index": 100, + "tip": "Practice forgiveness to let go of resentment." + }, + { + "index": 101, + "tip": "Engage in positive self-talk and affirmations." + }, + { + "index": 102, + "tip": "Avoid overcommitting; learn to say no." + }, + { + "index": 103, + "tip": "Take regular digital detox breaks." + }, + { + "index": 104, + "tip": "Volunteer or help others to boost your mood." + }, + { + "index": 105, + "tip": "Laugh often – watch a comedy or read a funny book." + }, + { + "index": 106, + "tip": "Accept your flaws and embrace imperfection." + }, + { + "index": 107, + "tip": "Make a habit of learning something new." + }, + { + "index": 108, + "tip": "Focus on your breathing to calm your mind." + }, + { + "index": 109, + "tip": "Take time to appreciate nature regularly." + }, + { + "index": 110, + "tip": "Set a regular bedtime and wake-up time." + }, + { + "index": 111, + "tip": "Avoid caffeine and heavy meals before bed." + }, + { + "index": 112, + "tip": "Make your bedroom a calm and relaxing environment." + }, + { + "index": 113, + "tip": "Limit screen time before bedtime." + }, + { + "index": 114, + "tip": "Avoid napping during the day to improve nighttime sleep." + }, + { + "index": 115, + "tip": "Create a bedtime routine to signal your body it's time for sleep." + }, + { + "index": 116, + "tip": "Use a comfortable mattress and pillows." + }, + { + "index": 117, + "tip": "Keep your bedroom cool and dark." + }, + { + "index": 118, + "tip": "Practice relaxation techniques, like reading or deep breathing." + }, + { + "index": 119, + "tip": "Don’t watch the clock if you can’t fall asleep; focus on relaxation." + } +] \ No newline at end of file diff --git a/src/help.js b/src/help.js index 6d2976b..1c0e036 100644 --- a/src/help.js +++ b/src/help.js @@ -340,6 +340,15 @@ router.get("/", (req, res) => { example: [`${baseurl}/travel-destinations-card`], }, }, + "health-tip-card": { + info: "Generates a random health tips for your good health", + api: { + args: { + theme: "Theme of card. All themes. Default: dark [Optional]", + }, + example: [`${baseurl}/health-tip-card`], + }, + }, }; res.json({ themes, cards });