@@ -56,6 +56,7 @@ import Nirum.Version (versionText)
56
56
57
57
data Docs = Docs
58
58
{ docsTitle :: T. Text
59
+ , docsOpenGraph :: [OpenGraph ]
59
60
, docsStyle :: T. Text
60
61
, docsHeader :: T. Text
61
62
, docsFooter :: T. Text
@@ -69,6 +70,11 @@ data CurrentPage
69
70
| DocumentPage FilePath
70
71
deriving (Eq , Show )
71
72
73
+ data OpenGraph = OpenGraph
74
+ { ogTag :: T. Text
75
+ , ogContent :: T. Text
76
+ } deriving (Eq , Ord , Show )
77
+
72
78
makeFilePath :: ModulePath -> FilePath
73
79
makeFilePath modulePath' = foldl (</>) " " $
74
80
map toNormalizedString (toList modulePath') ++ [" index.html" ]
@@ -104,7 +110,12 @@ $doctype 5
104
110
<meta name="generator" content="Nirum #{versionText}">
105
111
$forall Author { name = name' } <- authors md
106
112
<meta name="author" content="#{name'}">
113
+ $forall OpenGraph { ogTag, ogContent } <- docsOpenGraph $ target pkg
114
+ <meta property="#{ogTag}" content="#{ogContent}">
107
115
<link rel="stylesheet" href="#{root}style.css">
116
+ <link rel="stylesheet" href="#{hljsCss}">
117
+ <script src="#{hljsJs}"></script>
118
+ <script>hljs.initHighlightingOnLoad();</script>
108
119
<body>
109
120
#{preEscapedToMarkup $ docsHeader $ target pkg}
110
121
<nav>
@@ -161,6 +172,12 @@ $doctype 5
161
172
documentSortKey (" " , _) = (False , 0 , " " )
162
173
documentSortKey (fp@ (fp1 : _), _) =
163
174
(isUpper fp1, length (filter (== pathSeparator) fp), fp)
175
+ hljsBase :: T. Text
176
+ hljsBase = " https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/"
177
+ hljsCss :: T. Text
178
+ hljsCss = T. concat [hljsBase, " styles/github.min.css" ]
179
+ hljsJs :: T. Text
180
+ hljsJs = T. concat [hljsBase, " highlight.min.js" ]
164
181
165
182
typeExpression :: BoundModule Docs -> TE. TypeExpression -> Html
166
183
typeExpression _ expr = [shamlet |#{typeExpr expr}|]
@@ -490,7 +507,7 @@ strong code
490
507
pre
491
508
padding: 16px 10px
492
509
background-color: #{gray1}
493
- code
510
+ code, code.hljs
494
511
background: none
495
512
div
496
513
border-top: 1px solid #{gray3}
@@ -619,15 +636,32 @@ instance Target Docs where
619
636
targetName _ = " docs"
620
637
parseTarget table = do
621
638
title <- stringField " title" table
639
+ opengraphs <- optional $ opengraphsField " opengraphs" table
622
640
style <- optional $ stringField " style" table
623
641
header <- optional $ stringField " header" table
624
642
footer <- optional $ stringField " footer" table
625
643
return Docs
626
644
{ docsTitle = title
645
+ , docsOpenGraph = fromMaybe [] opengraphs
627
646
, docsStyle = fromMaybe " " style
628
647
, docsHeader = fromMaybe " " header
629
648
, docsFooter = fromMaybe " " footer
630
649
}
631
650
compilePackage = compilePackage'
632
651
showCompileError _ = id
633
652
toByteString _ = id
653
+
654
+ opengraphsField :: MetadataField -> Table -> Either MetadataError [OpenGraph ]
655
+ opengraphsField field' table = do
656
+ array <- tableArrayField field' table
657
+ opengraphs' <- mapM parseOpenGraph array
658
+ return $ toList opengraphs'
659
+ where
660
+ parseOpenGraph :: Table -> Either MetadataError OpenGraph
661
+ parseOpenGraph t = do
662
+ tag' <- stringField " tag" t
663
+ content' <- stringField " content" t
664
+ return OpenGraph
665
+ { ogTag = tag'
666
+ , ogContent = content'
667
+ }
0 commit comments