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.

165 lines
4.9 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. # =================================
  23. # Template Data
  24. # These are variables that will be accessible via our templates
  25. # To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
  26. templateData:
  27. # Specify some site properties
  28. site:
  29. # The production url of our website
  30. url: "http://www.semantic-ui.com"
  31. # Here are some old site urls that you would like to redirect from
  32. oldUrls: [
  33. 'learnsemantic.com'
  34. ]
  35. # The default title of our website
  36. title: "Semantic UI"
  37. # The website description (for SEO)
  38. description: """
  39. Semantic empowers designers and developers by creating a shared vocabulary for UI.
  40. """
  41. # The website keywords (for SEO) separated by commas
  42. keywords: """
  43. html5, ui, library, framework, javascript
  44. """
  45. # -----------------------------
  46. # Helper Functions
  47. # Get the prepared site/document title
  48. # Often we would like to specify particular formatting to our page's title
  49. # we can apply that formatting here
  50. getPreparedTitle: ->
  51. # if we have a document title, then we should use that and suffix the site's title onto it
  52. if @document.title
  53. "#{@document.title} | #{@site.title}"
  54. # if our document does not have it's own title, then we should just use the site's title
  55. else
  56. @site.title
  57. getPage: (collection, id) ->
  58. for item, index in collection
  59. selectedIndex = (index + 1) if item.id is id
  60. selectedIndex
  61. pageCount: (collection) ->
  62. for item, index in collection
  63. itemCount = index + 1
  64. itemCount
  65. getPageCollection: (collection, id, delta = 2) ->
  66. for item, index in collection
  67. selectedIndex = index if item.id is id
  68. lastIndex = index
  69. # determine page count before and after
  70. bottomCount = if (selectedIndex - delta >= 0) then delta else (selectedIndex)
  71. topCount = if (selectedIndex + delta <= lastIndex) then delta else (lastIndex - selectedIndex)
  72. bottomDelta = (delta * 2 - topCount)
  73. topDelta = (delta * 2 - bottomCount)
  74. bottomIndex = if (selectedIndex - bottomDelta >= 0) then (selectedIndex - bottomDelta) else 0
  75. topIndex = if (selectedIndex + topDelta <= lastIndex) then (selectedIndex + topDelta) else lastIndex
  76. result = collection[bottomIndex..topIndex]
  77. result
  78. # Get the prepared site/document description
  79. getPreparedDescription: ->
  80. # if we have a document description, then we should use that, otherwise use the site's description
  81. @document.description or @site.description
  82. # Get the prepared site/document keywords
  83. getPreparedKeywords: ->
  84. # Merge the document keywords with the site keywords
  85. @site.keywords.concat(@document.keywords or []).join(', ')
  86. getGruntedStyles: ->
  87. _ = require 'underscore'
  88. styles = []
  89. gruntConfig = require('./grunt-config.json')
  90. _.each gruntConfig, (value, key) ->
  91. styles = styles.concat _.flatten _.pluck value, 'dest'
  92. styles = _.filter styles, (value) ->
  93. return value.indexOf('.min.css') > -1
  94. _.map styles, (value) ->
  95. return value.replace 'out', ''
  96. getGruntedScripts: ->
  97. _ = require 'underscore'
  98. scripts = []
  99. gruntConfig = require('./grunt-config.json')
  100. _.each gruntConfig, (value, key) ->
  101. scripts = scripts.concat _.flatten _.pluck value, 'dest'
  102. scripts = _.filter scripts, (value) ->
  103. return value.indexOf('.min.js') > -1
  104. _.map scripts, (value) ->
  105. return value.replace 'out', ''
  106. # =================================
  107. # DocPad Events
  108. # Here we can define handlers for events that DocPad fires
  109. # You can find a full listing of events on the DocPad Wiki
  110. events:
  111. # Server Extend
  112. # Used to add our own custom routes to the server before the docpad routes are added
  113. serverExtend: (opts) ->
  114. # Extract the server from the options
  115. {server} = opts
  116. docpad = @docpad
  117. # As we are now running in an event,
  118. # ensure we are using the latest copy of the docpad configuraiton
  119. # and fetch our urls from it
  120. latestConfig = docpad.getConfig()
  121. oldUrls = latestConfig.templateData.site.oldUrls or []
  122. newUrl = latestConfig.templateData.site.url
  123. # Redirect any requests accessing one of our sites oldUrls to the new site url
  124. server.use (req,res,next) ->
  125. if req.headers.host in oldUrls
  126. res.redirect(newUrl+req.url, 301)
  127. else
  128. next()
  129. }
  130. # Export our DocPad Configuration
  131. module.exports = docpadConfig