Skip to content

Commit 9d15860

Browse files
authored
Merge branch 'master' into add-numeric-constraints
2 parents 7f549ca + 93488a2 commit 9d15860

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ To be released.
2727
crashed when a thight list item contains blocks other than paragraphs.
2828
- Package's version became shown on the generated docs.
2929
[[#297], [#304] by Jeong Ukjae]
30+
- Added `opengraphs` option for [OpenGraph] objects on docs.
31+
[[#283], [#305] by GyuYong Jung]
32+
- Added syntax highlighting.
33+
[[#310], [#311] by MinJune Kim]
3034

3135
### Python target
3236

@@ -45,12 +49,15 @@ To be released.
4549
[#206]: https://github.com/nirum-lang/nirum/issues/206
4650
[#271]: https://github.com/nirum-lang/nirum/pull/271
4751
[#281]: https://github.com/nirum-lang/nirum/pull/281
52+
[#283]: https://github.com/spoqa/nirum/pull/283
4853
[#297]: https://github.com/nirum-lang/nirum/issues/297
4954
[#300]: https://github.com/nirum-lang/nirum/pull/300
5055
[#304]: https://github.com/nirum-lang/nirum/pull/304
56+
[#305]: https://github.com/nirum-lang/nirum/pull/305
5157
[CommonMark]: http://commonmark.org/
5258
[table syntax extension]: https://github.github.com/gfm/#tables-extension-
5359
[special attributes extension]: https://michelf.ca/projects/php-markdown/extra/#spe-attr
60+
[OpenGraph]: http://ogp.me/
5461

5562

5663
Version 0.4.1

app/nirum-docs.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ packageMetadata = Metadata
3131
, authors = [Author "Nirum team" Nothing Nothing]
3232
, Nirum.Package.Metadata.target = Docs
3333
{ docsTitle = "Nirum"
34+
, docsOpenGraph = []
3435
, docsStyle = style
3536
, docsHeader = ""
3637
, docsFooter = footer

docs/target/docs.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ It goes to `<title>` elements of generated HTML pages. It's usually a name of
4646
the Nirum package.
4747

4848

49+
### `opengraphs` (optional): OpenGraph
50+
51+
It goes to `<meta>` elements of generated HTML pages. It mostly purposes to
52+
generate [OpenGraph] objects, but can be used for other metadata as well.
53+
54+
[OpenGraph]: http://ogp.me/
55+
56+
4957
### `style` (optional): Custom CSS
5058

5159
It goes to very ending of the CSS file, which means it can override other

src/Nirum/Package/Metadata.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri)
4848
, readMetadata
4949
, stringField
5050
, tableField
51+
, tableArrayField
5152
, textArrayField
5253
, versionField
5354
) where

src/Nirum/Targets/Docs.hs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Nirum.Version (versionText)
5656

5757
data Docs = Docs
5858
{ docsTitle :: T.Text
59+
, docsOpenGraph :: [OpenGraph]
5960
, docsStyle :: T.Text
6061
, docsHeader :: T.Text
6162
, docsFooter :: T.Text
@@ -69,6 +70,11 @@ data CurrentPage
6970
| DocumentPage FilePath
7071
deriving (Eq, Show)
7172

73+
data OpenGraph = OpenGraph
74+
{ ogTag :: T.Text
75+
, ogContent :: T.Text
76+
} deriving (Eq, Ord, Show)
77+
7278
makeFilePath :: ModulePath -> FilePath
7379
makeFilePath modulePath' = foldl (</>) "" $
7480
map toNormalizedString (toList modulePath') ++ ["index.html"]
@@ -104,7 +110,12 @@ $doctype 5
104110
<meta name="generator" content="Nirum #{versionText}">
105111
$forall Author { name = name' } <- authors md
106112
<meta name="author" content="#{name'}">
113+
$forall OpenGraph { ogTag, ogContent } <- docsOpenGraph $ target pkg
114+
<meta property="#{ogTag}" content="#{ogContent}">
107115
<link rel="stylesheet" href="#{root}style.css">
116+
<link rel="stylesheet" href="#{hljsCss}">
117+
<script src="#{hljsJs}"></script>
118+
<script>hljs.initHighlightingOnLoad();</script>
108119
<body>
109120
#{preEscapedToMarkup $ docsHeader $ target pkg}
110121
<nav>
@@ -161,6 +172,12 @@ $doctype 5
161172
documentSortKey ("", _) = (False, 0, "")
162173
documentSortKey (fp@(fp1 : _), _) =
163174
(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"]
164181

165182
typeExpression :: BoundModule Docs -> TE.TypeExpression -> Html
166183
typeExpression _ expr = [shamlet|#{typeExpr expr}|]
@@ -490,7 +507,7 @@ strong code
490507
pre
491508
padding: 16px 10px
492509
background-color: #{gray1}
493-
code
510+
code, code.hljs
494511
background: none
495512
div
496513
border-top: 1px solid #{gray3}
@@ -619,15 +636,32 @@ instance Target Docs where
619636
targetName _ = "docs"
620637
parseTarget table = do
621638
title <- stringField "title" table
639+
opengraphs <- optional $ opengraphsField "opengraphs" table
622640
style <- optional $ stringField "style" table
623641
header <- optional $ stringField "header" table
624642
footer <- optional $ stringField "footer" table
625643
return Docs
626644
{ docsTitle = title
645+
, docsOpenGraph = fromMaybe [] opengraphs
627646
, docsStyle = fromMaybe "" style
628647
, docsHeader = fromMaybe "" header
629648
, docsFooter = fromMaybe "" footer
630649
}
631650
compilePackage = compilePackage'
632651
showCompileError _ = id
633652
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

Comments
 (0)