|
| 1 | +import Basics |
| 2 | +import GenerateLayout1 |
| 3 | + |
| 4 | +type Text = Vector Char |
| 5 | + |
| 6 | + |
| 7 | +emphKeywordInContent :: Text -> Blog -> Blog |
| 8 | +emphKeywordInContent keyword blogs = |
| 9 | + case blogs of |
| 10 | + End -> End |
| 11 | + Layout1 header id author date content tags rst -> let newContent = case content of |
| 12 | + Content block -> Content (emphasizeKeywordInBlock keyword block) |
| 13 | + newRst = emphKeywordInContent keyword rst |
| 14 | + in Layout1 header id author date newContent tags newRst |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +filterByKeywordInTagList :: Text -> Blog -> Blog |
| 19 | +filterByKeywordInTagList keyword blogs = case blogs of |
| 20 | + End -> End |
| 21 | + Layout1 header id author date content tags rst -> let present = searchBlogTags keyword tags |
| 22 | + in if present then |
| 23 | + let newRst = filterByKeywordInTagList keyword rst |
| 24 | + in Layout1 header id author date content tags newRst |
| 25 | + else filterByKeywordInTagList keyword rst |
| 26 | + |
| 27 | + |
| 28 | +emphKeywordInTag :: Text -> Blog -> Blog |
| 29 | +emphKeywordInTag keyword blogs = case blogs of |
| 30 | + End -> End |
| 31 | + Layout1 header id author date content tags rst -> let present = searchBlogTags keyword tags |
| 32 | + in if (present) |
| 33 | + then let newContent = case content of |
| 34 | + Content block -> Content (emphasizeKeywordInBlock keyword block) |
| 35 | + newRst = emphKeywordInTag keyword rst |
| 36 | + in Layout1 header id author date newContent tags newRst |
| 37 | + else |
| 38 | + let newRst = emphKeywordInTag keyword rst |
| 39 | + in Layout1 header id author date content tags newRst |
| 40 | + |
| 41 | + |
| 42 | +-- main function |
| 43 | +gibbon_main = |
| 44 | + let blogs = mkBlogs_layout1 2 |
| 45 | + keyword :: Vector Char |
| 46 | + keyword = "a" |
| 47 | + newblgs = emphKeywordInContent keyword blogs |
| 48 | + newblgs' = emphKeywordInTag keyword newblgs |
| 49 | + newblgs'' = filterByKeywordInTagList keyword newblgs' |
| 50 | + in printPacked newblgs'' |
0 commit comments