Skip to content

Commit

Permalink
Since search-index.js is loaded asynchronously, it needs to be the pl…
Browse files Browse the repository at this point in the history
…ace that initializes the index, so add new global initializeSearch function that it can call; improve feedback in doc:site; style cleanup
  • Loading branch information
GeoffreyBooth committed May 13, 2018
1 parent 8903c62 commit 64ce85c
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 243 deletions.
21 changes: 13 additions & 8 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,11 @@ buildDocs = (watch = no) ->
sectionsSourceFolder = 'documentation/sections'
examplesSourceFolder = 'documentation/examples'
outputFolder = "docs/v#{majorVersion}"
searchCollections = docs: [], changelogs: []
{structure} = require "./documentation/structure.coffee"

monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

formatDate = (date) ->
date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) ->
"#{monthNames[$2 - 1]} #{+$3}, #{$1}"
searchCollections =
docs: []
changelogs: []

# Helpers
releaseHeader = (date, version, prevVersion) ->
Expand All @@ -198,6 +195,11 @@ buildDocs = (watch = no) ->
</h2>
"""

monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
formatDate = (date) ->
date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) ->
"#{monthNames[$2 - 1]} #{+$3}, #{$1}"

codeFor = require "./documentation/site/code.coffee"

# Template for search results.
Expand Down Expand Up @@ -241,7 +243,7 @@ buildDocs = (watch = no) ->
.replace /^\s+/g, " "

# Build search catalog.
searchCatalogue = (mdDoc, section, data) ->
searchCatalog = (mdDoc, section, data) ->
return unless match = /^(#+?)\s+([^\n]+)\s+([\s\S]+)/.exec mdDoc
[, level, title, body] = match
content = clean body
Expand Down Expand Up @@ -293,7 +295,7 @@ buildDocs = (watch = no) ->
md = md.replace /<%= releaseHeader %>/g, releaseHeader
md = md.replace /<%= majorVersion %>/g, majorVersion
md = md.replace /<%= fullVersion %>/g, CoffeeScript.VERSION
searchCatalogue md, file, searchData
searchCatalog md, file, searchData
html = markdownRenderer.render md
html = _.template(html)
codeFor: codeFor()
Expand Down Expand Up @@ -391,11 +393,14 @@ buildDocs = (watch = no) ->
window.searchResultTemplate = #{searchResultsTemplate};
window.searchResultsListTemplate = #{searchResultsListTemplate};
window.searchCollections = #{JSON.stringify searchCollections};
window.initializeSearch();
"""
fs.writeFileSync "#{outputFolder}/search-index.js", searchIdx
log 'output', green, "#{outputFolder}/search-index.js"
fs.writeFileSync "#{outputFolder}/index.html", output
log 'compiled', green, "#{indexFile}#{outputFolder}/index.html"
try
fs.symlinkSync "v#{majorVersion}/search-index.js", 'docs/search-index.js'
fs.symlinkSync "v#{majorVersion}/index.html", 'docs/index.html'
catch exception

Expand Down
Loading

0 comments on commit 64ce85c

Please sign in to comment.