* Migrate from static HTML/JS to Haskell/Scotty web application * Add server-side routing and API endpoints * Implement language switching and command processing * Set up project structure with stack * Move static assets to dedicated directory * Add type definitions and template rendering
114 lines
7.1 KiB
Haskell
114 lines
7.1 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Routes where
|
|
|
|
import Web.Scotty
|
|
import Data.Text.Lazy (Text)
|
|
import qualified Data.Text.Lazy as TL
|
|
import Data.Map.Strict (Map)
|
|
import qualified Data.Map.Strict as Map
|
|
import Control.Monad.IO.Class
|
|
import Network.HTTP.Types.Status
|
|
import Data.Aeson (ToJSON, object, (.=))
|
|
import Templates
|
|
import Types
|
|
|
|
indexHandler :: ActionM ()
|
|
indexHandler = do
|
|
html $ renderIndex French
|
|
|
|
commandHandler :: ActionM ()
|
|
commandHandler = do
|
|
cmd <- param "cmd" :: ActionM Text
|
|
langParam <- (param "lang" :: ActionM Text) `rescue` (\_ -> return "fr")
|
|
let lang = if langParam == "en" then English else French
|
|
let response = processCommand cmd lang
|
|
json response
|
|
|
|
languageHandler :: ActionM ()
|
|
languageHandler = do
|
|
langParam <- param "lang" :: ActionM Text
|
|
let lang = if langParam == "en" then English else French
|
|
let response = CommandResponse (getTranslation "languageChanged" lang) False
|
|
json response
|
|
|
|
processCommand :: Text -> Language -> CommandResponse
|
|
processCommand "help" lang =
|
|
let helpText = getTranslation "availableCommands" lang <> "\n\n" <>
|
|
"help: " <> getTranslation "help" lang <> "\n" <>
|
|
"about: " <> getTranslation "about" lang <> "\n" <>
|
|
"skills: " <> getTranslation "skills" lang <> "\n" <>
|
|
"projects: " <> getTranslation "projects" lang <> "\n" <>
|
|
"contact: " <> getTranslation "contact" lang <> "\n" <>
|
|
"clear: " <> getTranslation "clear" lang <> "\n" <>
|
|
"language: " <> getTranslation "language" lang
|
|
in CommandResponse helpText False
|
|
|
|
processCommand "about" lang = CommandResponse (getCommandResponse "about" lang) False
|
|
processCommand "skills" lang = CommandResponse (getCommandResponse "skills" lang) False
|
|
processCommand "projects" lang = CommandResponse (getCommandResponse "projects" lang) True
|
|
processCommand "contact" lang = CommandResponse (getCommandResponse "contact" lang) True
|
|
|
|
processCommand cmd lang =
|
|
let errorMsg = getTranslation "commandNotRecognized" lang
|
|
errorMsgWithCmd = TL.replace "{0}" cmd errorMsg
|
|
in CommandResponse errorMsgWithCmd False
|
|
|
|
getTranslation :: TranslationKey -> Language -> Text
|
|
getTranslation key lang =
|
|
case lang of
|
|
French -> Map.findWithDefault "Translation missing" key frenchTranslations
|
|
English -> Map.findWithDefault "Translation missing" key englishTranslations
|
|
|
|
getCommandResponse :: Text -> Language -> Text
|
|
getCommandResponse cmd lang =
|
|
case lang of
|
|
French -> Map.findWithDefault "Response missing" cmd frenchResponses
|
|
English -> Map.findWithDefault "Response missing" cmd englishResponses
|
|
|
|
frenchTranslations :: Translation
|
|
frenchTranslations = Map.fromList
|
|
[ ("welcome", "Bienvenue dans le Portfolio de Thomas Brasdefer.\nTapez 'help' pour voir la liste des commandes disponibles. Type 'language' to switch to English.")
|
|
, ("help", "Affiche la liste des commandes disponibles")
|
|
, ("about", "À propos de moi")
|
|
, ("skills", "Mes compétences")
|
|
, ("projects", "Mes projets")
|
|
, ("contact", "Mes coordonnées")
|
|
, ("clear", "Efface l'écran")
|
|
, ("language", "Change la langue (fr/en)")
|
|
, ("languageChanged", "Langue changée en français")
|
|
, ("commandNotRecognized", "Commande non reconnue: {0}. Tapez 'help' pour voir la liste des commandes.")
|
|
, ("availableCommands", "Commandes disponibles:")
|
|
]
|
|
|
|
englishTranslations :: Translation
|
|
englishTranslations = Map.fromList
|
|
[ ("welcome", "Welcome to Thomas Brasdefer's Portfolio.\nType 'help' to see the list of available commands. Tapez 'language' pour passer en français.")
|
|
, ("help", "Display the list of available commands")
|
|
, ("about", "About me")
|
|
, ("skills", "My skills")
|
|
, ("projects", "My projects")
|
|
, ("contact", "My contact information")
|
|
, ("clear", "Clear the screen")
|
|
, ("language", "Change language (fr/en)")
|
|
, ("languageChanged", "Language changed to English")
|
|
, ("commandNotRecognized", "Command not recognized: {0}. Type 'help' to see the list of commands.")
|
|
, ("availableCommands", "Available commands:")
|
|
]
|
|
|
|
frenchResponses :: Map Text Text
|
|
frenchResponses = Map.fromList
|
|
[ ("about", "Actuellement élève ingénieur en informatique, je suis particulièrement intéressé par le développement bas niveau, la programmation logique, la cybersécurité, la cryptographie et ,dans une certaine mesure, l'intelligence artificielle. Je suis plutôt sensible aux questions de l'open source et du logiciel libre.\n\nJe cultive également un certain intérêt pour la philosophie « classique », plus particulièrement la philosophie aristotélicienne et scolastique.\nJe suis aussi assez friand de l'histoire de France lors du XIIe siècle (la « Renaissance du Moyen Âge ») et plus largement lors du reigne de la dynastie des Capétiens direct.\nMais je dois admettre que, les années n'aidant pas, j'ai de moins en moins de temps à consacrer à ces sujets.")
|
|
, ("skills", "Langages:\n- C\n- Java\n- Python\n- Prolog\n- HTML/CSS/Javascript/PHP\n\nFrameworks:\n- Flask\n- Spring Boot\n\nOutils:\n- Git\n- Docker\n\n Systèmes:\n- Linux (Debian/Ubuntu/Arch)\n- Windows")
|
|
, ("projects", "1. <a href='https://gitea.hexasec.io/tombdf/Portfolio' target='_blank'>Ce portfolio</a> (HTML, CSS, JavaScript)\n2. <a href='' target='_blank'>Générateur de documentation Prolog</a> (Prolog)\n3. <a href='https://gitea.hexasec.io/tombdf/ComGen.git' target='_blank'>Générateur de commentaire de documentation</a> (Python)")
|
|
, ("contact", "Email: <a href='mailto:thomas@hexasec.io'>thomas@hexasec.io</a>\nLinkedIn: <a href='https://www.linkedin.com/in/thomas-brasdefer-2ab818275' target='_blank'>Thomas Brasdefer</a>\nGitea: <a href='https://gitea.hexasec.io/tombdf' target='_blank'>tombdf</a>")
|
|
]
|
|
|
|
englishResponses :: Map Text Text
|
|
englishResponses = Map.fromList
|
|
[ ("about", "Currently a student in computer engineering, I'm particularly interested in low-level programming, logic programming, cybersecurity, cryptography and, to a certain extent, artificial intelligence. I'm very interested in open source and free software.\n\nI also cultivate a certain interest in \"classical\" philosophy, particularly Aristotelian and Scholastic philosophy.\nI'm also quite fond of French history during the 12th century (the \"Renaissance of the Middle Ages\") and more broadly during the reign of the direct Capetian dynasty.\nBut I have to admit that, as the years go by, I have less and less time to devote to these subjects.")
|
|
, ("skills", "Languages:\n- C\n- Java\n- Python\n- Prolog\n- HTML/CSS/Javascript/PHP\n\nFrameworks:\n- Flask\n- Spring Boot\n\nTools:\n- Git\n- Docker\n\n OS:\n- Linux (Debian/Ubuntu/Arch)\n- Windows")
|
|
, ("projects", "1. <a href='https://gitea.hexasec.io/tombdf/Portfolio' target='_blank'>This portfolio</a> (HTML, CSS, JavaScript)\n2. <a href='' target='_blank'>Prolog documentation generator</a> (Prolog)\n3. <a href='https://gitea.hexasec.io/tombdf/ComGen.git' target='_blank'>Comments generator</a> (Python)")
|
|
, ("contact", "Email: <a href='mailto:thomas@hexasec.io'>thomas@hexasec.io</a>\nLinkedIn: <a href='https://www.linkedin.com/in/thomas-brasdefer-2ab818275' target='_blank'>Thomas Brasdefer</a>\nGitea: <a href='https://gitea.hexasec.io/tombdf' target='_blank'>tombdf</a>")
|
|
]
|