Skip to content

Commit

Permalink
docs: store content with associated version re: #12548
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 23, 2022
1 parent e414514 commit ad2446c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/search.js
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit ad2446c

Please sign in to comment.