#!/usr/bin/env runhaskell {-# OPTIONS -fglasgow-exts #-} -- ^ pattern type annotions -- -- Copyright (c) 2006 Don Stewart - http://www.cse.unsw.edu.au/~dons -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License as -- published by the Free Software Foundation; either version 2 of -- the License, or (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- -- Read in issue skeletons, generating html, wiki and txt versions, -- and updating the announce page. -- import Data.List import Text.PrettyPrint hiding (quotes) import Text.Printf import Control.Monad import System.Environment import System.Locale import System.Time import System.Cmd import System.Exit import System.IO import System.Directory import Control.Concurrent import Control.Exception import Debug.Trace import qualified Data.ByteString.Char8 as B -- -- The HWN data type -- data HWN = HWN { editorial :: (Maybe Editorial) , announce :: Announce , haskellprime :: HaskellPrime , libraries :: Libraries , hackage :: Hackage , conferences :: Conferences , discussion :: Discussion , jobs :: Jobs , blogs :: Blogs , quotes :: Quotes , commits :: Commits } deriving (Read,Show) type Editorial = String -- hwn sections newtype Announce = Announce [Item] deriving (Read,Show) newtype Jobs = Jobs [Item] deriving (Read,Show) newtype Discussion = Discussion [Item] deriving (Read,Show) newtype HaskellPrime = HaskellPrime [Link] deriving (Read,Show) newtype Libraries = Libraries [Link] deriving (Read,Show) newtype Hackage = Hackage [HackageItem] deriving (Read,Show) newtype Quotes = Quotes [Quote] deriving (Read,Show) newtype Commits = Commits [Commit] deriving (Read,Show) newtype Blogs = Blogs [Link] deriving (Read,Show) data Conferences = Conferences (Maybe Title) [Link] deriving (Read,Show) type Title = String type Author = String type Body = String newtype Text = Text String deriving (Read,Show) type Who = String type Url = String type Date = String -- an item about something someone's done. data Item = Item Title Author Body deriving (Read,Show) data HackageItem = HackageItem Title Author Body deriving (Read,Show) data Quote = Quote Who Body deriving (Read,Show) data Link = Link Url Body deriving (Read,Show) data Commit = Commit Date Author Body deriving (Read,Show) -- and an issue type newtype Issue = Issue Int deriving (Read,Show) -- -- supported formats -- data Fmt = Html | Wiki | TeX -- a mini pretty printer class class Pretty a where ppr :: Fmt -> a -> Doc ------------------------------------------------------------------------ -- -- document header -- header :: Issue -> CalendarTime -> Fmt -> Doc header _ ct Wiki = (wikiquote $ text $ formatCalendarTime defaultTimeLocale "%Y-%m-%d" ct) <> char '\n' header (Issue n) ct TeX = vcat [ text "\\documentclass[a4paper]{article}" , text "\\pagestyle{empty}" , text "\\usepackage{url}" , text "\\usepackage{multicol}" , text "\\usepackage[left=1.8cm,top=4cm,bottom=2cm,right=1.8cm,nohead,nofoot]{geometry}" , text "\\usepackage{sectsty}" , text "\\usepackage{relsize}" , text "\\allsectionsfont{\\sffamily\\raggedright}" , text "\\begin{document}" , text "\\begin{figure}[t]" , text "\\hspace{0.2cm}" , text "\\begin{minipage}[t]{.55\\textwidth}" , text "\\flushleft" , text "\\Huge\\textbf{Haskell Weekly News}" , text "\\end{minipage}" , text "\\hfill" , text "\\raisebox{0.4cm}{" , text "\\begin{minipage}[t]{.40\\textwidth}" , text "\\flushright" , text $ (printf "Issue %d, " n) ++ (formatCalendarTime defaultTimeLocale "%B %d, %Y" ct) ++ "\\\\" , text "\\url{http://sequence.complete.org/}" , text "\\end{minipage}" , text "}" , text "\\hspace{0.5cm}" , text "\\hrule" , text "\\vspace{0.5cm}" , text "\\end{figure}" , text "\\setlength{\\columnsep}{0.5cm}" , text "\\setlength{\\multicolsep}{1cm}" , text "\\begin{multicols}{2}" , text "\\setcounter{unbalance}{3}" , text "\\raggedcolumns" ] header (Issue n) ct Html = prefix $$ empty $$ p ( text "Welcome to issue" <+> int n <+> text "of HWN, a newsletter covering" $$ text "developments in the " <> (ppr Html (Link "http://haskell.org/" "Haskell")) <> text " community.") $$ empty where prefix = angle (text "!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"") $$ (text "" <> (text "
") <> (tag "title" $ text ("Haskell Weekly News: "++show date)) <> text "" <> angle (text "body")) date = text $ formatCalendarTime defaultTimeLocale "%B %d, %Y" ct ------------------------------------------------------------------------ -- -- document footer -- footer :: CalendarTime -> Fmt -> Doc footer _ Wiki = text "\n[[Old news|More news]]" footer _ TeX = vcat [ text "\\end{multicols}" , text "\\vspace*{\\fill}" , text "\\hrule" , text "\\hspace{0.5cm}" , text "\\flushleft" , text "\\begin{minipage}[t]{\\textwidth}" , text "\\flushleft" , text "\\textbf{Choose higher order, polymorphic and purely functional. Choose Haskell.} \\\\" , text "\\url{http://haskell.org/} \\\\" , text "\\end{minipage}" , text "\\end{document}" ] footer ct Html = tag "h4" (text "About the Haskell Weekly News") $$ empty $$ p ( text "New" <+> text "editions are posted to" $$ ppr Html (Link "http://www.haskell.org/mailman/listinfo/haskell" "the Haskell mailing list") $$ text "as well as to" $$ ppr Html (Link "http://sequence.complete.org/" "the Haskell Sequence") <+> text "and" $$ ppr Html (Link "http://planet.haskell.org/" "Planet Haskell") <> text "." $$ ppr Html (Link "http://sequence.complete.org/node/feed" "RSS") $$ text "is also available, and headlines appear on" <+> ppr Html (Link "http://haskell.org" "haskell.org") <> text "." <+> text "Headlines are available as" <+> (ppr Html (Link ("http://www.cse.unsw.edu.au/~dons/code/hwn/archives/" ++ date) "PDF")) <> text "." ) $$ p ( text "To help create new editions of this newsletter, please" $$ text "see the" <+> text "contributing" $$ text "information. Send stories to" <+> tag "code" (text "dons at galois.com") <> text "." $+$ text "The darcs repository is available at" <+> tag "code" (text "darcs get" <+> ppr Html (Link "http://www.cse.unsw.edu.au/~dons/code/hwn" "http://www.cse.unsw.edu.au/~dons/code/hwn"))) $$ text "" $$ text "