Browse Source

cleanup and comments and soykaf

hakyll-refactor
Shaun Kerr 5 years ago
parent
commit
67f908a672
71 changed files with 122 additions and 26 deletions
  1. +15
    -0
      Config.hs
  2. +18
    -0
      Format.hs
  3. +9
    -0
      Packs.hs
  4. +41
    -0
      State.hs
  5. +26
    -0
      Timestamp.hs
  6. +9
    -2
      ViewUtils.hs
  7. +0
    -0
      old/ChangeLog.md
  8. +0
    -0
      old/Setup.hs_
  9. +0
    -22
      old/State.hs
  10. +0
    -0
      old/_cache/02ffd36321aca0d8196095fa897a7038
  11. +0
    -0
      old/_cache/12991168de6a9db452e49f2814dc4837
  12. +0
    -0
      old/_cache/13318c2b4a591b8f412f367f81df20d6
  13. +0
    -0
      old/_cache/18bc831854684ac860e2cfa4e9301159
  14. +0
    -0
      old/_cache/21253358050819032165ae7515d3cfb6
  15. +0
    -0
      old/_cache/2c4bf143a0d65180ae3fe8595281bb5d
  16. +0
    -0
      old/_cache/2cc6229282889d93740fc5c44e426c43
  17. +0
    -0
      old/_cache/3234241ee02d543d0cdc0eecf6b7f701
  18. +0
    -0
      old/_cache/3502f2aa291df768b503711e91da7f94
  19. +0
    -0
      old/_cache/36f9964be8b4f357c1d80cfdc525df89
  20. +0
    -0
      old/_cache/3aa7c8fae80d374ec9a40c7a9116a08f
  21. +0
    -0
      old/_cache/41623fed16032ec0baf01c53a86cce9f
  22. +0
    -0
      old/_cache/5186f0e1b9013dffb631b7ac1daee0ff
  23. +0
    -0
      old/_cache/58a0023be224362f3c70e834c2890dab
  24. +0
    -0
      old/_cache/5a2f2185fd6eb7526e285f6845fb2711
  25. +0
    -0
      old/_cache/5e52357749f41a8425ceca375f580db8
  26. +0
    -0
      old/_cache/65d86825c80bb51fe28215cbbdc72f9c
  27. +0
    -0
      old/_cache/6b13d4c109d24e3df78f6283afdafd71
  28. +0
    -0
      old/_cache/74ad07f6399cddcf5e93a42176e6ff4a
  29. +0
    -0
      old/_cache/7a9e11cb9751d5e2c28f172e49a740f3
  30. +0
    -0
      old/_cache/7eebc8997569f57e9fd6bcfa43ee6244
  31. +0
    -0
      old/_cache/81d1b6c2c1cab5cdfc34988853034e75
  32. +0
    -0
      old/_cache/8202fa021d8183dcb2050787d67fa9ed
  33. +0
    -0
      old/_cache/8c2cc830d6d96619afd7f817c883e2cb
  34. +0
    -0
      old/_cache/8e5ffdf6c89ed1aa49301aa3a00a2add
  35. +0
    -0
      old/_cache/9861f58ae8a49766ccd8f33085c3ba42
  36. +0
    -0
      old/_cache/a2e2c78a44d784b0fd8ff02b6324dc02
  37. +0
    -0
      old/_cache/a8e78f0ff3815d8ef9ed987a4625aeb3
  38. +0
    -0
      old/_cache/b324eb6b5a5bbd10b5a71240f7edcd71
  39. +0
    -0
      old/_cache/b55ed8f8472b848711dbd0caa2920e4f
  40. +0
    -0
      old/_cache/c24ef28b2ac6c9fe797b11c5d68599ff
  41. +0
    -0
      old/_cache/cedbb457a9c3e70e2341381194664a42
  42. +0
    -0
      old/_cache/d5c19886a5497f571c624d44ba520d2b
  43. +0
    -0
      old/_cache/dbb2e29497bc6a4d9f381f8003dc0e29
  44. +0
    -0
      old/_cache/e4b9b8633ce1170f36e573786e855a55
  45. +0
    -0
      old/_cache/ed9c302a44a035e5579daccaf55007fa
  46. +0
    -0
      old/_cache/f38c8240d33ea73352ba3bbc7036a71f
  47. +0
    -0
      old/_site/about/index.html
  48. +0
    -0
      old/_site/contact/index.html
  49. +0
    -0
      old/_site/css/default.css
  50. +0
    -0
      old/_site/description/index.html
  51. +0
    -0
      old/_site/humans.txt
  52. +0
    -0
      old/_site/robots.txt
  53. +0
    -0
      old/about.md
  54. +0
    -0
      old/contact.md
  55. +0
    -0
      old/css/default.css
  56. +0
    -0
      old/default.nix
  57. +0
    -0
      old/description.md
  58. +0
    -0
      old/humans.txt
  59. +0
    -0
      old/icons/favicon.svg
  60. +0
    -0
      old/p7.cabal
  61. +0
    -0
      old/p7.nix
  62. +0
    -0
      old/rf.nix
  63. +0
    -0
      old/robots.txt
  64. +0
    -0
      old/shell.nix
  65. +4
    -2
      old/site.hs
  66. +0
    -0
      old/templates/archive.html
  67. +0
    -0
      old/templates/default.html
  68. +0
    -0
      old/templates/format.html
  69. +0
    -0
      old/templates/index.html
  70. +0
    -0
      old/templates/post-list.html
  71. +0
    -0
      old/templates/post.html

