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.

178 lines
5.2 KiB

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