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.

164 lines
4.9 KiB

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