old/Config.hs → Config.hs View File

@@ -1,19 +1,34 @@
module Config where
{---
- Config Module
-
- Contains settings that will effect the running of the program
-
- Shaun Kerr
-}
import System.Random
import State
import Timestamp
import Packs
-- Earliest rotation.
-- Each format is generated starting from this date.
genesis :: Timestamp
genesis = Ts 29 09 1996
-- Initial seed.
-- Keep it secret. Keep it safe.
seed :: Int
seed = 69420
-- Initial RNG
entropy :: StdGen
entropy = mkStdGen $ seed
-- Initial rotation.
-- Simple split in half, genesis leaves plenty of time to shuffle.
initialRotation :: State
initialRotation = ((i, o), b, r)
where

old/Format.hs → Format.hs View File

@@ -1,16 +1,27 @@
module Format where
{---
- Format Module
-
- Functions for generating new formats
- Little bit of a shitshow
-
- Shaun Kerr
-}
import System.Random
import State
import Timestamp
import Config
import Utils
-- Calculate the format starting from Genesis
currentFormat :: Timestamp -> State
currentFormat t = strictApplyN n nextFormat initialRotation
where
n = t `monthsSince` genesis
-- Take a format and return the next months format
nextFormat :: State -> State
nextFormat (p, b, r) = (np, nb, nr)
where
@@ -18,18 +29,23 @@ nextFormat (p, b, r) = (np, nb, nr)
(np, nr) = (addNewPack . addNewPack) (ip, r)
nb = rotateBox b
-- Returns the out rotation packs that are legal
legalOutRot :: [OutRot] -> [OutRot]
legalOutRot x = filter (\(Or _ n) -> n == 0) x
-- Updates out rotation pack legality
updatePackAge :: [OutRot] -> [OutRot]
updatePackAge p = map (\(Or s n) -> (Or s $ max 0 (n-1))) p
-- Illegalise a pack
setIllegal :: InRot -> OutRot
setIllegal (Ir n) = Or n 3
-- Legalise a pack
setLegal :: OutRot -> InRot
setLegal (Or n _) = Ir n
-- Drop two oldest packs
rotateOld :: Pool -> Pool
rotateOld (i, o) = (ni, no)
where
@@ -37,6 +53,7 @@ rotateOld (i, o) = (ni, no)
no = (updatePackAge o) ++ dropped
dropped = map setIllegal (take 2 i)
-- Add a new pack
addNewPack :: (Pool, StdGen) -> (Pool, StdGen)
addNewPack ((i, o), r) = ((ni, no), nr)
where
@@ -46,5 +63,6 @@ addNewPack ((i, o), r) = ((ni, no), nr)
ni = i ++ [(setLegal np)]
no = filter (\x -> x /= np) o
-- Update the banned box
rotateBox :: BoxQueue -> BoxQueue
rotateBox (Bq x) = Bq $ rotate 1 x

