Recently I wanted to refer to a Haskell package at Hackage in a paper
and I thought it would be a good idea to automatically generate BibTeX
entries for every uploaded package. I have attached a module that
generates a BibTeX entry from the upload time and the package
description. It will still need some fine tuning, e.g. LaTeX escapes for
non-ASCII characters.
I have pulled the hackage-scripts package to my machine and like to know
where to add something - if the feature is wanted, at all. I expect that
the BibTeX entry should be generated at upload time and should be
mentioned in the main package page if it exists.
module BibTeX where
import Data.Char ( toLower )
import Data.Version ( showVersion )
import qualified Distribution.PackageDescription as PkgD
import qualified Distribution.Package as Pkg
import qualified Distribution.Verbosity as Verbosity
import Distribution.PackageDescription
( PackageDescription, )
import Distribution.Package ( PackageIdentifier(..) )
import Distribution.PackageDescription.Parse
( readPackageDescription, )
import System.Time ( getClockTime,
CalendarTime, toCalendarTime, ctYear, ctMonth, )
import Util ( packageURL, )
fromPackage :: CalendarTime -> PackageDescription -> String
fromPackage time pkg =
let author = takeWhile ('<' /=) (PkgD.author pkg)
surname =
let nameParts = words author
in if null nameParts
then ""
else last nameParts
pkgId = PkgD.package pkg
Pkg.PackageName name = Pkg.pkgName pkgId
year = ctYear time
in unlines $
("@Misc{" ++ map toLower surname ++ show year ++ name ++ ",") :
map (\(field,value) -> " " ++ field ++ " = {" ++ value ++ "},") (
("author", author) :
("title", "{" ++ name ++ ": " ++ PkgD.synopsis pkg ++ "}") :
("howpublished", "\\url{http://hackage.haskell.org" ++ packageURL (PkgD.package pkg) ++ "}") :
("year", show year) :
("month", show (ctMonth time)) :
("version", showVersion (Pkg.pkgVersion pkgId)) :
("keywords", "Haskell, " ++ PkgD.category pkg ) :
[]) ++
"}" :
[]
example :: IO ()
example =
do now <- toCalendarTime =<< getClockTime
pkg <- readPackageDescription Verbosity.silent "example.cabal"
putStrLn (fromPackage now (PkgD.packageDescription pkg))
_______________________________________________
cabal-devel mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cabal-devel