1 | path = require('path')
|
2 | express = require('express')
|
3 | _ = require('lodash')
|
4 |
|
5 | navTree = require('./nav.json')
|
6 | config = require('./config')
|
7 |
|
8 | Doxx = require('..')
|
9 | doxxConfig = require('./config/doxx')
|
10 |
|
11 | app = express()
|
12 | doxx = Doxx(doxxConfig)
|
13 | doxx.configureExpress(app)
|
14 |
|
15 | staticDir = path.join(__dirname, 'static')
|
16 | contentsDir = path.join(__dirname, config.destDir)
|
17 |
|
18 | app.use(express.static(staticDir))
|
19 |
|
20 | getLocals = (extra) ->
|
21 | doxx.getLocals({ nav: navTree }, extra)
|
22 |
|
23 | doxx.loadLunrIndex()
|
24 |
|
25 | app.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 |
|
36 | app.use(express.static(contentsDir))
|
37 |
|
38 | app.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 |
|
43 | port = process.env.PORT ? 3000
|
44 |
|
45 | app.listen port, ->
|
46 | console.log("Server started on port #{port}")
|