old/Packs.hs → Packs.hs View File

@@ -1,5 +1,14 @@
module Packs where

{---
- Pack Module
-
- Defines datatypes for each pack and I totally didn't
- hand code this nuh-uh for real
-
- Shaun Kerr
-}

data BigBox =
Cc | Hp | Oc | Dd | Td | Rr deriving Eq


+ 41
- 0
State.hs View File

@@ -0,0 +1,41 @@
module State where
{---
- State Module
-
- Functions used for creating and defining the
- state of the current rotation.
-
- Shaun Kerr.
-}
import System.Random
import Packs
-- Total State is the Datapack Pool, the Banned Big Box,
-- and the next random number.
type State = (Pool, BoxQueue, StdGen)
-- In Rotation packs have no metadata
data InRot = Ir DataPack deriving (Show, Eq)
-- Out Rotation packs need a number of months
-- until they're legal again.
data OutRot = Or DataPack Integer
instance Eq OutRot where
(Or d1 _) == (Or d2 _) = d1 == d2
-- Box Queue is full of Maybes for the month
-- where none are banned.
data BoxQueue = Bq [Maybe BigBox]
-- Total pool is split into in and out of rotation
type Pool = ([InRot], [OutRot])
-- Simple Wrapper
createInRot :: [DataPack] -> [InRot]
createInRot x = map (\n -> Ir n) x
-- Wrapper + Initial legality
createOutRot :: [DataPack] -> [OutRot]
createOutRot x = map (\n -> Or n 0) x

+ 26
- 0
Timestamp.hs View File

@@ -1,10 +1,25 @@
module Timestamp where
{---
- Timestamp Module
-
- Functions related to getting and using timestamps.
-
- Shaun Kerr
-}
import Data.Time.LocalTime
import Data.Time.Format
-- Internal Date Representation
data Timestamp = Ts Integer Integer Integer deriving Show
-- Previews Start on the 20th
isPreviewSeason :: Timestamp -> Bool
isPreviewSeason (Ts x _ _) = x >= 20
-- True // False if first date is in the future
-- relative to the second date.
inFuture :: Timestamp -> Timestamp -> Bool
inFuture (Ts d1 m1 y1) (Ts d2 m2 y2)
| y1 /= y2 = y1 > y2
@@ -12,6 +27,9 @@ inFuture (Ts d1 m1 y1) (Ts d2 m2 y2)
| d1 /= d2 = d1 > d2
| otherwise = False
-- How many months in the future the first date is
-- relative from the second date.
-- returns 0 otherwise.
monthsSince :: Timestamp -> Timestamp -> Integer
monthsSince (Ts d1 m1 y1) (Ts d2 m2 y2)
| t1 `inFuture` t2 = (12 * (y1 - y2)) + (m1 - m2)
@@ -20,14 +38,22 @@ monthsSince (Ts d1 m1 y1) (Ts d2 m2 y2)
t1 = Ts d1 m1 y1
t2 = Ts d2 m2 y2
-- Helper, format Integer representation to Timestamp
toTS :: (Integer, Integer, Integer) -> Timestamp
toTS (y,m,d) = Ts d m y
-- IO Function, get the current date as a [Char]
getCurrentTime :: IO [Char]
getCurrentTime = getZonedTime
>>= return . (formatTime defaultTimeLocale "%Y %m %d")
-- Helper, format the [Char] as triple Integer
fmtCurrentTime :: [Char] -> (Integer, Integer, Integer)
fmtCurrentTime n = (\[a,b,c] -> (a,b,c)) iTime
where
iTime = map (\x -> read x :: Integer) $ words n
-- Hide away some ugly steps. Not sure we ever
-- use the other two so can probably compact this.
getTimestamp :: [Char] -> Timestamp
getTimestamp x = toTS . fmtCurrentTime $ x

+ 9
- 2
ViewUtils.hs View File

