-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
fix: genIndex error for search #1933
Conversation
1. url is wrong if multiple contents are on the same site, example: `https://xxxxx/docs/` and `https://xxxxx/blog/` 2. when the `token.text` is undefined, `handlePostContent` is undefined too at line 216
…ires, this plugin can still operate normally
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f41ee5a:
|
@@ -128,9 +142,7 @@ export function genIndex(path, content = '', router, depth) { | |||
token.text = getTableData(token); | |||
token.text = getListData(token); | |||
|
|||
index[slug].body = index[slug].body | |||
? index[slug].body + token.text | |||
: token.text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index[slug].body
is always undefined
, see the line 122
120 if (!index[slug]) {
121 index[slug] = { slug, title: '', body: '' };
122 } else if (index[slug].body) {
......
127 } else {
...... //index[slug].body is always undefined
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the token.text
is undefined
, it will make the index[slug].body
also undefined
.
So I change the token.text
to token.text || ''
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code index[slug].body ? index[slug].body + token.text :
is redundant, and it is not the cause of the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice point.
src/plugins/search/search.js
Outdated
|
||
if (isExpired) { | ||
if (!INDEXS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When manually delete docsify.search.index
and keep docsify.search.expires
, this plugin can still operate normally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user should know what he does when he gonna manually delete index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to reduce a manual operation step during the test, haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to reduce a manual operation step during the test, haha.
If user wanna break it, he should break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this change is not necessary, is it?
If not, I'll revert this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this change is not necessary, is it? If not, I'll revert this code.
yep. personally, I think we do not need handle this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/plugins/search/search.js
Outdated
slug = '#/' + slug.substring(5); | ||
} | ||
slug = pathname + (flag ? '/' : '') + slug; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does those changes for ? could you plz give a sample and add verify test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When my website has multiple paths, it can prevent 404 error.
For example:
http://xxxxxx/A/
http://xxxxxx/B/
When searching on page A and accessing page B, 404 will appear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When my website has multiple paths, it can prevent 404 error. For example:
http://xxxxxx/A/
http://xxxxxx/B/
When searching on page A and accessing page B, 404 will appear.
I see, maybe u can take a look on this namespace
configs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, maybe u can take a look on this
namespace
configs here.
Should I configure it like this?
{
search: [
'/A',
'/B'
]
}
or
{
search: {
paths: [
'/A',
'/B'
]
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you need distinguish those namespace for different paths (sites), may could refer to our site with multi langs nav . if you deploy multi sites in same domain, the namespace
config should be in each site's index.html search config
.
// Use different indexes for path prefixes (namespaces).
// NOTE: Only works in 'auto' mode.
//
// When initialiazing an index, we look for the first path from the sidebar.
// If it matches the prefix from the list, we switch to the corresponding index.
pathNamespaces: ['/zh-cn', '/ru-ru', '/ru-ru/v1'],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will try it.
search.js
two BUGs: 404
and handlePostContent is undefined
handlePostContent is undefined
PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
handlePostContent is undefined
https://xxxxx/docs/
andhttps://xxxxx/blog/
token.text
is undefined,handlePostContent
is undefined too at line 217https://github.com/docsifyjs/docsify/blob/develop/src/plugins/search/search.js#L217
Summary
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
Related issue, if any:
Tested in the following browsers: