You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.2 KiB

  1. # The DocPad Configuration File
  2. # It is simply a CoffeeScript Object which is parsed by CSON
  3. docpadConfig = {
  4. outPath: '../docs',
  5. renderPasses: 1,
  6. enabledPlugins:
  7. handlebars: false
  8. html2coffee: false
  9. jade: false
  10. marked: false
  11. paged: false
  12. livereload: false
  13. plugins:
  14. handlebars:
  15. helpers:
  16. # Expose docpads 'getBlock' function to handlebars
  17. getBlock: (type, additional...) ->
  18. additional.pop() # remove the hash object
  19. @getBlock(type).add(additional).toHTML()
  20. # Check Version
  21. # Whether or not to check for newer versions of DocPad
  22. checkVersion: true # default
  23. documentsPaths: [ # default
  24. 'documents'
  25. ]
  26. # Files Paths
  27. # An array of paths which contents will be treated as files
  28. # If it is a relative path, it will have the resolved `srcPath` prepended to it
  29. filesPaths: [ # default
  30. 'files'
  31. 'public'
  32. ]
  33. # =================================
  34. # Template Data
  35. # These are variables that will be accessible via our templates
  36. # To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
  37. templateData:
  38. # Specify some site properties
  39. site:
  40. # The production url of our website
  41. url: "http://www.semantic-ui.com"
  42. # Here are some old site urls that you would like to redirect from
  43. oldUrls: [
  44. 'learnsemantic.com'
  45. ]
  46. # The default title of our website
  47. title: "Semantic UI"
  48. # The website description (for SEO)
  49. description: """
  50. Semantic empowers designers and developers by creating a shared vocabulary for UI.
  51. """
  52. # The website keywords (for SEO) separated by commas
  53. keywords: """
  54. html5, ui, library, framework, javascript
  55. """
  56. # -----------------------------
  57. # Helper Functions
  58. # Get the prepared site/document title
  59. # Often we would like to specify particular formatting to our page's title
  60. # we can apply that formatting here
  61. getPreparedTitle: ->
  62. # if we have a document title, then we should use that and suffix the site's title onto it
  63. if @document.title
  64. "#{@document.title} | #{@site.title}"
  65. # if our document does not have it's own title, then we should just use the site's title
  66. else
  67. @site.title
  68. getPage: (collection, id) ->
  69. for item, index in collection
  70. selectedIndex = (index + 1) if item.id is id
  71. selectedIndex
  72. pageCount: (collection) ->
  73. for item, index in collection
  74. itemCount = index + 1
  75. itemCount
  76. getPageCollection: (collection, id, delta = 2) ->
  77. for item, index in collection
  78. selectedIndex = index if item.id is id
  79. lastIndex = index
  80. # determine page count before and after
  81. bottomCount = if (selectedIndex - delta >= 0) then delta else (selectedIndex)
  82. topCount = if (selectedIndex + delta <= lastIndex) then delta else (lastIndex - selectedIndex)
  83. bottomDelta = (delta * 2 - topCount)
  84. topDelta = (delta * 2 - bottomCount)
  85. bottomIndex = if (selectedIndex - bottomDelta >= 0) then (selectedIndex - bottomDelta) else 0
  86. topIndex = if (selectedIndex + topDelta <= lastIndex) then (selectedIndex + topDelta) else lastIndex
  87. result = collection[bottomIndex..topIndex]
  88. result
  89. # Get the prepared site/document description
  90. getPreparedDescription: ->
  91. # if we have a document description, then we should use that, otherwise use the site's description
  92. @document.description or @site.description
  93. # Get the prepared site/document keywords
  94. getPreparedKeywords: ->
  95. # Merge the document keywords with the site keywords
  96. @site.keywords.concat(@document.keywords or []).join(', ')
  97. getGruntedStyles: ->
  98. _ = require 'underscore'
  99. styles = []
  100. gruntConfig = require('./grunt-config.json')
  101. _.each gruntConfig, (value, key) ->
  102. styles = styles.concat _.flatten _.pluck value, 'dest'
  103. styles = _.filter styles, (value) ->
  104. return value.indexOf('.min.css') > -1
  105. _.map styles, (value) ->
  106. return value.replace 'out', ''
  107. getGruntedScripts: ->
  108. _ = require 'underscore'
  109. scripts = []
  110. gruntConfig = require('./grunt-config.json')
  111. _.each gruntConfig, (value, key) ->
  112. scripts = scripts.concat _.flatten _.pluck value, 'dest'
  113. scripts = _.filter scripts, (value) ->
  114. return value.indexOf('.min.js') > -1
  115. _.map scripts, (value) ->
  116. return value.replace 'out', ''
  117. # =================================
  118. # DocPad Events
  119. # Here we can define handlers for events that DocPad fires
  120. # You can find a full listing of events on the DocPad Wiki
  121. events:
  122. # Server Extend
  123. # Used to add our own custom routes to the server before the docpad routes are added
  124. serverExtend: (opts) ->
  125. # Extract the server from the options
  126. {server} = opts
  127. docpad = @docpad
  128. # As we are now running in an event,
  129. # ensure we are using the latest copy of the docpad configuraiton
  130. # and fetch our urls from it
  131. latestConfig = docpad.getConfig()
  132. oldUrls = latestConfig.templateData.site.oldUrls or []
  133. newUrl = latestConfig.templateData.site.url
  134. # Redirect any requests accessing one of our sites oldUrls to the new site url
  135. server.use (req,res,next) ->
  136. if req.headers.host in oldUrls
  137. res.redirect(newUrl+req.url, 301)
  138. else
  139. next()
  140. }
  141. # Export our DocPad Configuration
  142. module.exports = docpadConfig