@@ -1,5 +1,14 @@
module ViewUtils where

{---
- ViewUtils Module
-
- Your guess is as good as mine why this is its own thing
- gotta get the month I guess
-
- Shaun Kerr
-}

import Timestamp

showMonth :: Integer -> String
@@ -15,5 +24,3 @@ showMonth 9 = "September"
showMonth 10 = "October"
showMonth 11 = "November"
showMonth 12 = "December"



ChangeLog.md → old/ChangeLog.md View File


Setup.hs → old/Setup.hs_ View File


+ 0
- 22
old/State.hs View File

@@ -1,22 +0,0 @@
module State where
import System.Random
import Packs
type State = (Pool, BoxQueue, StdGen)
data InRot = Ir DataPack deriving (Show, Eq)
data OutRot = Or DataPack Integer
instance Eq OutRot where
(Or d1 _) == (Or d2 _) = d1 == d2
data BoxQueue = Bq [Maybe BigBox]
type Pool = ([InRot], [OutRot])
createInRot :: [DataPack] -> [InRot]
createInRot x = map (\n -> Ir n) x
createOutRot :: [DataPack] -> [OutRot]
createOutRot x = map (\n -> Or n 0) x

_cache/02ffd36321aca0d8196095fa897a7038 → old/_cache/02ffd36321aca0d8196095fa897a7038 View File


_cache/12991168de6a9db452e49f2814dc4837 → old/_cache/12991168de6a9db452e49f2814dc4837 View File


_cache/13318c2b4a591b8f412f367f81df20d6 → old/_cache/13318c2b4a591b8f412f367f81df20d6 View File


_cache/18bc831854684ac860e2cfa4e9301159 → old/_cache/18bc831854684ac860e2cfa4e9301159 View File


_cache/21253358050819032165ae7515d3cfb6 → old/_cache/21253358050819032165ae7515d3cfb6 View File


_cache/2c4bf143a0d65180ae3fe8595281bb5d → old/_cache/2c4bf143a0d65180ae3fe8595281bb5d View File


_cache/2cc6229282889d93740fc5c44e426c43 → old/_cache/2cc6229282889d93740fc5c44e426c43 View File


_cache/3234241ee02d543d0cdc0eecf6b7f701 → old/_cache/3234241ee02d543d0cdc0eecf6b7f701 View File


_cache/3502f2aa291df768b503711e91da7f94 → old/_cache/3502f2aa291df768b503711e91da7f94 View File


_cache/36f9964be8b4f357c1d80cfdc525df89 → old/_cache/36f9964be8b4f357c1d80cfdc525df89 View File


_cache/3aa7c8fae80d374ec9a40c7a9116a08f → old/_cache/3aa7c8fae80d374ec9a40c7a9116a08f View File


_cache/41623fed16032ec0baf01c53a86cce9f → old/_cache/41623fed16032ec0baf01c53a86cce9f View File


_cache/5186f0e1b9013dffb631b7ac1daee0ff → old/_cache/5186f0e1b9013dffb631b7ac1daee0ff View File


_cache/58a0023be224362f3c70e834c2890dab → old/_cache/58a0023be224362f3c70e834c2890dab View File


_cache/5a2f2185fd6eb7526e285f6845fb2711 → old/_cache/5a2f2185fd6eb7526e285f6845fb2711 View File


_cache/5e52357749f41a8425ceca375f580db8 → old/_cache/5e52357749f41a8425ceca375f580db8 View File


_cache/65d86825c80bb51fe28215cbbdc72f9c → old/_cache/65d86825c80bb51fe28215cbbdc72f9c View File


_cache/6b13d4c109d24e3df78f6283afdafd71 → old/_cache/6b13d4c109d24e3df78f6283afdafd71 View File


_cache/74ad07f6399cddcf5e93a42176e6ff4a → old/_cache/74ad07f6399cddcf5e93a42176e6ff4a View File


_cache/7a9e11cb9751d5e2c28f172e49a740f3 → old/_cache/7a9e11cb9751d5e2c28f172e49a740f3 View File


_cache/7eebc8997569f57e9fd6bcfa43ee6244 → old/_cache/7eebc8997569f57e9fd6bcfa43ee6244 View File


_cache/81d1b6c2c1cab5cdfc34988853034e75 → old/_cache/81d1b6c2c1cab5cdfc34988853034e75 View File


_cache/8202fa021d8183dcb2050787d67fa9ed → old/_cache/8202fa021d8183dcb2050787d67fa9ed View File


_cache/8c2cc830d6d96619afd7f817c883e2cb → old/_cache/8c2cc830d6d96619afd7f817c883e2cb View File


_cache/8e5ffdf6c89ed1aa49301aa3a00a2add → old/_cache/8e5ffdf6c89ed1aa49301aa3a00a2add View File


_cache/9861f58ae8a49766ccd8f33085c3ba42 → old/_cache/9861f58ae8a49766ccd8f33085c3ba42 View File


_cache/a2e2c78a44d784b0fd8ff02b6324dc02 → old/_cache/a2e2c78a44d784b0fd8ff02b6324dc02 View File


_cache/a8e78f0ff3815d8ef9ed987a4625aeb3 → old/_cache/a8e78f0ff3815d8ef9ed987a4625aeb3 View File


_cache/b324eb6b5a5bbd10b5a71240f7edcd71 → old/_cache/b324eb6b5a5bbd10b5a71240f7edcd71 View File


_cache/b55ed8f8472b848711dbd0caa2920e4f → old/_cache/b55ed8f8472b848711dbd0caa2920e4f View File


_cache/c24ef28b2ac6c9fe797b11c5d68599ff → old/_cache/c24ef28b2ac6c9fe797b11c5d68599ff View File


_cache/cedbb457a9c3e70e2341381194664a42 → old/_cache/cedbb457a9c3e70e2341381194664a42 View File


_cache/d5c19886a5497f571c624d44ba520d2b → old/_cache/d5c19886a5497f571c624d44ba520d2b View File


_cache/dbb2e29497bc6a4d9f381f8003dc0e29 → old/_cache/dbb2e29497bc6a4d9f381f8003dc0e29 View File


_cache/e4b9b8633ce1170f36e573786e855a55 → old/_cache/e4b9b8633ce1170f36e573786e855a55 View File


_cache/ed9c302a44a035e5579daccaf55007fa → old/_cache/ed9c302a44a035e5579daccaf55007fa View File


_cache/f38c8240d33ea73352ba3bbc7036a71f → old/_cache/f38c8240d33ea73352ba3bbc7036a71f View File


_site/about/index.html → old/_site/about/index.html View File


_site/contact/index.html → old/_site/contact/index.html View File


_site/css/default.css → old/_site/css/default.css View File


_site/description/index.html → old/_site/description/index.html View File


_site/humans.txt → old/_site/humans.txt View File


_site/robots.txt → old/_site/robots.txt View File


about.md → old/about.md View File


contact.md → old/contact.md View File


css/default.css → old/css/default.css View File


default.nix → old/default.nix View File


description.md → old/description.md View File


humans.txt → old/humans.txt View File


icons/favicon.svg → old/icons/favicon.svg View File


p7.cabal → old/p7.cabal View File


p7.nix → old/p7.nix View File


rf.nix → old/rf.nix View File


robots.txt → old/robots.txt View File


shell.nix → old/shell.nix View File


site.hs → old/site.hs View File

@@ -47,10 +47,12 @@ ctx = defaultContext <>

-- Default context for format
fmtCtx :: Integer -> Integer -> String -> Context String
fmtCtx m y u =
fmtCtx m y u dps bbs =
(titleField mTitle) <>
(field "nrdbUrl" u) <>
(listFieldWith
(listField "dpacks" (
field "dp" (return .
)
ctx
where
mTitle = "Format for " ++ (showMonth m) ++ " " ++ y

templates/archive.html → old/templates/archive.html View File


templates/default.html → old/templates/default.html View File


templates/format.html → old/templates/format.html View File


templates/index.html → old/templates/index.html View File


templates/post-list.html → old/templates/post-list.html View File


templates/post.html → old/templates/post.html View File


Loading…
Cancel
Save