UNPKG

1.06 kBtext/coffeescriptView Raw
1path = require('path')
2express = require('express')
3_ = require('lodash')
4
5navTree = require('./nav.json')
6config = require('./config')
7
8Doxx = require('..')
9doxxConfig = require('./config/doxx')
10
11app = express()
12doxx = Doxx(doxxConfig)
13doxx.configureExpress(app)
14
15staticDir = path.join(__dirname, 'static')
16contentsDir = path.join(__dirname, config.destDir)
17
18app.use(express.static(staticDir))
19
20getLocals = (extra) ->
21 doxx.getLocals({ nav: navTree }, extra)
22
23doxx.loadLunrIndex()
24
25app.get '/search-results', (req, res) ->
26 { searchTerm } = req.query
27 res.render 'search', getLocals
28 title: "Search results for \"#{searchTerm}\""
29 breadcrumbs: [
30 'Search Results'
31 searchTerm
32 ]
33 searchTerm: searchTerm
34 searchResults: doxx.lunrSearch(searchTerm)
35
36app.use(express.static(contentsDir))
37
38app.get '*', (req, res) ->
39 res.render 'not-found', getLocals
40 title: "We don't seem to have such page"
41 breadcrumbs: [ 'Page not found' ]
42
43port = process.env.PORT ? 3000
44
45app.listen port, ->
46 console.log("Server started on port #{port}")