Skip to content

Commit

Permalink
feat: Support search when there is no title
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Feb 20, 2021
1 parent 47cd86c commit 0e66834
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function genIndex(path, content = '', router, depth) {
let slug;
let title = '';

tokens.forEach(token => {
tokens.forEach(function(token, tokenIndex) {
if (token.type === 'heading' && token.depth <= depth) {
const { str, config } = getAndRemoveConfig(token.text);

Expand All @@ -106,6 +106,15 @@ export function genIndex(path, content = '', router, depth) {

index[slug] = { slug, title: title, body: '' };
} else {
if (tokenIndex === 0) {
slug = router.toURL(path);
index[slug] = {
slug,
title: path !== '/' ? path.slice(1) : 'Home Page',
body: token.text || '',
};
}

if (!slug) {
return;
}
Expand Down

0 comments on commit 0e66834

Please sign in to comment.