Skip to content

Commit 197fc76

Browse files
committed
Added opengraphs option for open graph tags on docs
1 parent 0309938 commit 197fc76

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGES.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ To be released.
2424
to customize the look and feel of the result pages.
2525
- Fixed an incorrect processing of [CommonMark] thight list items: it had
2626
crashed when a thight list item contains blocks other than paragraphs.
27+
- Added `opengraphs` option for [OpenGraph] tags on docs. [[#283] by GyuYong Jung]
2728

2829
### Et cetera
2930

@@ -32,11 +33,13 @@ To be released.
3233
[nirumlang/nirum](https://hub.docker.com/r/nirumlang/nirum/)
3334
(from [spoqa/nirum](https://hub.docker.com/r/spoqa/nirum/)).
3435

35-
[#126]: https://github.com/nirum-lang/nirum/issues/126
36-
[#281]: https://github.com/nirum-lang/nirum/pull/281
36+
[#126]: https://github.com/spoqa/nirum/issues/126
37+
[#281]: https://github.com/spoqa/nirum/pull/281
38+
[#283]: https://github.com/spoqa/nirum/pull/283
3739
[CommonMark]: http://commonmark.org/
3840
[table syntax extension]: https://github.github.com/gfm/#tables-extension-
3941
[special attributes extension]: https://michelf.ca/projects/php-markdown/extra/#spe-attr
42+
[OpenGraph]: http://ogp.me
4043

4144

4245
Version 0.4.1

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Nirum.Version (versionText)
5555

5656
data Docs = Docs
5757
{ docsTitle :: T.Text
58+
, docsOpenGraph :: [OpenGraph]
5859
, docsStyle :: T.Text
5960
, docsHeader :: T.Text
6061
, docsFooter :: T.Text
@@ -68,6 +69,11 @@ data CurrentPage
6869
| DocumentPage FilePath
6970
deriving (Eq, Show)
7071

72+
data OpenGraph = OpenGraph
73+
{ ogTag :: T.Text
74+
, ogContent :: T.Text
75+
} deriving (Eq, Ord, Show)
76+
7177
makeFilePath :: ModulePath -> FilePath
7278
makeFilePath modulePath' = foldl (</>) "" $
7379
map toNormalizedString (toList modulePath') ++ ["index.html"]
@@ -103,6 +109,8 @@ $doctype 5
103109
<meta name="generator" content="Nirum #{versionText}">
104110
$forall Author { name = name' } <- authors md
105111
<meta name="author" content="#{name'}">
112+
$forall OpenGraph { ogTag, ogContent } <- docsOpenGraph $ target pkg
113+
<meta property="#{ogTag}" content="#{ogContent}">
106114
<link rel="stylesheet" href="#{root}style.css">
107115
<body>
108116
#{preEscapedToMarkup $ docsHeader $ target pkg}
@@ -616,15 +624,32 @@ instance Target Docs where
616624
targetName _ = "docs"
617625
parseTarget table = do
618626
title <- stringField "title" table
627+
opengraphs <- optional $ opengraphsField "opengraphs" table
619628
style <- optional $ stringField "style" table
620629
header <- optional $ stringField "header" table
621630
footer <- optional $ stringField "footer" table
622631
return Docs
623632
{ docsTitle = title
633+
, docsOpenGraph = fromMaybe [] opengraphs
624634
, docsStyle = fromMaybe "" style
625635
, docsHeader = fromMaybe "" header
626636
, docsFooter = fromMaybe "" footer
627637
}
628638
compilePackage = compilePackage'
629639
showCompileError _ = id
630640
toByteString _ = id
641+
642+
opengraphsField :: MetadataField -> Table -> Either MetadataError [OpenGraph]
643+
opengraphsField field' table = do
644+
array <- tableArrayField field' table
645+
opengraphs' <- mapM parseOpenGraph array
646+
return $ toList opengraphs'
647+
where
648+
parseOpenGraph :: Table -> Either MetadataError OpenGraph
649+
parseOpenGraph t = do
650+
tag' <- stringField "tag" t
651+
content' <- stringField "content" t
652+
return OpenGraph
653+
{ ogTag = tag'
654+
, ogContent = content'
655+
}

0 commit comments

Comments
 (0)