PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/docpad.coffee

https://gitlab.com/khaledweka/AlertifyJS
CoffeeScript | 192 lines | 99 code | 33 blank | 60 comment | 14 complexity | 2f0a4a9593c8b82e995d19a1219455d9 MD5 | raw file
  1. # The DocPad Configuration File
  2. # It is simply a CoffeeScript Object which is parsed by CSON
  3. fs = require('fs')
  4. #docpad = require('docpad')
  5. docpadConfig = {
  6. srcPath : './docpad'
  7. outPath: './site'
  8. # =================================
  9. # Template Data
  10. # These are variables that will be accessible via our templates
  11. # To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
  12. layoutsPaths:
  13. ['layouts', 'data']
  14. templateData:
  15. # Specify some site properties
  16. site:
  17. # The production url of our website
  18. # If not set, will default to the calculated site URL (e.g. http://localhost:9778)
  19. url: "http://alertifyjs.com"
  20. # Here are some old site urls that you would like to redirect from
  21. oldUrls: [
  22. ]
  23. # The default title of our website
  24. title: "ALERTIFY JS"
  25. # The website description (for SEO)
  26. description: """
  27. AlertifyJS is a javascript framework for developing pretty browser dialogs and notifications.
  28. """
  29. # The website keywords (for SEO) separated by commas
  30. keywords: """
  31. alert, notify, alertify, pretty, browser, dialog, notification, js, javascript, growl, css
  32. """
  33. # The website's styles
  34. styles: [
  35. '/build/css/alertify.css'
  36. '/build/css/themes/default.css'
  37. '/css/normalize.min.css'
  38. '/css/font-awesome.min.css'
  39. '/css/semantic.min.css'
  40. 'http://fonts.googleapis.com/earlyaccess/droidarabickufi.css'
  41. 'http://fonts.googleapis.com/css?family=Droid+Sans:400,700'
  42. '/css/site.min.css',
  43. 'styles/style.css'
  44. ]
  45. # The website's scripts
  46. scripts: [
  47. '/build/alertify.js'
  48. '/js/jquery-1.11.1.min.js'
  49. '/js/jquery.mobile.custom.min.js'
  50. '/js/scrollLock.min.js'
  51. '/js/semantic.min.js'
  52. '/js/site.min.js',
  53. '/scripts/script.js'
  54. ]
  55. # Get the documentation data
  56. getPackage: (name,module, sort) ->
  57. pkg = JSON.parse(fs.readFileSync('./package.json'))
  58. # Get the documentation data
  59. getDocData: (name,module, sort) ->
  60. items = JSON.parse(fs.readFileSync('./docpad/data/' + name + '.json'))
  61. .map (item) ->
  62. if(typeof item.script == 'string')
  63. item.script = item.script.replace(/\{component\}/gm,module)
  64. else
  65. item.script = item.script.map (line) ->
  66. line.replace(/\{component\}/gm,module)
  67. item
  68. if(sort)
  69. # sort by name
  70. items = items.sort (a,b) ->
  71. if (a.name > b.name)
  72. 1
  73. else if (a.name < b.name || a.type == 'm')
  74. -1
  75. else
  76. 0
  77. # sort by type
  78. .sort (a,b) ->
  79. if (a.type > b.type)
  80. -1
  81. else if (a.type < b.type)
  82. 1
  83. else
  84. 0
  85. items
  86. # Get the prepared site/document title
  87. # Often we would like to specify particular formatting to our page's title
  88. # we can apply that formatting here
  89. getPreparedTitle: ->
  90. # if we have a document title, then we should use that and suffix the site's title onto it
  91. if @document.title
  92. "#{@document.title} | #{@site.title}"
  93. # if our document does not have it's own title, then we should just use the site's title
  94. else
  95. @site.title
  96. # Get the prepared site/document description
  97. getPreparedDescription: ->
  98. # if we have a document description, then we should use that, otherwise use the site's description
  99. @document.description or @site.description
  100. # Get the prepared site/document keywords
  101. getPreparedKeywords: ->
  102. # Merge the document keywords with the site keywords
  103. @site.keywords.concat(@document.keywords or []).join(', ')
  104. # =================================
  105. # Collections
  106. # Here we define our custom collections
  107. # What we do is we use findAllLive to find a subset of documents from the parent collection
  108. # creating a live collection out of it
  109. # A live collection is a collection that constantly stays up to date
  110. # You can learn more about live collections and querying via
  111. # http://bevry.me/queryengine/guide
  112. collections:
  113. # Create a collection called posts
  114. # That contains all the documents that will be going to the out path posts
  115. contents: ->
  116. @getCollection('documents').findAllLive({relativeOutDirPath: 'contents'})
  117. # =================================
  118. # Environments
  119. # DocPad's default environment is the production environment
  120. # The development environment, actually extends from the production environment
  121. # The following overrides our production url in our development environment with false
  122. # This allows DocPad's to use it's own calculated site URL instead, due to the falsey value
  123. # This allows <%- @site.url %> in our template data to work correctly, regardless what environment we are in
  124. environments:
  125. development:
  126. templateData:
  127. site:
  128. url: false
  129. # =================================
  130. # Plugin Configuration
  131. plugins:
  132. highlightjs:
  133. className: 'example'
  134. # =================================
  135. # DocPad Events
  136. # Here we can define handlers for events that DocPad fires
  137. # You can find a full listing of events on the DocPad Wiki
  138. events:
  139. # Server Extend
  140. # Used to add our own custom routes to the server before the docpad routes are added
  141. serverExtend: (opts) ->
  142. # Extract the server from the options
  143. {server} = opts
  144. docpad = @docpad
  145. # As we are now running in an event,
  146. # ensure we are using the latest copy of the docpad configuraiton
  147. # and fetch our urls from it
  148. latestConfig = docpad.getConfig()
  149. oldUrls = latestConfig.templateData.site.oldUrls or []
  150. newUrl = latestConfig.templateData.site.url
  151. # Redirect any requests accessing one of our sites oldUrls to the new site url
  152. server.use (req,res,next) ->
  153. if req.headers.host in oldUrls
  154. res.redirect(newUrl+req.url, 301)
  155. else
  156. next()
  157. }
  158. # Export our DocPad Configuration
  159. module.exports = docpadConfig