Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate json file for index search #1252

Merged
merged 2 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"handlebars": "^4.7.3",
"highlight.js": "^9.18.1",
"lodash": "^4.17.15",
"lunr": "^2.3.8",
"marked": "0.8.0",
"minimatch": "^3.0.0",
"progress": "^2.0.3",
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@types/lodash": "^4.14.149",
"@types/lunr": "^2.3.3",
"@types/marked": "^0.7.3",
"@types/minimatch": "3.0.3",
"@types/mocha": "^7.0.2",
Expand Down
25 changes: 19 additions & 6 deletions src/lib/output/plugins/JavascriptIndexPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Path from 'path';
import { Builder, trimmer } from 'lunr';

import { DeclarationReflection, ProjectReflection } from '../../models/reflections/index';
import { GroupPlugin } from '../../converter/plugins/GroupPlugin';
Expand Down Expand Up @@ -66,12 +67,24 @@ export class JavascriptIndexPlugin extends RendererComponent {
rows.push(row);
}

const fileName = Path.join(event.outputDirectory, 'assets', 'js', 'search.js');
const data =
`var typedoc = typedoc || {};
typedoc.search = typedoc.search || {};
typedoc.search.data = ${JSON.stringify({kinds: kinds, rows: rows})};`;
const builder = new Builder();
builder.pipeline.add(trimmer);

writeFile(fileName, data, false);
builder.ref('id');
builder.field('name', {boost: 10});
builder.field('parent');

rows.forEach(row => builder.add(row));

const index = builder.build();

const jsonFileName = Path.join(event.outputDirectory, 'assets', 'js', 'search.json');
Gerrit0 marked this conversation as resolved.
Show resolved Hide resolved
const jsonData = JSON.stringify({
kinds,
rows,
index
});

writeFile(jsonFileName, jsonData, false);
}
}