packages feed

html-presentation-text-0.1.0.0: Main.hs

-- |
-- Module      :  Main
-- Copyright   :  (c) OleksandrZhabenko 2022
-- License     :  MIT
-- Stability   :  Experimental
-- Maintainer  :  olexandr543@yahoo.com
--
-- Simple tool to create html presentation for text. The html and css template is taken from different tutorials
-- in the Internet (with changes). The idea is to post some text on the background partially transparent image.

module Main where

import Data.Lists.FLines (newLineEnding)
import System.Environment (getArgs)
import CLI.Arguments
import CLI.Arguments.Parsing
import CLI.Arguments.Get
import Data.Monoid (mconcat,mappend)

main :: IO ()
main = do
  args <- getArgs
  let argsB = fst . takeBsR bSpecs $ args
      file = mconcat . getB "f" $ argsB
      image = mconcat . getB "i" $ argsB
      header = (\ts -> if null ts then "Заголовок" else ts) . mconcat . getB "h" $ argsB
      top = (\ts -> if null ts then "20" else ts) . mconcat . getB "t" $ argsB
      right = (\ts -> if null ts then "20" else ts) . mconcat . getB "r" $ argsB
      paddingleftright = (\ts -> if null ts then "15" else ts) . mconcat . getB "p" $ argsB
      fontsize = (\ts -> if null ts then "100" else ts) . mconcat . getB "s" $ argsB
      opacity = (\ts -> if null ts then "0.5" else ts) . mconcat . getB "o" $ argsB
      width = (\ts -> if null ts then "1080" else ts) . mconcat . getB "w" $ argsB
      maxwidth = (\ts -> if null ts then "100" else ts) . mconcat . getB "m" $ argsB
      backgroundcolor = (\ts -> if null ts then "#025abb" else ts) . mconcat . getB "b" $ argsB
      color = (\ts -> if null ts then "#fed501" else ts) . mconcat . getB "c" $ argsB
  text <- readFile file
  let lineS = concatMap (\xs -> "    " `mappend` xs `mappend` "<br>" `mappend` newLineEnding) . lines $ text
  appendFile (header ++ ".html") $ mconcat ["<!DOCTYPE html>", newLineEnding, "<html>", newLineEnding,
    "<head>", newLineEnding, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",
    newLineEnding, "<style>", newLineEnding, ".container {", newLineEnding, "  position: relative;",
    newLineEnding, "  font-family: Helvetica, sans-serif;", newLineEnding, "}", newLineEnding, newLineEnding,
    ".text-block {", newLineEnding, "  position: absolute;", newLineEnding, "  top: ", top, "px;",
    newLineEnding, "  right: ", right, "px;", newLineEnding, "  background-color: ",
    backgroundcolor, ";", newLineEnding, "  color: ",
    color, ";", newLineEnding, "  line-height: 161.8%;", newLineEnding,
    "  padding-left: ", paddingleftright, "px;", newLineEnding, "  padding-right: ", paddingleftright,
    "px;", newLineEnding, "  font-size: ", fontsize, "%;", newLineEnding, "}", newLineEnding, "</style>",
    newLineEnding, "</head>", newLineEnding, "<body>", newLineEnding, "", newLineEnding, "<h2>", header,
    "</h2>", newLineEnding, "<div class=\"container\">", newLineEnding, "  <img src=", show image, " alt=",
    show header, " style=\"opacity: ", opacity, "; max-width: ", maxwidth, "%;\">", newLineEnding,
    "  <div class=\"text-block\">", newLineEnding, "    <h4>", header, "</h4>", newLineEnding, "    <p>",
    newLineEnding] `mappend` lineS `mappend` mconcat ["    </p>", newLineEnding, "  </div>", newLineEnding,
    "</div>", newLineEnding, "", newLineEnding, "</body>", newLineEnding, "</html>", newLineEnding]

bSpecs = zip ["f","i","h","t","r","p","s","o","w","m","b","c"] . cycle $ [1]