diff --git a/docs/search.js b/docs/search.js index 8aa7d4c6455..83615f0ca96 100644 --- a/docs/search.js +++ b/docs/search.js @@ -6,6 +6,7 @@ const filemap = require('./source'); const fs = require('fs'); const pug = require('pug'); const mongoose = require('../'); +let { version } = require('../package.json'); const { marked: markdown } = require('marked'); const highlight = require('highlight.js'); @@ -15,10 +16,14 @@ markdown.setOptions({ } }); +// 5.13.5 -> 5.x, 6.8.2 -> 6.x, etc. +version = version.slice(0, version.indexOf('.')) + '.x'; + const contentSchema = new mongoose.Schema({ title: { type: String, required: true }, body: { type: String, required: true }, - url: { type: String, required: true } + url: { type: String, required: true }, + version: { type: String, required: true, default: version } }); contentSchema.index({ title: 'text', body: 'text' }); const Content = mongoose.model('Content', contentSchema, 'Content'); @@ -28,7 +33,6 @@ const files = Object.keys(filemap); for (const filename of files) { const file = filemap[filename]; - console.log(file) if (file.api) { // API docs are special, raw content is in the `docs` property for (const _class of file.docs) { @@ -115,8 +119,11 @@ run().catch(error => console.error(error.stack)); async function run() { await mongoose.connect(config.uri, { dbName: 'mongoose' }); - await Content.deleteMany({}); + await Content.deleteMany({ version }); for (const content of contents) { + if (version !== '6.x') { + content.url = `/docs/${version}/docs/${content.url}`; + } await content.save(); }