Skip to content

Commit f6ab14c

Browse files
committed
Added opengraphs option for open graph tags on docs
1 parent 1d6c839 commit f6ab14c

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 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] objects on docs. [[#283] by GyuYong Jung]
2728

2829
### Python target
2930

@@ -40,10 +41,12 @@ To be released.
4041

4142
[#126]: https://github.com/nirum-lang/nirum/issues/126
4243
[#281]: https://github.com/nirum-lang/nirum/pull/281
44+
[#283]: https://github.com/spoqa/nirum/pull/283
4345
[#300]: https://github.com/nirum-lang/nirum/pull/300
4446
[CommonMark]: http://commonmark.org/
4547
[table syntax extension]: https://github.github.com/gfm/#tables-extension-
4648
[special attributes extension]: https://michelf.ca/projects/php-markdown/extra/#spe-attr
49+
[OpenGraph]: http://ogp.me/
4750

4851

4952
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ Settings
4545
It goes to `<title>` elements of generated HTML pages. It's usually a name of
4646
the Nirum package.
4747

48+
### `opengraphs` (optional): OpenGraph
49+
50+
It goes to `<meta>` elements of generated HTML pages. It generate OpenGraph
51+
objects.
52+
4853

4954
### `style` (optional): Custom CSS
5055

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)